Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Making a simple windows app

Status
Not open for further replies.

Guest_imported

New member
Jan 1, 1970
0
Hi, I am a beginner at programming in c++. I wanted to make
a simple windows program. The program just makes a window.
One of the first things you have to do is make and register an windows class.But both the CreateWindow function and RegisterClassEx function fail and return 0. Can any one tell me what the problem could be ?







 
The CreateWindow function has many possible issues but if your RegisterClassEx() failed then CreateWindow will fail since it requires the window-class (the first parameter) to be valid. Also, if you are creating the main window, usually CreateWindowEx() is used because it gives you more style options (like WS_EX_ACCEPTFILES, etc.) But that's up to you.

The RegisterClassEx function fails if the WNDCLASSEX struct has bad values. This often happens if you declared the struct, but didn't clear it (with ZeroMemory, memset, or whatever) and then only set values for a few of the members. The members you didn't set might have junk values which cause the function to fail. You might also have set bad values (if you are just starting, the win32 API is rather idiosyncratic). Here's the class-registering code from one of my programs:

WNDCLASSEX wce;
ZeroMemory(&wce, sizeof(WNDCLASSEX));
wce.cbSize = sizeof(wce);
wce.hbrBackground = (HBRUSH) COLOR_WINDOW + 4;
wce.lpfnWndProc = MainProc;
wce.lpszClassName = pClass;
wce.lpszMenuName = (LPCTSTR) IDR_MENU1;
if (!RegisterClassEx(&wce)) return 0;




--Will Duty
wduty@radicalfringe.com

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top