11-06-2011, 01:37 AM
|
#1
|
|
Member
|
Win32 Help
My problem is that the colour of each window is supposed to be different but they're all white. Not sure what problem is, any help would be great!
Quote:
#include <windows.h>
// Store handles to the main window and application
// instance globally.
HWND ghMainWnd = 0;
HWND ghSecWnd = 0;
HWND ghThdWnd = 0;
HINSTANCE ghAppInst = 0;
// Step 1: Define and implement the window procedure.
LRESULT CALLBACK
WndProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)
{
switch( msg )
{
// Handle left mouse button click message.
case WM_LBUTTONDOWN:
if(hWnd == ghMainWnd)
{
MessageBox(0, "You clicked the main window.", "Msg", MB_OK);
return 0;
}
if(hWnd == ghSecWnd)
{
MessageBox(0, "You clicked the secondary window.", "Msg", MB_OK);
return 0;
}
if(hWnd == ghThdWnd)
{
MessageBox(0, "You clicked the third window.", "Msg", MB_OK);
return 0;
}
// Handle key down message.
case WM_KEYDOWN:
if( wParam == VK_ESCAPE )
//Excersise 14.6.1
if(MessageBox(0,"Are you sure?","Exit",MB_YESNO) == IDYES)
{
DestroyWindow(ghMainWnd);
return 0;
}
break;
// Handle destroy window message.
case WM_DESTROY:
PostQuitMessage(0);
return 0;
}
// Forward any other messages we didn't handle to the
// default window procedure.
return DefWindowProc(hWnd, msg, wParam, lParam);
}
// WinMain: Entry point for a Windows application.
int WINAPI
WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance,
PSTR cmdLine, int showCmd)
{
//14.6.5
HBRUSH blueBrush = CreateSolidBrush(RGB(0,0,255));
HBRUSH randBrush = CreateSolidBrush(RGB(5,100,200));
//End 14.6.5
// Save handle to application instance.
ghAppInst = hInstance;
// Step 2: Fill out a WNDCLASS instance.
WNDCLASS wc;
wc.style = CS_HREDRAW | CS_VREDRAW;
wc.lpfnWndProc = WndProc;
wc.cbClsExtra = 0;
wc.cbWndExtra = 0;
wc.hInstance = ghAppInst;
wc.hIcon = ::LoadIcon(0, IDI_APPLICATION);
wc.hCursor = ::LoadCursor(0, IDC_ARROW);
wc.hbrBackground = (HBRUSH)::GetStockObject(WHITE_BRUSH);
wc.lpszMenuName = 0;
wc.lpszClassName = "MyWndClassName";
WNDCLASS wc2 = wc;
WNDCLASS wc3 = wc;
wc2.hbrBackground = blueBrush;
wc3.hbrBackground = randBrush;
// Step 3: Register the WNDCLASS instance with Windows.
RegisterClass( &wc );
RegisterClass( &wc2);
RegisterClass( &wc3);
// Step 4: Create the window, and save handle in global
// window handle variable ghMainWnd.
//Exercise 14.6.2 and 14.6.3
ghMainWnd = ::CreateWindow("MyWndClassName", "MyWindow", WS_OVERLAPPEDWINDOW|WS_VSCROLL|WS_HSCROLL, 0, 0, 300, 300, 0, 0, ghAppInst, 0);
ghSecWnd = ::CreateWindow("MyWndClassName", "MyWindow2", WS_OVERLAPPEDWINDOW|WS_VSCROLL|WS_HSCROLL, 300, 0, 300, 300, 0, 0, ghAppInst, 0);
ghThdWnd = ::CreateWindow("MyWndClassName", "MyWindow3", WS_OVERLAPPEDWINDOW|WS_VSCROLL|WS_HSCROLL, 0, 300, 300, 300, 0, 0, ghAppInst, 0);
if(ghMainWnd == 0)
{
::MessageBox(0, "CreateWindow1 - Failed", 0, 0);
return false;
}
if(ghSecWnd == 0)
{
::MessageBox(0, "CreateWindow2 - Failed", 0, 0);
return false;
}
if(ghThdWnd == 0)
{
::MessageBox(0, "CreateWindow3 - Failed", 0, 0);
return false;
}
// Step 5: Show and update the window.
ShowWindow(ghMainWnd, showCmd);
ShowWindow(ghSecWnd, showCmd);
ShowWindow(ghThdWnd, showCmd);
UpdateWindow(ghMainWnd);
UpdateWindow(ghSecWnd);
UpdateWindow(ghThdWnd);
// Step 6: Enter the message loop and don't quit until
// a WM_QUIT message is received.
MSG msg;
ZeroMemory(&msg, sizeof(MSG));
while( GetMessage(&msg, 0, 0, 0) )
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
// Return exit code back to operating system.
return (int)msg.wParam;
}
|
|
|
|
11-12-2011, 10:56 AM
|
#2
|
|
Junior Member
|
Re: Win32 Help
you have to give each WNDCLASS a different name and use it when you create a window.
wc.lpszClassName = "MyWndClassName";
wc2.lpszClassName = "MyWndClassName2";
ghMainWnd = ::CreateWindow("MyWndClassName", "MyWindow", WS_OVERLAPPEDWINDOW|WS_VSCROLL|WS_HSCROLL, 0, 0, 300, 300, 0, 0, ghAppInst, 0);
ghSecWnd = ::CreateWindow("MyWndClassName2", "MyWindow2", WS_OVERLAPPEDWINDOW|WS_VSCROLL|WS_HSCROLL, 300, 0, 300, 300, 0, 0, ghAppInst, 0);
|
|
|
| Thread Tools |
|
|
| Display Modes |
Linear Mode
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
Powered by vBulletin® Version 3.6.9 Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.
All times are GMT -8. The time now is 08:12 PM.
|
|