Archived

This topic is now archived and is closed to further replies.

gobal handler to function handler

This topic is 5236 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

hi....
#define WIN32_LEAN_AND_MEAN
#include <windows.h>

HWND g_hwnd = NULL; // gobal handler

.
.
.

bool CreateWindowApp(HWND, HINSTANCE, char[]);
.
.
.

int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance,
				   LPSTR lpstrCmdLine, int iCmdShow)
{
   //passing g_hwnd through CreateWindowApp

   CreateWindowApp(g_hwnd, hInstance, clsn); 
   .
   .
   .
}
.
.
.

bool CreateWindowApp(HWND hwnd, HINSTANCE hinstance, char classn[])
{
	hwnd = CreateWindowEx(NULL,
				classn,
				"Yahooo",
				WS_OVERLAPPEDWINDOW,
				0,
				0,
				CW_USEDEFAULT,
				CW_USEDEFAULT,
				GetDesktopWindow(),
				NULL,
				hinstance,
				NULL);
	if(hwnd)
	{
		return true;
	}
	else
	{
		return false;
	}
}
.
.
.
Question: Why it won''t initialize my g_hwnd in CreateWindowApp()... when i pass to it...... Thanks :-)

Share this post


Link to post
Share on other sites
g_hwnd is global

you make a call to "CreateWindowApp(g_hwnd, hInstance, clsn); "
this call sends a copy of g_hwnd (call by value) , the function will change the copy and not g_hwnd;

just change CreateWindowApp to

bool CreateWindowApp( HINSTANCE hinstance, char classn[])
{ g_hwnd = CreateWindowEx(...)
...
}

no need to pass a global varible , since its global , just change it in every function you want

Share this post


Link to post
Share on other sites
First off, since the HWND is global, you don''t need to pass it to the function. But I assume you''re looking for a little more modularity in the end, so the reason it''s not working may be that you need to pass a pointer to the HWND and have the function accept a pointer to an HWND. I can''t remember if HWND is actually a typdefed-over pointer. If it is, I would probably be wrong...

The only other thought I have is that you never registered the class name, but I imagine you did that. Oh, and maybe for the parent window, try NULL instead of GetDesktopWindow().

-Auron

Share this post


Link to post
Share on other sites
Or you could use pass-by-reference instead of pass-by-value:

bool CreateWindowApp(HWND&, HINSTANCE, char[]);

With that ampersand in there (and in the function itself, too) it should work with no changes.

Superpig
- saving pigs from untimely fates, and when he''s not doing that, runs The Binary Refinery.
Enginuity1 | Enginuity2 | Enginuity3 | Enginuity4

Share this post


Link to post
Share on other sites