 |
Cheat Engine The Official Site of Cheat Engine
|
View previous topic :: View next topic |
Author |
Message |
NoMercy Master Cheater
Reputation: 1
Joined: 09 Feb 2009 Posts: 289
|
Posted: Mon Feb 28, 2011 9:14 am Post subject: Not global class object, usable in win32 WNDPROC |
|
|
Hello everyone,
I've got a problem with using my class object.
Code: | int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance,LPSTR lpCmdLine, int nCmdShow)
{
static Dialog MainDialog(hInstance,L"MainWindClass",L"NCE",WndMainWindow,200,200);
MainDialog.Create();
} |
This is a win32 class wrapper and it does make the gui, which works. So it also makes the WNDPROC.
Code: | LRESULT CALLBACK WndMainWindow(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
{
switch( message)
{
case WM_CREATE:
MainDialog.CreateButton(true,L"Open",2,2,20,20,0);
break;
case WM_COMMAND:
break;
case WM_CLOSE:
ShowWindow(hWnd,SW_HIDE);
break;
default:
return DefWindowProc(hWnd, message, wParam, lParam);
}
return DefWindowProc(hWnd, message, wParam, lParam);
} |
as you can see in the WM_CREATE, I would like to use the MainDialog class object again to create all my buttons and things.
How can I pass this the best way to this or shall I make a another class for this work?
Grz.
|
|
Back to top |
|
 |
atom0s Moderator
Reputation: 205
Joined: 25 Jan 2006 Posts: 8587 Location: 127.0.0.1
|
Posted: Mon Feb 28, 2011 12:52 pm Post subject: |
|
|
Well based on the code you are showing, that shouldn't even compile. MainDialog is defined in the scope of WinMain, so your WNDPROC shouldn't even know it exists.
You need to globally declare it if you want to use it outside the scope of WinMain.
_________________
- Retired. |
|
Back to top |
|
 |
NoMercy Master Cheater
Reputation: 1
Joined: 09 Feb 2009 Posts: 289
|
Posted: Mon Feb 28, 2011 12:54 pm Post subject: |
|
|
Wiccaan wrote: | Well based on the code you are showing, that shouldn't even compile. MainDialog is defined in the scope of WinMain, so your WNDPROC shouldn't even know it exists.
You need to globally declare it if you want to use it outside the scope of WinMain. |
Yes, that is the problem, I gave it as example what I want. I wanna know which otion I should choose or if there is a better option.
1. Create a new class for creatting buttons, etc
2. Make the class Global ( in a namespace or just global, isnt that bad?)
3. Anything else?
|
|
Back to top |
|
 |
Slugsnack Grandmaster Cheater Supreme
Reputation: 71
Joined: 24 Jan 2007 Posts: 1857
|
Posted: Mon Feb 28, 2011 6:54 pm Post subject: |
|
|
it looks like you're creating a dialog ? in which case you should not be returning defwindowproc. you should just return true if you processed the message. false otherwise.
|
|
Back to top |
|
 |
atom0s Moderator
Reputation: 205
Joined: 25 Jan 2006 Posts: 8587 Location: 127.0.0.1
|
Posted: Mon Feb 28, 2011 7:18 pm Post subject: |
|
|
NoMercy wrote: | Wiccaan wrote: | Well based on the code you are showing, that shouldn't even compile. MainDialog is defined in the scope of WinMain, so your WNDPROC shouldn't even know it exists.
You need to globally declare it if you want to use it outside the scope of WinMain. |
Yes, that is the problem, I gave it as example what I want. I wanna know which otion I should choose or if there is a better option.
1. Create a new class for creatting buttons, etc
2. Make the class Global ( in a namespace or just global, isnt that bad?)
3. Anything else? |
The way you are doing it in that example above more follow more to a singleton then anything. Which isn't a terrible thing to do for a single window that you don't want to recreate. (That is, if you are doing a single window.)
It's mainly up to you how you want to wrap the functions up and expose them. Everyone will have their opinions against what you come up with, but basically in the end if its error free and works for your needs, then go with what works best for you.
Regardless though, if you want to be able to interact with the object in various functions, you will need to make it global. (Or pass a pointer around via a param.)
_________________
- Retired. |
|
Back to top |
|
 |
NoMercy Master Cheater
Reputation: 1
Joined: 09 Feb 2009 Posts: 289
|
Posted: Tue Mar 01, 2011 2:38 am Post subject: |
|
|
Slugsnack wrote: | it looks like you're creating a dialog ? in which case you should not be returning defwindowproc. you should just return true if you processed the message. false otherwise. |
Weird, but I followed the http://msdn.microsoft.com/en-us/library/bb384843.aspx tutorial once , there they do it like this.
That was my question, I always hears making global variables is bad, but making a global class
Code: | Class x
{
//
}
x GlobalX |
Isnt it bad to have GlobalX global?
|
|
Back to top |
|
 |
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum You cannot attach files in this forum You can download files in this forum
|
|