Results 1 to 10 of 10

Thread: GUI stuff

  1. #1

    Thread Starter
    Addicted Member Cbomb's Avatar
    Join Date
    Jul 1999
    Posts
    153

    GUI stuff

    I'm trying to create a GUI for a simple program I'm working on. I figured out how to use resource dialogs (in VC++ 5). And making a GUI in that is sooo easy. Is it possible to use just this dialog for my program?

    I can't seem to word this correctly. I guess what I want is a dialog with no parent.

    Any help would be great. Thanks.
    Cbomb
    Techie

  2. #2
    PowerPoster abdul's Avatar
    Join Date
    Dec 2000
    Location
    Ontario,Canada
    Posts
    2,827
    If you just want that dialog to show up when your program starts, then it's possible!

    (I actually did not fully understand your question)
    Baaaaaaaaah

  3. #3

    Thread Starter
    Addicted Member Cbomb's Avatar
    Join Date
    Jul 1999
    Posts
    153

    lol i know...

    Basically. The visible application would be just that dialog. I just dont want to do a bunch of "CreateWindows" to make everything.

    Better?
    Cbomb
    Techie

  4. #4
    PowerPoster abdul's Avatar
    Join Date
    Dec 2000
    Location
    Ontario,Canada
    Posts
    2,827
    You just need to call "CreateDialog" or "ShowDialog" to make the dialog visible.

    Here is a simple dialog based app that just shows a dialogbox (stored in a resource file) when the program starts:

    Code:
    #include <windows.h>
    #include "resource.h"
    static HINSTANCE hinst = NULL;
    
    BOOL CALLBACK DlgProc(HWND, UINT, WPARAM, LPARAM);
    
    HWND dlghwnd;
    
    int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance,
       LPSTR lpCmdLine, int nCmdShow)
    {
       WNDCLASSEX WndClass;
       MSG Msg;
    
       hinst = hInstance;
    
       dlghwnd = CreateDialog(hinst, MAKEINTRESOURCE(MYDLG), NULL, DlgProc);
    
       ShowWindow(dlghwnd, nCmdShow);
       UpdateWindow(dlghwnd);
    
       while(GetMessage(&Msg, NULL, 0, 0))
       {
          TranslateMessage(&Msg);
          DispatchMessage(&Msg);
       }
       return Msg.wParam;
    }
    
    
    
    
    
    BOOL  CALLBACK DlgProc(HWND hwnd, UINT Message, WPARAM wparam, LPARAM lparam)
    {
    	
       switch(Message)
       {
       
       case WM_INITDIALOG:
    
    	   return TRUE;
    
    
          case WM_CLOSE:
    		  EndDialog(hwnd, 0);
             PostQuitMessage(0);
    
    		 return TRUE;
          
       }
       return FALSE;
    }
    Baaaaaaaaah

  5. #5

    Thread Starter
    Addicted Member Cbomb's Avatar
    Join Date
    Jul 1999
    Posts
    153

    cool

    Ok it compiles 0 errs 0 warns but when I run it there is no window. I check running processes and it IS there, so I kill it.

    Heres my code:

    Code:
    #include <windows.h>
    #include "resource.h"
    
    HWND dlghwnd;
    
    BOOL CALLBACK DlgProc(HWND hwnd, UINT Message, WPARAM wParam, LPARAM lParam)
    {
        return TRUE;
    }
    
    int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow)
    {
       MSG Msg;
       HINSTANCE hinst;
       hinst = hInstance;
    
       dlghwnd = CreateDialog(hinst, MAKEINTRESOURCE(ID_dialog_compviewer), NULL, (WNDENUMPROC)DlgProc);
    
       ShowWindow(dlghwnd, nCmdShow);
       UpdateWindow(dlghwnd);
    
       while(GetMessage(&Msg, NULL, 0, 0))
       {
          TranslateMessage(&Msg);
          DispatchMessage(&Msg);
       }
       return Msg.wParam;
    }
    What am I not doing? Thanks.
    Cbomb
    Techie

  6. #6
    PowerPoster abdul's Avatar
    Join Date
    Dec 2000
    Location
    Ontario,Canada
    Posts
    2,827

    Re: cool

    I just made a little changes to the code. See if that helps

    Code:
    #include <windows.h>
    #include "resource.h"
    
    HWND dlghwnd;
    
    BOOL CALLBACK DlgProc(HWND hwnd, UINT Message, WPARAM wParam, LPARAM lParam)
    {
         switch(Message)
       {
       
       case WM_INITDIALOG:  //You need to handle this messages and return
    						//TRUE for that
    
    	   return TRUE;
    
    
          case WM_CLOSE:  //If you want close the dialog box and exit the
    					 //program then you also need to handle this message
    		  DestroyWindow(hwnd); //Closes the dialog box
             PostQuitMessage(0);  //Exit the program
    
    		 return TRUE;
          
       }
       return FALSE;  // Return FALSE for any other message that we dont
    					//care of
    }
    
    int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow)
    {
       MSG Msg;
       HINSTANCE hinst;
       hinst = hInstance;
    
       dlghwnd = CreateDialog(hinst, MAKEINTRESOURCE(ID_dialog_compviewer), NULL, DlgProc); //You dont need "WNDENUMPROC" here 
    
       ShowWindow(dlghwnd, nCmdShow);
       UpdateWindow(dlghwnd);
    
       while(GetMessage(&Msg, NULL, 0, 0))
       {
          TranslateMessage(&Msg);
          DispatchMessage(&Msg);
       }
       return Msg.wParam;
    }
    Baaaaaaaaah

  7. #7

    Thread Starter
    Addicted Member Cbomb's Avatar
    Join Date
    Jul 1999
    Posts
    153

    (WNDENUMPROC)

    if I dont put the (WNDENUMPROC) in there I get this error:

    error C2664: 'CreateDialogParamA' : cannot convert parameter 4 from 'int (void *,unsigned int,unsigned int,long)' to 'int (__stdcall *)(void)'

    ??
    Cbomb
    Techie

  8. #8
    PowerPoster abdul's Avatar
    Join Date
    Dec 2000
    Location
    Ontario,Canada
    Posts
    2,827
    I get an error message when I use WNDENUMPROC in VC++. Just leave it where it is and then try to run your code
    Baaaaaaaaah

  9. #9
    Frenzied Member
    Join Date
    Jun 2000
    Location
    England, Buckingham
    Posts
    1,341

  10. #10

    Thread Starter
    Addicted Member Cbomb's Avatar
    Join Date
    Jul 1999
    Posts
    153

    WOOHO!

    That example project works great! Thank you.
    Cbomb
    Techie

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width