Difference between hInstance and hWnd (and now other questions)

Started by
8 comments, last by Celvin 16 years, 5 months ago
I'm completing the NeHe tutorials and I just want to make sure that I've got this correct. As I understand it: hWnd is the window's handle and is how the OS defines a window when talking about it inside the PC. hInstance is the OS' handle for the program when running it. The difference between hInstance and HWND is that the instance is creating the window and in theory you could run a program that creates multiple windows. I should not think of the window as the program itself. Or am I horribly wrong? ^_^ [Edited by - rossmills on November 23, 2007 2:28:55 PM]
Advertisement
You are right.

In fact, the only thing a HWND and a HINSTANCE have in common is that both are handles (I think they are also typedef's to a same type)

The HWND is the handle on the window that Windows makes available to the user when the OS creates the window.

For the HINSTANCE, I think it is the handle on the process that Windows makes available to the user, when it creates the process. But I am not sure on this one. It could be an handle on the process, or something else that identifies uniquely the instance of the application.


Thanks.

One of the main reasons I got confused was because I was used to thinking in terms of each window being a separate program, which is not correct. That's what comes with using computers casually, I guess.

Edit: What is GLuint?

I see reference to it everywhere, yet cannot find what it actually *does*! 0_o

Is there a site that would describe such things in future? I checked OpenGL.org and MSDN.com.

Thanks for any help you can give.
I'm not familiar with OpenGL but I'd assume an OpenGL typedef'd unsigned integer
So what is GLint used for that int can't do?

Edit: I have been informed that GLint is merely designed so that you can be assured that it is always 32 bits long.

If this is wrong, feel free to correct me.

New issue

Later on, NeHe's first tutorial states:

"In the next section of code, we grab an instance for our Window, then we declare the Window Class."

I am confused by this, surely you must define a class before instancing it?

Or am I completely misinterpreting that statement?
Quote:Original post by rossmills
"In the next section of code, we grab an instance for our Window, then we declare the Window Class."

I am confused by this, surely you must define a class before instancing it?

Or am I completely misinterpreting that statement?


AFAIK, "classes" in the Windows API sense have nothing to do with C++ classes.
Quote:
Original post by rossmills
"In the next section of code, we grab an instance for our Window, then we declare the Window Class."

I am confused by this, surely you must define a class before instancing it?

Or am I completely misinterpreting that statement?


By grabbing an instance i reckon they mean to get the HINSTANCE handle. By itself this is just an identifier (handle) to your process.

HWNDs (windows) are created inside a process.

A window class is not a class in the programming language sense. It is merely a collection of possible window properties.

Common classes are EDIT or LISTBOX. They define a basic look and behaviour of the window.

Fruny: Ftagn! Ia! Ia! std::time_put_byname! Mglui naflftagn std::codecvt eY'ha-nthlei!,char,mbstate_t>

Quote:Original post by rossmills
So what is GLint used for that int can't do?

Cross platform compatible.
It basically just allows the OpenGL implementers to pick "the right" size for the integers used in the OGL api, without being forced to use "whatever 'int' is on this platform".
I don't know if GLint will *always* be 32 bit. But it'll always be the size needed by the OpenGL API.

[uote]
"In the next section of code, we grab an instance for our Window, then we declare the Window Class."

I am confused by this, surely you must define a class before instancing it?

Or am I completely misinterpreting that statement?
Hehe yeah. The Win32 API is C, not C++. Classes don't exist in the OO sense.
Instead, think of it using the "original" definition of the word 'class': Basically just "type" or "category".
When you define your window class, you just define a category of windows, or a template for creating windows, you're saying "whenever I try to create a window based on the class X, it should have these properties set to these values".
Just making sure I understand correctly.

The concept of making a "window" is already a standard thing within the API, so all a window Class is in C is providing specifics for the variables associated with that window.

...right?

So can I call on that class multiple times at the same time? Or would that be thinking too OO?
Quote:
For the HINSTANCE, I think it is the handle on the process that Windows makes available to the user, when it creates the process.

Nope, a HINSTANCE is not a process handle (such as returned by OpenProcess).
For a quick description, see http://blogs.msdn.com/oldnewthing/archive/2004/06/14/155107.aspx

If you're curious about why you need to pass a HINSTANCE to CreateWindow, see http://blogs.msdn.com/oldnewthing/archive/2005/04/18/409205.aspx

This topic is closed to new replies.

Advertisement