home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / S12317.ZIP / APP.C next >
C/C++ Source or Header  |  1988-12-30  |  4KB  |  109 lines

  1. #define INCL_GPI
  2. #define INCL_WIN
  3.  
  4.  
  5. /**********************************************************************
  6. *                                      *
  7. *                                      *
  8. *  This program illustrates how to Change the Font used in a List Box *
  9. *                                      *
  10. *  This would be useful if your application needed to have list boxes *
  11. *  that display information in columns or if you just wanted to use a *
  12. *  a non-proportional font.                          *
  13. *                                      *
  14. *  This is accomplished with the following steps:              *
  15. *                                      *
  16. *  1. Query the available fonts and select one that you wish to use.  *
  17. *                                      *
  18. *  2. Use the style LS_OWNERDRAW when creating your list-box control. *
  19. *  This style will cause a WM_MEASUREITEM message to be sent to the   *
  20. *  owner when the listbox is created and a WM_DRAWITEM message to be  *
  21. *  sent to the owner of the control whenever a list-box item is about *
  22. *  to be drawn.                               *
  23. *                                      *
  24. *  3. In the message processing for the WM_MEASUREITEM message you    *
  25. *  return the height of the listbox items.                  *
  26. *                                      *
  27. *  4. In the message processing for the WM_DRAWITEM, you need to set  *
  28. *  the font selection to the desired font and return FALSE. The mp2   *
  29. *  parameter will contain the address of the OWNERITEM structure      *
  30. *  associated with the item that needs drawing. This structure          *
  31. *  contains the PS for the list box, among other things.          *
  32. *                                      *
  33. ***********************************************************************/
  34.  
  35.  
  36. #include <os2.h>
  37. #include <stddef.h>
  38. #include "APP.h"
  39.  
  40. HAB     hAB;
  41. HMQ     hMsgQ;
  42. HWND    hwndApp;
  43. HWND    hwndAppFrame;
  44. HWND    hwndKid;
  45. HWND    hwndKidFrame;
  46. HWND    hwndList;
  47. extern FONTMETRICS FontMetrics;
  48.  
  49. /* Write-once global variables */
  50. char    szAppName[10];
  51. char    szKidName[10];
  52. ULONG    style = FCF_STANDARD;
  53. ULONG    KidCtlData = FCF_TITLEBAR | FCF_SYSMENU;
  54.  
  55. SHORT cdecl main(  )
  56. {
  57.     QMSG    qMsg;
  58.  
  59.     hAB   = WinInitialize(NULL);
  60.     hMsgQ = WinCreateMsgQueue( hAB, 0 );
  61.  
  62.     WinLoadString( hAB, NULL, IDSNAME, sizeof(szAppName), (NPCH)szAppName );
  63.     WinLoadString( hAB, NULL, IDSKIDNAME, sizeof(szKidName), szKidName );
  64.  
  65.     if ( !WinRegisterClass( hAB, (NPCH)szAppName, (PFNWP)APPWndProc,
  66.             CS_CLIPCHILDREN | CS_SIZEREDRAW, NULL ) )
  67.         return( FALSE );
  68.  
  69.  
  70.     /* Create a window instance of class szAppName */
  71.     hwndAppFrame = WinCreateStdWindow(
  72.         HWND_DESKTOP,     /* specify desktop as parent window           */
  73.     FS_ICON | FS_ACCELTABLE | WS_VISIBLE,
  74.     &style,
  75.         (NPCH)szAppName,  /* window class name                          */
  76.         (NPCH)szAppName,  /* name appearing in window caption           */
  77.         0L,
  78.         NULL,             /*  use current executable module id          */
  79.     ID_APP,       /*  menu id and accelerator id and icon id    */
  80.         (HWND FAR *)&hwndApp  /* window handle                          */
  81.         );
  82.  
  83.  
  84. //                      Add the list box to the client window
  85. //
  86. /* note the LS_OWNERDRAW style.  This will cause a WM_DRAWITEM message
  87.    to be sent to the owner of the listbox                   */
  88.     hwndList = WinCreateWindow (hwndApp, WC_LISTBOX, NULL,
  89.                    WS_VISIBLE | LS_OWNERDRAW, 0, 0, 0, 0,
  90.                    hwndApp, HWND_BOTTOM, LID_LIST1, NULL, NULL);
  91.     WinSetWindowPos (hwndList, HWND_BOTTOM, 10, 10, (short) 100,
  92.                  (short) 100, SWP_SIZE | SWP_MOVE | SWP_SHOW);
  93.  
  94.  
  95.  
  96.  
  97.  
  98.     while( WinGetMsg( hAB, (PQMSG)&qMsg, (HWND)NULL, 0, 0 ) )
  99.     {
  100.         WinDispatchMsg( hAB, (PQMSG)&qMsg );
  101.     }
  102.  
  103.     WinDestroyWindow( hwndAppFrame );
  104.     WinDestroyMsgQueue( hMsgQ );
  105.     WinTerminate( hAB );
  106. }
  107. /*
  108. */
  109.