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
|
#include <windows.h>
LRESULT CALLBACK WindowProc(HWND hWnd,
UINT message,
WPARAM wParam,
LPARAM lParam);
int WINAPI WinMain(HINSTANCE hInstance,
HINSTANCE hPrevInstance,
LPSTR lpCmdLine,
int nCmdShow)
{
HWND hWnd;
WNDCLASSEX wc;
ZeroMemory(&wc, sizeof(WNDCLASSEX));
wc.cbSize = sizeof(WNDCLASSEX);
wc.style = CS_HREDRAW | CS_VREDRAW;
wc.lpfnWndProc = WindowProc;
wc.hInstance = hInstance;
wc.hCursor = LoadCursor(NULL, IDC_ARROW);
wc.hbrBackground = CreateSolidBrush(RGB(235, 246, 252));
wc.lpszClassName = L"WindowClass1";
RegisterClassEx(&wc);
hWnd = CreateWindowEx(NULL,
L"WindowClass1", // name of the window class
L"Mini-Prog", // title of the window
WS_OVERLAPPEDWINDOW, // window style
300, // x-position of the window
300, // y-position of the window
500, // width of the window
400, // height of the window
NULL, // we have no parent window, NULL
NULL, // we aren't using menus, NULL
hInstance, // application handle
NULL); // used with multiple windows, NULL
ShowWindow(hWnd, nCmdShow);
MSG msg;
while(GetMessage(&msg, NULL, 0, 0))
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
return msg.wParam;
}
#define ID_BUTTON 1
#define ID_EDIT 2
#define ID_EDITCHILD 100
LRESULT CALLBACK WindowProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
{
static HWND hwndEdit;
switch(message)
{
case WM_CREATE:
{
//Button
HWND hWndButton = CreateWindowEx(NULL,TEXT("button"), TEXT("Click Me"),
WS_CHILD | WS_VISIBLE | BS_DEFPUSHBUTTON,
10, 10, 80, 20,
hWnd, (HMENU) ID_BUTTON, GetModuleHandle(NULL), NULL);
// Edit Box
CreateWindow(TEXT("EDIT"), TEXT("This is some editable text"),
WS_VISIBLE | ES_MULTILINE | WS_CHILD | WS_BORDER,
10, 40, 200, 60,
hWnd, (HMENU) ID_EDIT, NULL, NULL);
hwndEdit = CreateWindowEx(
0, L"EDIT", // predefined class
NULL, // no window title
WS_CHILD | WS_VISIBLE | WS_VSCROLL |
ES_LEFT | ES_MULTILINE | ES_AUTOVSCROLL,
0, 0, 0, 0, // set size in WM_SIZE message
hwnd, // parent window
(HMENU) ID_EDITCHILD, // edit control ID
(HINSTANCE) GetWindowLong(hwnd, GWL_HINSTANCE),
NULL); // pointer not needed
} break;
case WM_DESTROY:
{
PostQuitMessage(0);
return 0;
} break;
case WM_COMMAND:
{
switch(LOWORD(wParam))
{
case ID_BUTTON://button
{
MessageBox(hWnd, L"You clicked me", L"Success!", MB_ICONINFORMATION);
}
}
}
}
return DefWindowProc (hWnd, message, wParam, lParam);
}
|