HBRUSH problem

here is the code with the problem.

winClass.hbrBackground = GetStockObject(BLACK_BRUSH);

the equal sign says...

Error: a value of type "HGDIOBJ" cannot be assigned to an entity of type "HBRUSH"
Last edited on
You have to typecast it, so do this --

winClass.hbrBackground=(HBRUSH)GetStockObject(BLACK_BRUSH)
Thanks bro. But now im getting this error:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
'Win32 Projects.exe': Loaded 'C:\Users\david\Documents\Visual Studio 2010\Projects\Win32 Projects\Debug\Win32 Projects.exe', Symbols loaded.
'Win32 Projects.exe': Loaded 'C:\Windows\SysWOW64\ntdll.dll', Cannot find or open the PDB file
'Win32 Projects.exe': Loaded 'C:\Windows\SysWOW64\kernel32.dll', Cannot find or open the PDB file
'Win32 Projects.exe': Loaded 'C:\Windows\SysWOW64\KernelBase.dll', Cannot find or open the PDB file
'Win32 Projects.exe': Loaded 'C:\Windows\SysWOW64\user32.dll', Cannot find or open the PDB file
'Win32 Projects.exe': Loaded 'C:\Windows\SysWOW64\gdi32.dll', Cannot find or open the PDB file
'Win32 Projects.exe': Loaded 'C:\Windows\SysWOW64\lpk.dll', Cannot find or open the PDB file
'Win32 Projects.exe': Loaded 'C:\Windows\SysWOW64\usp10.dll', Cannot find or open the PDB file
'Win32 Projects.exe': Loaded 'C:\Windows\SysWOW64\msvcrt.dll', Cannot find or open the PDB file
'Win32 Projects.exe': Loaded 'C:\Windows\SysWOW64\advapi32.dll', Cannot find or open the PDB file
'Win32 Projects.exe': Loaded 'C:\Windows\SysWOW64\sechost.dll', Cannot find or open the PDB file
'Win32 Projects.exe': Loaded 'C:\Windows\SysWOW64\rpcrt4.dll', Cannot find or open the PDB file
'Win32 Projects.exe': Loaded 'C:\Windows\SysWOW64\sspicli.dll', Cannot find or open the PDB file
'Win32 Projects.exe': Loaded 'C:\Windows\SysWOW64\cryptbase.dll', Cannot find or open the PDB file
'Win32 Projects.exe': Loaded 'C:\Windows\SysWOW64\msvcr100d.dll', Symbols loaded.
'Win32 Projects.exe': Loaded 'C:\Windows\SysWOW64\imm32.dll', Cannot find or open the PDB file
'Win32 Projects.exe': Loaded 'C:\Windows\SysWOW64\msctf.dll', Cannot find or open the PDB file
First-chance exception at 0x753e675b in Win32 Projects.exe: 0xC0000005: Access violation reading location 0xcccccccc.
Unhandled exception at 0x753e675b in Win32 Projects.exe: 0xC0000005: Access violation reading location 0xcccccccc.


Here is my code in its entirety.

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
// A complete windows program.

/***INCLUDES***/
#define WIN32_MEAN_AND_LEAN

#include <Windows.h>
#include <windowsX.h>
#include <stdio.h>
#include <math.h>
#include <tchar.h>

/***DEFINES***/
#define WINDOW_CLASS_NAME "WINCLASS1"

/***GLOBALS***/

/***FUNCTIONS***/
LRESULT CALLBACK WndProc(HWND hWnd, UINT msg, WPARAM wParam,
						 LPARAM lParam)
{
	// This is the main message handler of the system
	PAINTSTRUCT		ps;		// used in WM_PAINT
	HDC				hdc;	// handle to a device context

	switch( msg )
	{
	case WM_CREATE:
		// do initialization stuff here
		// return success
		return(0);
		break;

	case WM_PAINT:
		// simply validate the window
		hdc = BeginPaint(hWnd, &ps);
		// You would do all your painting here
		EndPaint(hWnd, &ps);
		//return success
		return(0);
		break;

	case WM_DESTROY:
		// Kill the application, this sends a WM_QUIT message
		PostQuitMessage(0);
		//return success
		return(0);
		break;

	default:
		break;
	} // end switch

	// Process any messages that we didn't take care of
	return (DefWindowProc(hWnd,msg,wParam,lParam));

} // end WndProc


/***WINMAIN***/
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance,
				   LPSTR lpCmdLine, int nCmdShow)
{
	WNDCLASSEX winClass;	// This will hold the class we create
	HWND	   hWnd;		// Generic window handle
	MSG		   msg;			// generic message

	// 1. Fill out Window Class Structure
	winClass.cbSize			= sizeof(WNDCLASSEX);
	winClass.style			= CS_HREDRAW | CS_VREDRAW;
	winClass.lpfnWndProc	= WndProc;
	winClass.cbWndExtra		= 0;
	winClass.cbClsExtra		= 0;
	winClass.hInstance		= hInstance;
	winClass.hIcon			= LoadIcon(NULL, IDI_APPLICATION);
	winClass.hCursor		= LoadCursor(NULL, IDC_ARROW);
	winClass.hbrBackground	= (HBRUSH)GetStockObject(BLACK_BRUSH);
	winClass.lpszClassName	= _T(WINDOW_CLASS_NAME);
	winClass.hIconSm		= LoadIcon(NULL, IDI_APPLICATION);

	// 2. Register the window class
	if(!RegisterClassEx(&winClass))
		return(0);

	// 3. Create the window
	if(!(hWnd = CreateWindowExA(NULL, WINDOW_CLASS_NAME,
							   "WINDOW 2",
							   WS_OVERLAPPEDWINDOW | WS_VISIBLE,
							   0, 0, 400, 400, NULL, NULL,
							   hInstance, NULL)))
		return(0);

	if(!(hWnd = CreateWindowExA(NULL, WINDOW_CLASS_NAME,
							   "WINDOW 1",
							   WS_OVERLAPPEDWINDOW | WS_VISIBLE,
							   400, 400, 400, 400, NULL, NULL,
							   hInstance, NULL)))
		return(0);

	// Enter main event loop
	while(GetMessage(&msg, NULL, 0, 0))
	{
		TranslateMessage(&msg);
		DispatchMessage(&msg);
	} // end while

	return(msg.wParam);

}// end WinMain

For starters, you icon decs are wrong. They should look like this --

LoadIcon(NULL, MAKEINTRESOURCE(IDI_APPLICATION));

The same is true for the small icon, i.e., the last one in your register class.

Secondly, your class name is also wrong. It should look like this --

winClass.lpszClassName = WINDOW_CLASS_NAME;

That's for starters. See what kind of errors that fixes.
Last edited on
LOL lamblion those two things you said werent the problem. I forgot winClass.lpszMenuName!

The way i did the two things you said are fine i guess.
Are you trying to tell me that this compiles --

winClass.lpszClassName=_T(WINDOW_CLASS_NAME);

Are you also trying to tell me that it compiles WITHOUT adding the (HBRUSH) typecase?

Errorneous coding will only lead to problems in other areas of your code. Missing the menu was only one of your errors.
I just needed the typecase and the menu. Someone else told me a while ago to use _T() and include tchar.h because of UNICODE or something
Topic archived. No new replies allowed.