Thread: Dialog Problems

  1. #1
    Registered User
    Join Date
    Aug 2004
    Posts
    9

    Dialog Problems

    I'm trying to create a program with a dialog as the main window but it doesn't display. What am I doing wrong? (Using Dev-cpp)

    Dialog Resource:
    Code:
    IDD_MAIN DIALOG 146, 39, 260, 265
    STYLE WS_POPUP | WS_VISIBLE | WS_CAPTION | WS_SYSMENU
    CAPTION "Dialog Title"
    FONT 8, "MS Sans Serif"
    BEGIN
        LISTBOX         301, 12, 47, 120, 192, LBS_SORT | WS_VSCROLL | WS_TABSTOP
        LTEXT           "View", 302, 12, 17, 20, 12
        COMBOBOX        303, 13, 26, 120, 83, CBS_DROPDOWN | CBS_SORT | WS_VSCROLL | WS_TABSTOP
        IDB_ADDENTRY PUSHBUTTON      "Add Entry", 304, 14, 239, 55, 14
        IDB_DELETEENTRY PUSHBUTTON      "Delete Entry", 305, 75, 239, 55, 14
        GROUPBOX        "Entries", 306, 6, 6, 132, 254
    END
    Main File:
    Code:
    #include <windows.h>
    #include "resource.h"
    
    BOOL CALLBACK MainDlgProc(HWND hwnd, UINT Message, WPARAM wParam, LPARAM lParam)
    {
    	switch(Message)
    	{
    		case WM_INITDIALOG:
    		    ;
    		break;
    		case WM_CLOSE:
    			EndDialog(hwnd, 0);
    		break;
    		case WM_COMMAND:
    		
    		break;
    		case WM_DESTROY:
    			
    		break;
    		default:
    		    	
    			return FALSE;
    	}
    	return TRUE;
    }
    
    int WINAPI WinMain (HINSTANCE hInstance,
                        HINSTANCE hPrevInstance,
                        LPSTR lpszCmdLine,
                        int nCmdShow)
    
    {
        return DialogBox(GetModuleHandle(NULL), 
                    MAKEINTRESOURCE(IDD_MAIN), hwnd, MainDlgProc);
    }
    Thanks for any help...
    Last edited by CV3; 08-25-2004 at 10:45 AM. Reason: Fix typos

  2. #2
    Registered User
    Join Date
    Dec 2002
    Posts
    35
    So far i have not see your resource.h but be resource contains an ID number. And your RC file doesnt has " #include "resource.h" " line.

    You dont need GetModuleHandle(NULL) since you have "HINSTANCE hInstance" in main. Use "hInstance" there.

    And most important:

    int DialogBox(

    HINSTANCE hInstance, // handle to application instance
    LPCTSTR lpTemplate, // identifies dialog box template
    HWND hWndParent, // handle to owner window
    DLGPROC lpDialogFunc // pointer to dialog box procedure
    );

    yours:

    hwnd, MainDlgProc

    hwnd: completely wrong use "0". A dialog never be a parent of itself Maybe desktop.

    MainDlgProc: for this, try to adding (DLGPROC) casting.
    Code:
    return DialogBox(hInstance, 
                    MAKEINTRESOURCE(IDD_MAIN), 0, (DLGPROC) MainDlgProc);
    Want to learn? Then try to teach...

  3. #3
    Registered User
    Join Date
    Jan 2004
    Posts
    24
    I'm not an expert at windows but dont you have an extra ) after IDD_MAIN in MAKEINTRESOURCE?

  4. #4
    Registered User
    Join Date
    Aug 2004
    Posts
    9
    Linuxman - I don't see that

    fizisyen - thanks for your reply. That isn't the whole of my .rc file just the part with the dialog code The dialog is defined properly in resource.h as well.

    I tried eveything you suggested but the program just exits without displaying the dialog at all.

  5. #5
    Registered User
    Join Date
    Dec 2002
    Posts
    35
    these lines are wrong,
    Code:
        IDB_ADDENTRY PUSHBUTTON      "Add Entry", 304, 14, 239, 55, 14
        IDB_DELETEENTRY PUSHBUTTON      "Delete Entry", 305, 75, 239, 55, 14
    must,
    Code:
        PUSHBUTTON      "Add Entry",IDB_ADDENTRY, 304, 14, 239, 55, 14
        PUSHBUTTON      "Delete Entry",IDB_DELETEENTRY , 305, 75, 239, 55, 14
    and one more mingw specific "WARNING": always be sure your resource files names(.rc) diffrent from some other implementation file(.c .cpp) . Because, every compiled file has the same extension ".o" so, not important what is the extension(.cpp or .rc) this will do by DevC++ automatically by adding "_res.h". But please use project templates. There are every possible needs for you.

    And i compiled successfully your source. Anyway, this is Relo project(freeware ide like Dev)
    Want to learn? Then try to teach...

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. dialog box problem keeps haunting me
    By Bleech in forum Windows Programming
    Replies: 2
    Last Post: 08-23-2006, 01:12 AM
  2. Display Dialog Box Then Execute
    By stickman in forum C++ Programming
    Replies: 17
    Last Post: 05-10-2006, 11:02 AM
  3. Have a new dialog replace another one
    By axr0284 in forum Windows Programming
    Replies: 6
    Last Post: 03-10-2006, 05:23 PM
  4. Dialog Box Resources
    By Mecnels in forum Windows Programming
    Replies: 2
    Last Post: 04-28-2003, 05:57 AM
  5. Dialog Box & Property Sheet :: MFC
    By kuphryn in forum Windows Programming
    Replies: 2
    Last Post: 08-01-2002, 01:33 PM