home *** CD-ROM | disk | FTP | other *** search
/ The Developer Connection…ice Driver Kit for OS/2 3 / DEV3-D1.ISO / devtools / smart / samples / win31os2 / list.c__ / LIST.C
Encoding:
C/C++ Source or Header  |  1993-10-08  |  2.6 KB  |  95 lines

  1. #include <windows.h>
  2. #include "list.h"
  3.  
  4. HFONT    hFont;
  5.  
  6. int PASCAL WinMain (HANDLE hInstance, HANDLE hPrevInstance,
  7.                     LPSTR lpszCmdLine, int nCmdShow)
  8. {
  9.     WNDCLASS    wndClass;
  10.     HWND        hWnd;
  11.     MSG         msg;
  12.  
  13.     if (!hPrevInstance)
  14.     {
  15.         wndClass.style          = CS_HREDRAW | CS_VREDRAW;
  16.         wndClass.lpfnWndProc    = MainWndProc;
  17.         wndClass.cbClsExtra     = 0;
  18.         wndClass.cbWndExtra     = DLGWINDOWEXTRA;
  19.         wndClass.hInstance      = hInstance;
  20.         wndClass.hIcon          = LoadIcon(hInstance, "AppIcon");
  21.         wndClass.hCursor        = LoadCursor(NULL, IDC_ARROW);
  22.         wndClass.hbrBackground  = COLOR_WINDOW + 1;
  23.         wndClass.lpszMenuName   = NULL;
  24.         wndClass.lpszClassName  = "AppClass";
  25.  
  26.         if (!RegisterClass (&wndClass))
  27.             return FALSE;
  28.     }
  29.  
  30.  
  31.     hWnd = CreateDialog (hInstance, "AppClass", 0, NULL);
  32.  
  33.     ShowWindow (hWnd, nCmdShow);
  34.     UpdateWindow (hWnd);
  35.  
  36.     while (GetMessage (&msg, NULL, 0,0 ))
  37.     {
  38.         if (!IsDialogMessage (hWnd, &msg))
  39.         {
  40.             TranslateMessage (&msg);
  41.             DispatchMessage (&msg);
  42.         }
  43.     }
  44.  
  45.     return (msg.wParam);
  46. }
  47.  
  48. long FAR PASCAL MainWndProc (HWND hWnd, unsigned iMessage,
  49.                              WPARAM wParam, LPARAM lParam)
  50. {
  51.     HWND            hList;
  52.     WORD            iSel;
  53.     PAINTSTRUCT     ps;
  54.     HDC             hDC;
  55.     RECT            Rect;
  56.  
  57.     switch (iMessage)
  58.     {
  59.         case WM_CREATE:
  60.             hFont = CreateFont (24,0,0,0,0,TRUE,0,0,0,0,0,0,
  61.                           VARIABLE_PITCH | FF_ROMAN,(LPSTR)"Roman");
  62.             SendDlgItemMessage (hWnd, ID_LISTBOX, WM_SETFONT, hFont, 1L);
  63.             break;
  64.  
  65.         case WM_PAINT:
  66.             hDC = BeginPaint (hWnd,(LPPAINTSTRUCT)&ps);
  67.             GetClientRect (hWnd,(LPRECT)&Rect);
  68.             FillRect (hDC, (LPRECT)&Rect, GetStockObject (LTGRAY_BRUSH);
  69.             EndPaint (hWnd,(LPPAINTSTRUCT)&ps);
  70.             break;
  71.  
  72.         case WM_DESTROY:
  73.             DeleteObject (hFont);
  74.             PostQuitMessage (0);
  75.             break;
  76.  
  77.         case WM_COMMAND:
  78.             hList = GetDlgItem (hWnd, ID_LISTBOX);
  79.             switch (wParam)
  80.             {
  81.                 case ID_DELETE:
  82.                     iSel = SendMessage (hList, LB_GETCURSEL, 0, 0L);
  83.                     if (iSel != LB_ERR)
  84.                         SendMessage (hList, LB_DELETESTRING, iSel, 0L);
  85.                     break;
  86.             }
  87.             break;
  88.  
  89.         default:
  90.             return (DefWindowProc (hWnd, iMessage, wParam, lParam));
  91.     }
  92.  
  93.     return (0);
  94. }
  95.