Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- MainWndProc (HWND hwnd, UINT nMsg, WPARAM wParam, LPARAM
- lParam)
- {
- /* The window handle for the "Click Me" button. */
- static HWND hwndButton = 0;
- static int cx, cy; /* Height and width of our button. */
- HDC hdc; /* A device context used for drawing */
- PAINTSTRUCT ps; /* Also used during window drawing */
- RECT rc; /* A rectangle used during drawing */
- /*
- * Perform processing based on what kind of message we got.
- */
- switch (nMsg)
- {
- case WM_CREATE:
- {
- /* The window is being created. Create our button
- * window now. */
- TEXTMETRIC tm;
- /* First we use the system fixed font size to choose
- * a nice button size. */
- hdc = GetDC (hwnd);
- SelectObject (hdc, GetStockObject (SYSTEM_FIXED_FONT));
- GetTextMetrics (hdc, &tm);
- cx = tm.tmAveCharWidth * 30;
- cy = (tm.tmHeight + tm.tmExternalLeading) * 2;
- ReleaseDC (hwnd, hdc);
- /* Now create the button */
- hwndButton = CreateWindow (
- "button", /* Builtin button class */
- "Click Here",
- WS_CHILD | WS_VISIBLE | BS_PUSHBUTTON,
- 0, 0, cx, cy,
- hwnd, /* Parent is this window. */
- (HMENU) 1, /* Control ID: 1 */
- ((LPCREATESTRUCT) lParam)->hInstance,
- NULL
- );
- return 0;
- break;
- }
- case WM_DESTROY:
- /* The window is being destroyed, close the application
- * (the child button gets destroyed automatically). */
- PostQuitMessage (0);
- return 0;
- break;
- case WM_COMMAND:
- /* Check the control ID, notification code and
- * control handle to see if this is a button click
- * message from our child button. */
- if (LOWORD(wParam) == 1 &&
- HIWORD(wParam) == BN_CLICKED &&
- (HWND) lParam == hwndButton)
- {
- /* Our button was clicked. Close the window. */
- DestroyWindow (hwnd);
- }
- return 0;
- break;
- }
- /* If we don't handle a message completely we hand it to the system
- * provided default window function. */
- return DefWindowProc (hwnd, nMsg, wParam, lParam);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement