Sign in to follow this  

Difference between hInstance and hWnd (and now other questions)

This topic is 3676 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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]

Share this post


Link to post
Share on other sites
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.


Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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?

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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?[/quote]
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".

Share this post


Link to post
Share on other sites
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?

Share this post


Link to post
Share on other sites
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

Share this post


Link to post
Share on other sites

This topic is 3676 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this