Windows Programming and HWND
I begun my windows programming studies with Windows Game Programming for dummies. LaMothe is a pretty good teacher with this type of thing, but what really has slipped past me is why HWND is used. I know that it is a handle to the window, but when and why is it used? For example:
hdc = BeginPaint(hwnd, &ps);
hdc is a handle to the device context (basically, the video card and GDI), BeginPaint retrives and processes the WM_PAINT message, but what about it''s arguments? hwnd? why is hwnd in there?!
That was just an example, but what I''m really looking for is an exaplanation of HWND in general! Why is it needed? When is it used? Thanks to anyone who can help me out here!
Programming::~Fredric(const Annoy_Ance)
3D Math- The type of mathematics that'll put hair on your chest!
Well.. In case of BeginPaint, function has to know where you want to paint to. So you supply a handle to the window, indicating that you want to paint there... And there''s pretty much the same logic behing every function that requires HWND. You see, there are actually many window handles open at the same time, at least one for every window (in different applications). So windows has to be able to know what window you are using in your own program.
The backbone of the windows OS(operating system) is keeping track of all the different windows that have been started by the user. At the start of the program, the OS has to be informed of the presence of the program so that it can send system messages(Mouse movement and button-pressings) to the program. So you would register the presence of your program with the OS and in return you would be given an identifier or handle to it. Any time you would do change something about or in a window, the OS would find which program it was and send a message to the screen display or whatever. Game-Programming books tend to hide that aspect because most are interested only in what THEIR program is doing.
I''m sure others will chime in with clarifications.
ZoomBoy
A 2D RPG with skills, weapons, and adventure.
See my character editor, Tile editor and diary at
Check out my web-site
I''m sure others will chime in with clarifications.
ZoomBoy
A 2D RPG with skills, weapons, and adventure.
See my character editor, Tile editor and diary at
Check out my web-site
mussepigg - I was looking for an example of HWND in general, not using it with the GDI... sorry
ZoomBoy - I still don''t understand!
Anyone else care to try at getting through my thick skull?
Programming::~Fredric(const Annoy_Ance)
ZoomBoy - I still don''t understand!
Anyone else care to try at getting through my thick skull?
Programming::~Fredric(const Annoy_Ance)
3D Math- The type of mathematics that'll put hair on your chest!
Gross oversimplification:
Pretend that somewhere deep inside of the Windows OS there is a class called Window. Think of an HWND as a pointer a Window object. When calling BeginPaint, Windows doesn''t know which window to begin painting in (after all your program can be running multiple windows), so you need to pass a parameter to say which window to begin painting in. So in C++ terms it''s like BeginPaint(hwnd, &ps) is really hwnd->BeginPaint(&ps).
Pretend that somewhere deep inside of the Windows OS there is a class called Window. Think of an HWND as a pointer a Window object. When calling BeginPaint, Windows doesn''t know which window to begin painting in (after all your program can be running multiple windows), so you need to pass a parameter to say which window to begin painting in. So in C++ terms it''s like BeginPaint(hwnd, &ps) is really hwnd->BeginPaint(&ps).
I think I''m getting small grip on HWND... but, again, I really need HWND to be explained to me generally, not in the example I used... Can anyone explain HWND to me GENERALLY?
Programming::~Fredric(const Annoy_Ance)
Programming::~Fredric(const Annoy_Ance)
3D Math- The type of mathematics that'll put hair on your chest!
An HWND is an identifier for your window. Just like a pointer is an identifier to a block of memory, your address is an identifier for your house and your name is an identifier for yourself.
General enough?
General enough?
Zoomboy had a very good explanation, I''ll see if I can make it a little more clear tho...
Your operating system (windows) needs a way of keeping track of all the windows that are present, because it is a multitasking OS. Whenever an application creates a window, that window is registered with the OS so the OS can keep track of it for things like drawing on it (right now as I''m typing the OS is sending signals to the IE browser to refresh as letters are being added, through the handle. As you''re scrolling through this message, the OS is sending the window of your browser messages to update. I have 4 programs up and visible, and each window has its own drawing routines... how does Windows know how to refresh the one I''m working in? It knows which window to send the messages to because it has a handle (HWND))
In many applications you will have multiple windows. In this case your HWND will become more important to you (most games are a single window, which is why HWND isn''t used too often there)
HTH
-fel
Your operating system (windows) needs a way of keeping track of all the windows that are present, because it is a multitasking OS. Whenever an application creates a window, that window is registered with the OS so the OS can keep track of it for things like drawing on it (right now as I''m typing the OS is sending signals to the IE browser to refresh as letters are being added, through the handle. As you''re scrolling through this message, the OS is sending the window of your browser messages to update. I have 4 programs up and visible, and each window has its own drawing routines... how does Windows know how to refresh the one I''m working in? It knows which window to send the messages to because it has a handle (HWND))
In many applications you will have multiple windows. In this case your HWND will become more important to you (most games are a single window, which is why HWND isn''t used too often there)
HTH
-fel
~ The opinions stated by this individual are the opinions of this individual and not the opinions of her company, any organization she might be part of, her parrot, or anyone else. ~
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement