1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156
|
#include <windows.h>
#include <tchar.h>
#include "drawing.h"
//adds windows styling
#pragma comment(linker,"\"/manifestdependency:type='win32' \
name='Microsoft.Windows.Common-Controls' version='6.0.0.0' \
processorArchitecture='*' publicKeyToken='6595b64144ccf1df' language='*'\"")
//constant control identifiers
#define EXITBUTTON 101
//globals
RECT rc;
HWND hWndButton;
HWND hWnd;
int posX = 0;
int posY = 0;
//This is where it all happens
LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
{
switch (message)
{
case WM_CREATE:
{
//add controls on window creation message
hWndButton = CreateWindowEx(
NULL,
_T("BUTTON"),
_T("Exit"),
WS_TABSTOP | WS_VISIBLE | WS_CHILD | BS_DEFPUSHBUTTON,
posX,
posY,
80,
26,
hWnd,
(HMENU) 101,
GetModuleHandle(NULL),
NULL);
//end of Exit button
//enter drawing class passing window handle
drawing draw = drawing(&hWnd);
}
break;
//control message processing
case WM_COMMAND:
{
//switch process depending on control ID
switch (LOWORD(wParam))
{
case EXITBUTTON:
PostQuitMessage(0);
break;
}
}
break;
// Position stuff when window size changes
case WM_SIZE:
GetClientRect(hWnd, &rc);
posX = rc.right - 90;
posY = rc.bottom - 36;
MoveWindow(hWndButton, posX, posY, 80, 26, true);
break;
//client exit control on window
case WM_DESTROY:
PostQuitMessage(0);
break;
//if nothing happens pass it on to the default windows procedure
default:
return DefWindowProc(hWnd, message, wParam, lParam);
break;
}
return 0;
}
//
// Application entry point
//
int WINAPI WinMain(HINSTANCE hInstance,
HINSTANCE hPrevInstance,
LPSTR lpCmdLine,
int nCmdShow) {
//
// create window class structure
//
WNDCLASSEX wcex;
wcex.cbSize = sizeof(WNDCLASSEX);
wcex.style = CS_HREDRAW | CS_VREDRAW;
wcex.lpfnWndProc = WndProc;
wcex.cbClsExtra = 0;
wcex.cbWndExtra = 0;
wcex.hInstance = hInstance;
wcex.hIcon = LoadIcon(hInstance, MAKEINTRESOURCE(IDI_APPLICATION));
wcex.hCursor = LoadCursor(NULL, IDC_ARROW);
wcex.hbrBackground = (HBRUSH)(COLOR_WINDOW + 1);
wcex.lpszMenuName = NULL;
wcex.lpszClassName = _T("mainWindowClass");
wcex.hIconSm = LoadIcon(wcex.hInstance, MAKEINTRESOURCE(IDI_APPLICATION));
//register window
if (!RegisterClassEx(&wcex))
{
MessageBox(NULL,
_T("Call to RegisterClassEx failed!"),
_T("Win32 Guided Tour"),
NULL);
return 1;
}
//
//actually create the window
//
hWnd = CreateWindow(
_T("mainWindowClass"),
_T("Steve's Window!"),
WS_OVERLAPPEDWINDOW,
CW_USEDEFAULT, CW_USEDEFAULT,
500, 400,
NULL,
NULL,
hInstance,
NULL
);
if (!hWnd)
{
MessageBox(NULL,
_T("Call to CreateWindow failed!"),
_T("Win32 Guided Tour"),
NULL);
return 1;
}
//show and update the created window
ShowWindow(hWnd,nCmdShow);
UpdateWindow(hWnd);
//
//Enter the message loop
//
MSG msg;
while (GetMessage(&msg, NULL, 0, 0))
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
return (int)msg.wParam;
}
| |