#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
:-)
gobal handler to function handler
hi....
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
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
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
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
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
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
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement