Ive had a look, and i couldnt find the information was looking for, such as if WNDCLASSEX has default values so that we dont have to define the attributes ourselves. To make my questions abit clearer, ill number them:
1. I know what im doing by putting "WNDCLASSEX wndclass;", im creating a window class of my own, so i could put wndclass.style = whatever, and so on... Correct??
2. I THINK i know what im doing by putting "HWND hWindow;", am i creating a handle to a window? so we would put hWindow = CreateWindow (blahhh), so then hWindow has now been assigned a window, so if we ever wanted to refer to that specific window i would refer to it as hWindow, i hope im correct??
May I suggest the following from MSDN: Learn to Program for Windows in C++
http://msdn.microsoft.com/en-us/library/ff381399(v=VS.85).aspx
If you want to really learn Windows API programming, buy/borrow a copy of Petzold followed by Richter.
http://www.cplusplus.com/forum/windows/35315/#msg190916
The link doesnt tell you whether you HAVE to fill in the attributes of WNDCLASSEX, or whether you can just leave it with its default values (if it does have default values?).
The link doesnt tell you whether you HAVE to fill in the attributes...
...
You must set the following structure members:
lpfnWndProc is a pointer to an application-defined function called the window procedure or "window proc." The window procedure defines most of the behavior of the window. We'll examine the window procedure in detail later. For now, just treat this as a forward reference. hInstance is the handle to the application instance. Get this value from the hInstance parameter of wWinMain. lpszClassName is a string that identifies the window class.
WNDCLASS/WNDCLASSEX are C data structures, there are no default values set up when it is created. If you zero the structure and set the bare minimum, windows will take care of anything not specifically set. If you don't zero the structure and don't set the fields then in all likely hood your program will crash. There are only 10 or 12 field, best practice would be to set them to a known value and move on. In addition to the three previously mentioned fields the cbSize field of WNDCLASSEX neds to be set wc.cbSize=sizeof (WNDCLASSEX);
Thanks very much :). I think i understand the hWindow part, i just want to double check that im understanding it right...
The HWND is a type which is a handle to a window. So by putting HWND hWindow; i am making a special kind of variable which will be the handle to my window. So i can then put:
hWindow = CreateWindow(...parameters...);
So then whenever i wanted to refer to that window i would use hWindow to refer to it. And if i wanted to have a second window, i would have to have a second special variable like so:
could we not just use int instead then? Is it just a typedef for our benefit?
It is a bit more than a simple typedef (at least in VS2010), there are various conditionals that determine the exact nature of the handle so that the type can be checked.
If you hover the mouse pointer over it the IDE will show its definition.
I get typedef HWND_ *HWND, this goes back to a macro, DECLARE_HANDLE (HWND);, that goes back to #define DECLARE_HANDLE(name) struct name##__{int unused;}; typedef struct name##__ *name .
I once learned on here that the point of parameters is so you can pass different numbers to a function() every time you call it. Because the parameters of functions such as winmain() and wndproc() are not used to do that, are they special parameters?