-
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...
-
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);
-
I'm not an expert at windows but dont you have an extra ) after IDD_MAIN in MAKEINTRESOURCE?
-
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.
-
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)