Hello,
<edit>EDIT: Writing this made me realize that it could be the menu, so I removed it from dialog #1001 and it worked, do I have to initialize menus or something too?
I've tried with LoadMenu()/SetMenu() but I get the same error, my menu template is:
Code:
2001 MENUEX
BEGIN
POPUP "File", 0, 0, 0
BEGIN
MENUITEM "Config", 6002, 0, 0
MENUITEM "", 0, 0|MFT_SEPARATOR, 0
MENUITEM "Exit", 6001, 0, 0
END
POPUP "Help", 0, 0, 0
BEGIN
MENUITEM "About", 6004, 0, 0
END
END
</edit>
I'm creating a Win32 GUI application with MinGW. I have a dialog template in a resource, and I'm attempting to display it with DialogBox(), however I get a "13: The Data is invalid" error when I call DialogBox() trying to show the main dialog, but if I try to show another window it works (a window without dialog).
The main code:
Code:
#include <windows.h>
#include <commctrl.h>
BOOL CALLBACK mainDialogProc(HWND hWndDlg, UINT msg, WPARAM wParam, LPARAM lParam);
void reportError(void);
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow)
{
INITCOMMONCONTROLSEX commonControls;
/* init the common controls */
commonControls.dwSize = sizeof(INITCOMMONCONTROLSEX);
commonControls.dwICC = ICC_LISTVIEW_CLASSES | ICC_PROGRESS_CLASS;
if(InitCommonControlsEx(&commonControls) != TRUE)
{
reportError();
return 0;
}
if(DialogBox(hInstance, MAKEINTRESOURCE(1001), NULL, (DLGPROC) mainDialogProc) <= 0)
{
reportError();
return 0;
}
return 0;
}
BOOL CALLBACK mainDialogProc(HWND hWndDlg, UINT msg, WPARAM wParam, LPARAM lParam)
{
switch (msg)
{
case WM_INITDIALOG:
MessageBox(0, "dialog ran", "hi", 0);
return TRUE;
default:
return FALSE;
}
return FALSE;
}
void reportError(void)
{
LPVOID lpMsgBuf;
FormatMessage( FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS,
NULL,
GetLastError(),
0,
(LPTSTR) &lpMsgBuf,
0,
NULL);
MessageBox(NULL, (LPCTSTR)lpMsgBuf, "Error", MB_OK | MB_ICONERROR);
LocalFree(lpMsgBuf);
return;
}
And the 2 dialog templates:
Code:
1001 DIALOGEX DISCARDABLE 6, 18, 374, 198
STYLE WS_POPUP|DS_MODALFRAME|DS_3DLOOK|DS_CENTER|WS_CAPTION|WS_SYSMENU|WS_MINIMIZEBOX|WS_VISIBLE
CAPTION "pipsv"
MENU 2001
FONT 8, "MS Sans Serif", 0, 0, 1
BEGIN
CONTROL "Connection", 4001, "Button", BS_GROUPBOX, 248, 136, 124, 36
CONTROL "", 4008, "msctls_progress32", PBS_SMOOTH|WS_BORDER, 8, 108, 88, 10
CONTROL "test1", 4009, "Static", SS_CENTER|WS_GROUP, 8, 120, 88, 8
CONTROL "test2", 4004, "Button", BS_GROUPBOX, 4, 136, 120, 60
CONTROL "test3", 4005, "Static", WS_GROUP, 8, 148, 112, 8
CONTROL "", 4010, "SysListView32", LVS_REPORT|LVS_SINGLESEL|LVS_AUTOARRANGE|WS_BORDER|WS_TABSTOP, 8, 16, 360, 88
END
1002 DIALOGEX DISCARDABLE 6, 18, 210, 142
STYLE WS_POPUP|DS_MODALFRAME|DS_CONTEXTHELP|DS_3DLOOK|WS_CAPTION|WS_SYSMENU|WS_VISIBLE
CAPTION "Dialog"
FONT 8, "MS Sans Serif", 0, 0, 1
BEGIN
CONTROL "OK", IDOK, "Button", WS_TABSTOP, 160, 5, 45, 15
CONTROL "Cancel", IDCANCEL, "Button", WS_TABSTOP, 160, 23, 45, 15
END
So in other words, when I try to show dialog #1001 I get the error, but it works fine with dialog #1002. I've initialized all the controls I've used - with InitCommonControlsEx() (I think)? The only difference between #1001 and #1002 is, 1001 has more controls and a menu... perhaps I haven't initialized all the controls I ask for?
I compile with,
Code:
windres -o resource.o resource.rc
gcc -W -Wall -ansi -pedantic -O2 -mwindows -D _WIN32_IE=0x0500 -o stuff resource.o stuff.c -lkernel32 -luser32 -lws2_32 -lgdi32 -lcomctl32
Thanks in advance.