Advertisement
Rapptz

Untitled

Oct 28th, 2012
520
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.13 KB | None | 0 0
  1. MainWndProc (HWND hwnd, UINT nMsg, WPARAM wParam, LPARAM
  2. lParam)
  3. {
  4.         /* The window handle for the "Click Me" button. */
  5. static HWND hwndButton = 0;
  6. static int   cx, cy; /* Height and width of our button. */         
  7.      HDC             hdc;   /* A device context used for drawing */
  8.      PAINTSTRUCT     ps;     /* Also used during window drawing */
  9.     RECT            rc;  /* A rectangle used during drawing */
  10.  
  11.         /*
  12.          * Perform processing based on what kind of message we got.
  13.          */
  14.         switch (nMsg)
  15.         {
  16.                 case WM_CREATE:
  17.                  {
  18.                         /* The window is being created. Create our button
  19.                          * window now. */
  20.                         TEXTMETRIC   tm;
  21.  
  22.                         /* First we use the system fixed font size to choose
  23.                          * a nice button size. */
  24.                          hdc = GetDC (hwnd);
  25.      SelectObject (hdc, GetStockObject (SYSTEM_FIXED_FONT));
  26.                         GetTextMetrics (hdc, &tm);
  27.                         cx = tm.tmAveCharWidth * 30;
  28.                         cy = (tm.tmHeight + tm.tmExternalLeading) * 2;
  29.                         ReleaseDC (hwnd, hdc);
  30.  
  31.                         /* Now create the button */
  32.                         hwndButton = CreateWindow (
  33.                                 "button",    /* Builtin button class */
  34.                                 "Click Here",
  35.                                 WS_CHILD | WS_VISIBLE | BS_PUSHBUTTON,
  36.                                 0, 0, cx, cy,
  37.                                 hwnd,        /* Parent is this window. */
  38.                                 (HMENU) 1,   /* Control ID: 1 */
  39.                                 ((LPCREATESTRUCT) lParam)->hInstance,
  40.                                 NULL
  41.                                 );
  42.  
  43.                         return 0;
  44.                     break;
  45.                 }
  46.  
  47.                 case WM_DESTROY:
  48.                     /* The window is being destroyed, close the application
  49.                      * (the child button gets destroyed automatically). */
  50.                         PostQuitMessage (0);
  51.                         return 0;
  52.                         break;
  53.  
  54.                 case WM_COMMAND:
  55.                         /* Check the control ID, notification code and
  56.                          * control handle to see if this is a button click
  57.                          * message from our child button. */
  58.                         if (LOWORD(wParam) == 1 &&
  59.                             HIWORD(wParam) == BN_CLICKED &&
  60.                             (HWND) lParam == hwndButton)
  61.                         {
  62.                                 /* Our button was clicked. Close the window. */
  63.                                  DestroyWindow (hwnd);
  64.                         }
  65.                         return 0;
  66.                         break;
  67.         }
  68.  
  69.         /* If we don't handle a message completely we hand it to the system
  70.          * provided default window function. */
  71.         return DefWindowProc (hwnd, nMsg, wParam, lParam);
  72. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement