home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / smart21b.zip / SAMPLES / WIN32OS2 / LIST.C next >
C/C++ Source or Header  |  1994-09-01  |  3KB  |  96 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.             hWndPrevParent = SetParent (hWnd, hWndParent);
  80.             switch (wParam)
  81.             {
  82.                 case ID_DELETE:
  83.                     iSel = SendMessage (hList, LB_GETCURSEL, 0, 0L);
  84.                     if (iSel != LB_ERR)
  85.                         SendMessage (hList, LB_DELETESTRING, iSel, 0L);
  86.                     break;
  87.             }
  88.             break;
  89.  
  90.         default:
  91.             return (DefWindowProc (hWnd, iMessage, wParam, lParam));
  92.     }
  93.  
  94.     return (0);
  95. }
  96.