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
|
#include <windows.h>
LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM);
LRESULT CALLBACK PanelProc(HWND, UINT, WPARAM, LPARAM);
void RegisterRedPanel(void);
void RegisterBluePanel(void);
int WINAPI WinMain( HINSTANCE hInstance, HINSTANCE hPrevInstance,
LPSTR lpCmdLine, int nCmdShow )
{
MSG msg ;
WNDCLASS wc = {0};
wc.lpszClassName = TEXT( "Windows" );
wc.hInstance = hInstance ;
wc.hbrBackground = GetSysColorBrush(COLOR_3DFACE);
wc.lpfnWndProc = WndProc ;
wc.hCursor = LoadCursor(0,IDC_ARROW);
RegisterClass(&wc);
CreateWindow( wc.lpszClassName, TEXT("Windows"),
WS_OVERLAPPEDWINDOW | WS_VISIBLE,
100, 100, 250, 180, 0, 0, hInstance, 0);
while( GetMessage(&msg, NULL, 0, 0)) {
TranslateMessage(&msg);
DispatchMessage(&msg);
}
return (int) msg.wParam;
}
LRESULT CALLBACK WndProc( HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam )
{
switch(msg)
{
case WM_CREATE:
{
RegisterRedPanel();
CreateWindow(TEXT("RedPanel"), NULL,
WS_CHILD | WS_VISIBLE,
20, 20, 80, 80,
hwnd, (HMENU) 1, NULL, NULL);
RegisterBluePanel();
CreateWindow(TEXT("BluePanel"), NULL,
WS_CHILD | WS_VISIBLE,
120, 20, 80, 80,
hwnd, (HMENU) 2, NULL, NULL);
break;
}
case WM_DESTROY:
{
PostQuitMessage(0);
break;
}
}
return DefWindowProc(hwnd, msg, wParam, lParam);
}
LRESULT CALLBACK PanelProc( HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam )
{
switch(msg)
{
case WM_LBUTTONUP:
{
Beep(50, 40);
break;
}
}
return DefWindowProc(hwnd, msg, wParam, lParam);
}
void RegisterRedPanel(void) {
HBRUSH hbrush = CreateSolidBrush(RGB(255, 0, 0));
WNDCLASS rwc = {0};
rwc.lpszClassName = TEXT( "RedPanel" );
rwc.hbrBackground = hbrush;
rwc.lpfnWndProc = PanelProc ;
rwc.hCursor = LoadCursor(0,IDC_ARROW);
RegisterClass(&rwc);
}
void RegisterBluePanel(void) {
HBRUSH hbrush = CreateSolidBrush(RGB(0, 0, 255));
WNDCLASS rwc = {0};
rwc.lpszClassName = TEXT( "BluePanel" );
rwc.hbrBackground = hbrush;
rwc.lpfnWndProc = PanelProc ;
rwc.hCursor = LoadCursor(0,IDC_ARROW);
RegisterClass(&rwc);
}
|