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
|
#include <windows.h>
LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM); // Prototypes defined here
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: // On creation of the window, do the following:
{
RegisterRedPanel(); // Register panel before creating it!
CreateWindow(TEXT("RedPanel"), NULL, // Then create it before registering another panel!
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: // When the user attempts to close the window, close it.
{
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); // Makes a noise happen when you click on the red or blue panel(The proceure the panels follow, in other words)
break;
}
}
return DefWindowProc(hwnd, msg, wParam, lParam);
}
LRESULT CALLBACK PanelProc2( HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam )
{
switch(msg)
{
case WM_LBUTTONUP:
{
// Possibly place function in here to change colour of the rectangle?
break;
}
}
return DefWindowProc(hwnd, msg, wParam, lParam);
}
void RegisterRedPanel(void) {
HBRUSH hbrush = CreateSolidBrush(RGB(255, 0, 0)); // Use CreateSolidBrush() to create a coloured window background, WILL NEED THIS!!! :-)
WNDCLASS rwc = {0};
rwc.lpszClassName = TEXT( "RedPanel" );
rwc.hbrBackground = hbrush;
rwc.lpfnWndProc = PanelProc ; // Calls the panel procedure
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 = PanelProc2 ; // again,calls the panel procedure
rwc.hCursor = LoadCursor(0,IDC_ARROW);
RegisterClass(&rwc);
}
void changeCol(WNDCLASS bla)
{
HBRUSH hbrush = CreateSolidBrush(RGB(255, 255, 0));
bla.hbrBackground = hbrush;
}
|