WinMain()

Pages: 12
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??


3. Im not certain on what im doing by putting:

static TCHAR szAppName[] = TEXT("Skeleton");
MSG msg;

What are they for, and how would i use them?



Thanks






Last edited on
closed account (z05DSL3A)
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
ok, ill look into getting that book, thanks. But in the mean time would you be able to answer any of my questions
closed account (z05DSL3A)
The first link should answer your questions and more besides. It is a reasonable tutorial to get you going in the right direction.
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?).
closed account (z05DSL3A)
TpOreilly wrote:
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.

...
Thank you, and as for the others, do they have DEFAULT values which we dont HAVE to fill in then?
closed account (z05DSL3A)
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:

HWND hWindowTwo;

Right or wrong?

closed account (z05DSL3A)
pretty much.
Just notice that there's nothing special about a HWND. It's just an integer.
hmmm ok, could we not just use int instead then? Is it just a typedef for our benefit?
Last edited on
Oops. Actually, it's a void pointer, not an integer. Anyway, the Windows typedefs are there to hide implementation details.
ha ok, so it is a typedef?
Yes. If you hover the mouse pointer over it the IDE will show its definition.
closed account (z05DSL3A)
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 .
Last edited on
thanks :)
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?
???
Ive started a new thread for the previous question:

http://cplusplus.com/forum/beginner/37041/
Last edited on
Topic archived. No new replies allowed.
Pages: 12