Cheat Engine Forum Index Cheat Engine
The Official Site of Cheat Engine
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 


MultiDialog Applications.

 
Post new topic   Reply to topic    Cheat Engine Forum Index -> General programming
View previous topic :: View next topic  
Author Message
WafflesFTW
Expert Cheater
Reputation: 0

Joined: 21 Mar 2008
Posts: 131

PostPosted: Tue Jun 24, 2008 8:17 am    Post subject: MultiDialog Applications. Reply with quote

Basically, what I want, is when the IDC_BUTTON1 button is clicked, a second dialog will pop up. What happens, is after I click the button. Everything closes. Help would be greatly appreciated.

Code:

#include <windows.h>
#include <resource.h>

LRESULT WINAPI DialogProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam);
LRESULT WINAPI DialogChildProc(HWND hWndChild, UINT message, WPARAM wParam, LPARAM lParam);
HINSTANCE instance;
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance,
    LPSTR lpCmdLine, int nCmdShow)
{
   WNDCLASSEX WindowClass;
   instance = hInstance;

   static LPCTSTR szAppName = L"OFWin";
   HWND hWnd;
   MSG msg;

   WindowClass.cbSize = sizeof(WNDCLASSEX);
   WindowClass.style = CS_HREDRAW | CS_VREDRAW;
   WindowClass.lpfnWndProc = DialogProc;
   WindowClass.cbClsExtra = 0;
   WindowClass.cbWndExtra = 0;
   WindowClass.hInstance = hInstance;
   WindowClass.hIcon = LoadIcon(0, IDI_APPLICATION);
   WindowClass.hCursor = LoadCursor(0, IDC_ARROW);
   WindowClass.hbrBackground = (HBRUSH)(COLOR_MENU);
   WindowClass.lpszMenuName = 0;
   WindowClass.lpszClassName = szAppName;
   WindowClass.hIconSm = 0;

   RegisterClassEx(&WindowClass);

   hWnd = CreateDialog(
      hInstance,
      MAKEINTRESOURCE(IDD_DIALOG1),
      0,
      (DLGPROC)DialogProc
      );


   

   while(GetMessage(&msg, 0, 0, 0) == TRUE)
   {
      TranslateMessage(&msg);
      DispatchMessage(&msg);
   }


   return static_cast<int>(msg.wParam);
}



LRESULT WINAPI DialogProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
{
   switch(message)
   {
   case WM_COMMAND:
      switch(LOWORD(wParam))
      {
      case IDC_BUTTON1:
         {
            HWND hWndChild = CreateDialog(
               instance,
               MAKEINTRESOURCE(IDD_DIALOG2),
               0,
               (DLGPROC)DialogChildProc
               );
         }
         break;
      }
   break;
            
   case WM_DESTROY:
        PostQuitMessage(0);
        return TRUE;
   
   case WM_CLOSE:
        DestroyWindow (hWnd);
        return TRUE;

   default:
      return DefWindowProc(hWnd, message, wParam, lParam);
      
   }

}
LRESULT WINAPI DialogChildProc(HWND hWndChild, UINT message, WPARAM wParam, LPARAM lParam)
{
   switch(message)
   {
   case WM_DESTROY:
        PostQuitMessage(0);
        return TRUE;
   
   case WM_CLOSE:
        DestroyWindow (hWndChild);
        return TRUE;

   default:
      return DefWindowProc(hWndChild, message, wParam, lParam);
      
   }

}



Back to top
View user's profile Send private message AIM Address
tombana
Master Cheater
Reputation: 2

Joined: 14 Jun 2007
Posts: 456
Location: The Netherlands

PostPosted: Tue Jun 24, 2008 10:10 am    Post subject: Reply with quote

First of all, since you're using resource dialogs, you don't have to create a window class. So forget that whole part. Next to that, resource dialogs don't need a message loop, it's done automatically.

From Win32 Programmer's reference:
Quote:
Although the dialog box procedure is similar to a window procedure, it must not call the DefWindowProc function to process unwanted messages. Unwanted messages are processed internally by the dialog box window procedure.

You use DefWindowProc in you're DialogProcedure. You shouldn't do that if you use resource dialogs. You should only use it with windows created with CreateWindow(Ex).


EDIT: If you didn't want to use resource dialogs, you should do CreateWindowEx instead of CreateDialog, and then the rest of the code would be correct.
Back to top
View user's profile Send private message
WafflesFTW
Expert Cheater
Reputation: 0

Joined: 21 Mar 2008
Posts: 131

PostPosted: Tue Jun 24, 2008 10:17 am    Post subject: Reply with quote

Thank you very much. I'm still new to this stuff. So no need to register class when using dialogs? Very cool thanks Very Happy
Back to top
View user's profile Send private message AIM Address
HomerSexual
Grandmaster Cheater Supreme
Reputation: 5

Joined: 03 Feb 2007
Posts: 1657

PostPosted: Tue Jun 24, 2008 10:18 am    Post subject: Reply with quote

tombana wrote:
First of all, since you're using resource dialogs, you don't have to create a window class. So forget that whole part. Next to that, resource dialogs don't need a message loop, it's done automatically.

From Win32 Programmer's reference:
Quote:
Although the dialog box procedure is similar to a window procedure, it must not call the DefWindowProc function to process unwanted messages. Unwanted messages are processed internally by the dialog box window procedure.

You use DefWindowProc in you're DialogProcedure. You shouldn't do that if you use resource dialogs. You should only use it with windows created with CreateWindow(Ex).


EDIT: If you didn't want to use resource dialogs, you should do CreateWindowEx instead of CreateDialog, and then the rest of the code would be correct.


DIALOGS NEED A MESSAGE LOOP (except for like the open/save/print dialogs)

_________________
Back to top
View user's profile Send private message
tombana
Master Cheater
Reputation: 2

Joined: 14 Jun 2007
Posts: 456
Location: The Netherlands

PostPosted: Tue Jun 24, 2008 11:02 am    Post subject: Reply with quote

blankrider wrote:
DIALOGS NEED A MESSAGE LOOP (except for like the open/save/print dialogs)

I've written a few apps which use resource dialogs, and they work without a message loop. (There probably is a message loop but not in my code, it'll be some in user32.dll or whatever)
Afaic you only need to code a messageloop if you create the dialog with CreateWindow(Ex).
Back to top
View user's profile Send private message
WafflesFTW
Expert Cheater
Reputation: 0

Joined: 21 Mar 2008
Posts: 131

PostPosted: Tue Jun 24, 2008 12:15 pm    Post subject: Reply with quote

Ok, I did what you said, and now NOTHING comes up, not even the first dialog.

http://pastebin.com/d64a88de8

That's my code.

Help please Very Happy
Back to top
View user's profile Send private message AIM Address
tombana
Master Cheater
Reputation: 2

Joined: 14 Jun 2007
Posts: 456
Location: The Netherlands

PostPosted: Tue Jun 24, 2008 12:30 pm    Post subject: Reply with quote

Try using DialogBox() instead of CreateDialog().
When you use CreateDialog(), the dialog box is created, but then the main functions exits, and the app is quit immediately. When you use DialogBox(), the dialog box is created, and the app will wait for the dialogbox to be closed, and then continues.
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    Cheat Engine Forum Index -> General programming All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
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


Powered by phpBB © 2001, 2005 phpBB Group

CE Wiki   IRC (#CEF)   Twitter
Third party websites