I wrote a resource script for a (modeless) dialog that should contain an edit control (used to show a non-edit log report):
IDD_LOG DIALOGEX 10, 10, 300, 200, 0
STYLE WS_VISIBLE | WS_POPUP | WS_CAPTION | WS_BORDER | WS_SYSMENU | DS_CENTER
CAPTION "Last Log Report"
{
EDITTEXT 301, 0, 0, 250, 180, WS_VISIBLE | WS_CHILD | WS_VSCROLL | ES_MULTILINE | ES_READONLY
}
When I call up the dialog via the menu using
hwndLogDlg = CreateDialog(NULL, MAKEINTRESOURCE(IDD_LOG), hwnd, (DLGPROC)LogDlgProc)
the following things are not right with it:
- The dialog window contains an edit control, but there's another edit control with the same size above it all. That edit control seems to be a non-child window.
Also, when I set the text in the edit control calling
SetDlgItemText(hwndLogDlg, IDDE_LOGTXT, "<Could not load log data>");
, both of them are set.
I suspect the resource compiler to see the edit control in the script as both a child of the dialog box and a second time as a separate window, although WS_CHILD is set. - The main window is blocked when the dialog is created, although the dialog is modeless.
- Clicking the closing button of the dialog window won't cause it to close, even though I call
DestroyWindow(hwndDlg);
on WM_QUIT and WM_DESTROY. Together with the problem of the main window being blocked, the only ways for me to close everything is to close the window from the taskbar or taskmanager.
Message loop:
while(GetMessage(&Msg, NULL, 0, 0) > 0) {
if (!IsDialogMessage(hwndDlg, &Msg)){
TranslateMessage(&Msg);
DispatchMessage(&Msg);
}
}
Dialog window procedure:
INT_PTR CALLBACK LogDlgProc(HWND hwndDlg, UINT message, WPARAM wParam, LPARAM lParam){
switch (message){
case WM_INITDIALOG:{
hwndLogTxt = GetDlgItem(hwndDlg, IDDE_LOGTXT);
fileHandler fH;
if (!fH.init("report.log")){
SetDlgItemText(hwndLogTxt, IDDE_LOGTXT, "<Could not load log data>");
err(ERR_CUSTOM,"Failed to extract log file!","Extraction Error!");
}
else SetDlgItemText(hwndLogTxt, IDDE_LOGTXT, fH.getStr());
break;
}
case WM_DESTROY:{
DestroyWindow(hwndDlg);
break;
}
}
return true;
}
So what I would like to get in the end, is a modeless dialog box containing a (read-only) edit control (that takes up all of the client-area of the dialog window). Is this problem about my resource syntax or about the way I call it? May I even have been missing necessary steps on WM_INITDIALOG?
SetDlgItemText
is wrong - it takes the parent (dialog) handle, not the control handle. – Jonathan Potter