whats wrong with this logic case code?
BOOL CALLBACK DlgProc(HWND hwnd, UINT Message, WPARAM wParam, LPARAM lParam)
{
switch(Message)
case WM_INITDIALOG:
case WM_COMMAND:
switch(LOWORD(wParam))
{
case IDC_BUTTON2:
run_the_exe( path1_exe );
break;
case IDC_BUTTON3:
run_the_exe( path1_exe );
break;
case WM_CLOSE:
EndDialog(hwnd, 0);
break;
return TRUE;
default:
return FALSE;
}
return TRUE;
}
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance,
LPSTR lpCmdLine, int nCmdShow)
{
return DialogBox(hInstance, MAKEINTRESOURCE(IDD_MAIN), NULL, DlgProc);
}
what happens is that my IDD_MAIN dialog box is transparent!! the buttons come out though...
the problems should lie in the logic switches but i dunno what's wrong
[898 byte] By [
hanhao] at [2007-11-18 17:35:17]

# 1 Re: whats wrong with this logic case code?
Originally posted by hanhao
what happens is that my IDD_MAIN dialog box is transparent!! the buttons come out though...
the problems should lie in the logic switches but i dunno what's wrong Why not use a debugger? If you went through it with a debugger, you will see what the problem is.
Where is the "return TRUE" for the WM_INITDIALOG case?
BOOL CALLBACK DlgProc(HWND hwnd, UINT Message, WPARAM wParam, LPARAM lParam)
{
switch(Message)
case WM_INITDIALOG:
return TRUE; // <-- Where is this line?
//...
}
Regards,
Paul McKenzie
# 2 Re: whats wrong with this logic case code?
There is more than one thing wrong with that code. It is hard to tell your intentions without formatted code but this is what it looks like when I format it myself:
BOOL CALLBACK DlgProc(HWND hwnd, UINT Message, WPARAM wParam, LPARAM lParam)
{
switch(Message)
case WM_INITDIALOG:
case WM_COMMAND:
switch(LOWORD(wParam))
{
case IDC_BUTTON2:
run_the_exe( path1_exe );
break;
case IDC_BUTTON3:
run_the_exe( path1_exe );
break;
case WM_CLOSE:
EndDialog(hwnd, 0);
break;
return TRUE;
default:
return FALSE;
}
return TRUE;
}
From that, first thing I notice is that the first switch statment has no brackets, which makes it hard to determine where the switch statement's body ends.
The next thing I notice is that there is no break statement in WM_INITDIALOG and no return , which makes it fall through to the next CASE label.
The next thing I notice by looking at the brackets for the switch statement within WM_COMMAND, is that WM_CLOSE is included within the body of WM_COMMAND, it does not belong there. Also the return line immediatley below WM_CLOSE will never be executed as it follows a break statement, and is within the body of the same switch statement as is the break statement.
I assume this is not what you intended.
In any case, fixing the above, to do what I think you intended would look something like this:
BOOL CALLBACK DlgProc(HWND hwnd, UINT Message, WPARAM wParam, LPARAM lParam)
{
switch(Message)
{
case WM_INITDIALOG:
break;
case WM_COMMAND:
switch(LOWORD(wParam))
{
case IDC_BUTTON2:
run_the_exe( path1_exe );
break;
case IDC_BUTTON3:
run_the_exe( path1_exe );
break;
default:
return false;
}
break;
case WM_CLOSE:
EndDialog(hwnd, 0);
break;
default:
return false;
}
return true;
}
RussG1 at 2007-11-9 13:10:20 >

# 3 Re: whats wrong with this logic case code?
what happens is that my IDD_MAIN dialog box is transparent!! the buttons come out though...
the problems should lie in the logic switches but i dunno what's wrong
It seems that WM_PAINT is not processed normally. Documents say that DlgProc should return FALSE for the messages it did not processed, this guarantee dialog manager performs the default dialog operation (paint ur dialog etc...). So the DlgProc should looks like this:
BOOL CALLBACK DlgProc(HWND hwnd, UINT Message, WPARAM wParam, LPARAM lParam)
{
switch(Message)
{ //process some messages
}
return FALSE;
}