Win32 conflict
I have a question. I have created a window class that creates that will create a window's class, register it, create the window, setup pixel format, and handle messages. The problem is it needs the instance for the program, and I've designed this engine I'm working on to not have a main.cpp with the main function, so the developer using the engine could do that. So I need to get the hinstance to the calss, but how? I know I could make an extra parameter, but there's only one instance. Is that just the only option then?
Quote:Original post by dbzprogrammer
I have a question. I have created a window class that creates that will create a window's class, register it, create the window
If you're creating the window, you have the HWND, correct?
HINSTANCE hinstance = (HINSTANCE)::GetWindowLong(hwnd, GWL_HINSTANCE);
HTH
Oh.......so I can create a another HINSTANCE ans assign it GetModuleHandle(NULL)?
Or would i have to create it by doing the second one?
Or would i have to create it by doing the second one?
Quote:Original post by dbzprogrammer
Oh.......so I can create a another HINSTANCE ans assign it GetModuleHandle(NULL)?
Or would i have to create it by doing the second one?
You can grab your programs HINSTANCE by doing either of those. If you have the HWND for the window, use the second one, otherwise use GetModuleHandle(NULL)
Yes, or rather, you can get a copy of the handle that was supplied to WinMain by argument. It's not really a new instance, since GetModuleHandle does not increase the reference count of the module. In other words you don't have to do any housekeeping. You can discard the handle when you don't need it anymore without having to release/free it in any way.
Take a look at this example at MSDN. It shows how to create a simple dialog box that uses GDI brushes to draw a pattern. That part is not related to you but if you scroll down to the bottom of the page and look at the last piece of code you have:
This is the general way to create a dialog box. The first parameter of DialogBox( ) takes the HINSTANCE of the executable where the dialog box resource is located, in this case the program executable itself; the one supplied by WinMain.
So, this is an example of how to use the GetModuleHandle( ) function. In your case you could do something like this:
I hope this answers your question.
Good luck.
Take a look at this example at MSDN. It shows how to create a simple dialog box that uses GDI brushes to draw a pattern. That part is not related to you but if you scroll down to the bottom of the page and look at the last piece of code you have:
DialogBox((HANDLE)GetModuleHandle(NULL), (LPTSTR)"CustBrush", hWnd, (DLGPROC) BrushDlgProc);
This is the general way to create a dialog box. The first parameter of DialogBox( ) takes the HINSTANCE of the executable where the dialog box resource is located, in this case the program executable itself; the one supplied by WinMain.
So, this is an example of how to use the GetModuleHandle( ) function. In your case you could do something like this:
HINSTANCE hAppInst;hAppInst = (HANDLE)GetModuleHandle( NULL );
I hope this answers your question.
Good luck.
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement