void main (void) { LIST *list; int done = 0; REC *rec; char line[80]; list = lst_init (); printf ("Type a list of names and ages. Empty line quits\n\n"); while (!done) { rec = lst_newnode (sizeof (REC)); gets (line); if ((done = (line[0] == '\0')) != 1) { strcpy (rec->name, line); gets (line); rec->age = atoi (line); lst_insertafter (list, rec, LST_HEAD (list)); } }; printf ("\nThe list you typed in was:\n\n"); for (rec = lst_first (list); rec; rec = lst_next (rec)) printf ("Name: %s, Age: %d\n", rec->name, rec->age); printf ("\nSorting the list...\n\n"); lst_mergesort (list, my_cmp); for (rec = lst_first (list); rec; rec = lst_next (rec)) printf ("Name: %s, Age: %d\n", rec->name, rec->age); lst_kill (list, lst_freenode); }
/**************************************************************************** DESCRIPTION: Create a new windowed device context. HEADER: mglwin.h PARAMETERS: hwnd - Window handle with which to associate new device context RETURNS: Pointer to the allocated windowed device context, or NULL if not enough memory. REMARKS: Creates a new windowed device context for drawing information into a window on the Windows desktop. When you create a Windowed device context, you associate it with a standard Windows HWND for the window that you wish MGL to display it's output on. Windowed device contexts are special device contexts in that you cannot directly access the surface for the device, nor can you actually use the MGL rasterizing functions to draw on the device surface. The only rasterizing functions supported are the MGL_bitBlt and MGL_stretchBlt for blt'ing data from memory device contexts to the window on the desktop. However in order to change the color palette values for the data copied to the window, you must use the MGL palette functions on the windowed display device context. Note that MGL automatically takes care of creating a proper Windows identity palette for the windowed device context, so as long as you program the same palette values for the windowed device and the memory device you should get the maximum performance blt'ing speed. SEE ALSO: MGL_createMemoryDC, MGL_createDisplayDC, MGL_destroyDC, MGL_setWinDC, MGL_activatePalette ****************************************************************************/ MGLDC * MGLAPI MGL_createWindowedDC( MGL_HWND hwnd) { MGLDC *dc; driverent *driver; PM_HWND hwndConsole = (PM_HWND)NULL; /* Allocate memory for the new DC */ _MGL_destroyCurrentMode(); if ((dc = _LST_newNode(sizeof(MGLDC))) == NULL) { FATALERROR(grNoMem); return NULL; } // TODO: Add code to handle multiple windowed DC's!! /* The display device list is currently empty, so create the new * list and start the specified graphics mode */ if (_MGL_winDCList == NULL) { if ((_MGL_winDCList = _LST_create()) == NULL) { FATALERROR(grNoMem); goto Error; } } /* Find the device driver to use */ if ((driver = _MGL_findStaticDriver(MGL_WINDOWEDNAME)) == NULL) { FATALERROR(grDriverNotFound); goto Error; } if (!driver) { FATALERROR(grDriverNotFound); goto Error; } /* Now initialise the driver */ if (!driver->data) { if ((driver->data = driver->driver->createInstance()) == NULL) { FATALERROR(grLoadMem); return NULL; } } if (!_MGL_initDC(dc,driver,NULL,hwnd,-1,-1,1,false,MGL_DEFAULT_REFRESH)) goto Error; /* Open a new windowed console for the mode */ hwndConsole = PM_openConsole((PM_HWND)hwnd,0,dc->mi.xRes+1,dc->mi.xRes+2,dc->mi.bitsPerPixel,false); /* Set up the mouse cursor */ // TODO: Tell the mouse system we are in a window so it will pass the // mouse cursor images through to the window manager? if (_MGL_consoleSupport) MS_setCursor(MGL_DEF_CURSOR); /* Allow the OS specific code to hook the window procedure as necessary */ _MGL_hookWindowProc(dc); /* Add the new DC to the start of the DC chain */ RESET_DEFAULT_CW(); _LST_addAfter(_MGL_winDCList,dc,LST_HEAD(_MGL_winDCList)); return dc; Error: if (hwndConsole) PM_closeConsole(hwndConsole); if (_MGL_winDCList && _MGL_winDCList->count == 0) { _LST_destroy(_MGL_winDCList,_LST_freeNode); _MGL_winDCList = NULL; } _LST_freeNode(dc); return NULL; }