| View previous topic :: View next topic |
| Author |
Message |
TraxMate Master Cheater
Reputation: 0
Joined: 01 Mar 2008 Posts: 363
|
Posted: Wed Feb 11, 2009 12:46 pm Post subject: [C++] Windows in a dll |
|
|
I know how to create windows trough a dll and it's working fine, but when I want to have more then one window the problem starts. The new window isn't showing, I know I've done everything right because it's working when I create a window trough a normal executable. But just in case I'm posting the source incase something isn't right..
| Code: | BOOL APIENTRY DllWnd(HINSTANCE hInstance)
{
WNDCLASSEX wc;
HWND hWnd;
MSG Msg;
wc.cbClsExtra = 0;
wc.cbSize = sizeof(WNDCLASSEX);
wc.cbWndExtra = 0;
wc.hbrBackground = (HBRUSH)COLOR_BTNSHADOW;
wc.hCursor = LoadCursor(0, IDC_ARROW);
wc.hIcon = LoadIcon(0, IDI_APPLICATION);
wc.hIconSm = LoadIcon(0, IDI_APPLICATION);
wc.hInstance = hInstance;
wc.lpfnWndProc = WndProc;
wc.lpszClassName = Class;
wc.lpszMenuName = 0;
wc.style = 0;
if(!RegisterClassEx(&wc))
{
MessageBox(NULL, L"Unable to create the window!", L"Error!", MB_OK);
return 0;
}
wc.lpfnWndProc = ProcWnd;
wc.lpszClassName = WndClass;
RegisterClassEx(&wc);
hWnd = CreateWindowEx(0, Class, L"The Window", WS_OVERLAPPEDWINDOW, CW_USEDEFAULT, CW_USEDEFAULT, 150, 150, NULL, NULL, hInstance, 0);
ShowWnd(hWnd); // <-- This window refuses to show...
ShowWindow(hWnd, SW_SHOWNORMAL);
UpdateWindow(hWnd);
while(GetMessage(&Msg, NULL, NULL, NULL) > 0)
{
TranslateMessage(&Msg);
DispatchMessage(&Msg);
}
return Msg.wParam;
}
BOOL APIENTRY DllMain(HMODULE hModule, DWORD dwReason, LPVOID lpReserved)
{
switch(dwReason)
{
case DLL_PROCESS_ATTACH:
CreateThread(0, 0, (LPTHREAD_START_ROUTINE)DllWnd, hModule, 0, 0);
break;
case DLL_PROCESS_DETACH:
break;
}
return TRUE;
} | And 'ShowWnd()' code
| Code: | BOOL ShowWnd(HWND hParent)
{
HINSTANCE hInstance;
HWND hWnd;
if(hWnd = FindWindow(WndClass, NULL))
{
if(hWnd != NULL)
SetForegroundWindow(hWnd);
}
else
{
hInstance = GetModuleHandle(NULL);
hWnd = CreateWindowEx(WS_EX_TOOLWINDOW, WndClass, L"The Wnd Window", WS_CAPTION | WS_SYSMENU, CW_USEDEFAULT, CW_USEDEFAULT, 100, 100, hParent, NULL, hInstance, 0);
return ShowWindow(hWnd, SW_SHOW);
}
return FALSE;
} |
|
|
| Back to top |
|
 |
Stylo Grandmaster Cheater Supreme
Reputation: 3
Joined: 16 May 2007 Posts: 1073 Location: Israel
|
Posted: Wed Feb 11, 2009 1:03 pm Post subject: |
|
|
why r u calling Registerclassex twice?
and why ShowWindow comes after your ShowWnd function? isn't it suppose to be the opposite?
edit: did you check that Class & WndClass contains the same value?
|
|
| Back to top |
|
 |
TraxMate Master Cheater
Reputation: 0
Joined: 01 Mar 2008 Posts: 363
|
Posted: Wed Feb 11, 2009 1:15 pm Post subject: |
|
|
| 1qaz wrote: | why r u calling Registerclassex twice?
and why ShowWindow comes after your ShowWnd function? isn't it suppose to be the opposite?
edit: did you check that Class & WndClass contains the same value? | I'm calling RegisterClassEx() twice because I'm registering two classes, I don't know if I can use one for both.
ShowWnd() is a new window not something I call to make the first window show. Class and WndClass does not have the same value. Class is for the first window and WndClass is for the second window I want to show.
|
|
| Back to top |
|
 |
Stylo Grandmaster Cheater Supreme
Reputation: 3
Joined: 16 May 2007 Posts: 1073 Location: Israel
|
Posted: Wed Feb 11, 2009 1:21 pm Post subject: |
|
|
as far as i know if you want to create a child window it suppose to have the same class name as the parent window
about the class registration i'd define two WNDCLASSEX and work with both but i don't know about your way it could be good too
|
|
| Back to top |
|
 |
TraxMate Master Cheater
Reputation: 0
Joined: 01 Mar 2008 Posts: 363
|
Posted: Wed Feb 11, 2009 1:31 pm Post subject: |
|
|
I want it to be a child window but in the same time be its own window and then it has to have it's own class name.
I've always been using this way to register two classes, it's the way i learned, and I learned win32 from lurc's WindowTemplate and this is almost an exact copy of it but in a dll. So I'm a little confused why this isn't working in a dll.
|
|
| Back to top |
|
 |
Stylo Grandmaster Cheater Supreme
Reputation: 3
Joined: 16 May 2007 Posts: 1073 Location: Israel
|
Posted: Wed Feb 11, 2009 1:52 pm Post subject: |
|
|
it can't be independent window if you open it through other window
maybe if you'll create it own executable file it can
you even set the parent window to be his parent window when calling createwindowex.
so you can't set it other class name :S
|
|
| Back to top |
|
 |
TraxMate Master Cheater
Reputation: 0
Joined: 01 Mar 2008 Posts: 363
|
Posted: Wed Feb 11, 2009 2:00 pm Post subject: |
|
|
Yes you can I've done it before. Im really bad at explaining so if you take a look at lurc's WindowTemplate and my source maybe you'll understand what I mean better.
|
|
| Back to top |
|
 |
Stylo Grandmaster Cheater Supreme
Reputation: 3
Joined: 16 May 2007 Posts: 1073 Location: Israel
|
Posted: Thu Feb 12, 2009 5:32 am Post subject: |
|
|
even the file you upload proof what i said ...
a new window that created through other window cannot be independent
since his creating window it's his parent
or else we miss understood each other?
|
|
| Back to top |
|
 |
TraxMate Master Cheater
Reputation: 0
Joined: 01 Mar 2008 Posts: 363
|
Posted: Thu Feb 12, 2009 8:42 am Post subject: |
|
|
| I think we missunderstood eachother. I don't want it to be independant, I want both windows to show when I inject it just like the WindowTemplate. It's not independant but it has it own window and procedure if you understand what I mean.
|
|
| Back to top |
|
 |
Anden100 Grandmaster Cheater
Reputation: 0
Joined: 20 Apr 2007 Posts: 668
|
Posted: Fri Feb 13, 2009 5:06 am Post subject: |
|
|
| TraxMate wrote: | | I think we missunderstood eachother. I don't want it to be independant, I want both windows to show when I inject it just like the WindowTemplate. It's not independant but it has it own window and procedure if you understand what I mean. |
So, what you are saying is, that you wish to create two windows?
|
|
| Back to top |
|
 |
TraxMate Master Cheater
Reputation: 0
Joined: 01 Mar 2008 Posts: 363
|
Posted: Fri Feb 13, 2009 5:24 am Post subject: |
|
|
| Anden100 wrote: | | So, what you are saying is, that you wish to create two windows? | Yes that's what I want to do.
|
|
| Back to top |
|
 |
Stylo Grandmaster Cheater Supreme
Reputation: 3
Joined: 16 May 2007 Posts: 1073 Location: Israel
|
Posted: Fri Feb 13, 2009 5:47 am Post subject: |
|
|
ok i succeeded to do what your saying
look
first of all you should call ShowWindow for the Parent window to open
then call other showwindow to pop the child window
here's an example
http://rapidshare.com/files/197563485/Win32Multi.rar.html
|
|
| Back to top |
|
 |
TraxMate Master Cheater
Reputation: 0
Joined: 01 Mar 2008 Posts: 363
|
Posted: Fri Feb 13, 2009 6:11 am Post subject: |
|
|
Yes thtas how I want it. Thanks .
EDIT: I just found an easier way, it looks exactly like my first post but instead of using hMdoule I used GetModuleHandle() and it works as normal
|
|
| Back to top |
|
 |
|