Click to See Complete Forum and Search --> : stupid dialog box


indiocolifa
January 19th, 2004, 11:28 PM
I'm stuck with a stupid problem: my modal dialog box does not appear. I'm very comfortable with the Win32 API but I think i'm in a bad day...

Here's the code (note that I'm using message crackers from WINDOWSX.H):


//
// helpDlg Dialog Procedure
//
BOOL CALLBACK helpDlg_DlgProc (HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lParam)
{
switch(msg)
{
HANDLE_MSG (hwndDlg, WM_INITDIALOG, helpDlg_OnInitDialog);

//// TODO: Add dialog message crackers here...

default:
return FALSE;
}
}



and WM_INITDIALOG handler...


//
// Process WM_INITDIALOG message for window/dialog: helpDlg
//
BOOL helpDlg_OnInitDialog(HWND hwnd, HWND hwndFocus, LPARAM lParam)
{
// fill the listbox
int itemdx;

// first clear all items if any
SendDlgItemMessage(hwnd, IDC_MESSAGES, LB_RESETCONTENT, 0, 0);

// add messages to listbox
for (int i = 0; i < numMessages; i++)
itemdx = (int)SendDlgItemMessage (hwnd, IDC_CBOMSG, LB_ADDSTRING, 0, (LPARAM)msginfo[i].WM_msg);

return FALSE;
}


and the function where it's called...


//
// process WM_ONCOMMAND
//
void Cls_OnCommand(HWND hwnd, int id, HWND hwndCtl, UINT codeNotify)
{
HMENU hMenu;
BYTE bAlpha; // window transparency alpha
HMODULE hUser32;
PSLWA pSetLayeredWndAttr;

switch (id)
{
// menus

case ID_HELP_ABOUT:
DialogBox(GetModuleHandle(0), MAKEINTRESOURCE(IDD_ABOUT), hwnd, AboutDlg_DlgProc);
break;

case ID_HELP_MESSAGEHELP: // hereĦs where i call the dlg which does not appear!
DialogBox(GetModuleHandle(0), MAKEINTRESOURCE(IDD_HELPWINDOW), hwnd, helpDlg_DlgProc);
break;

...


some clues?

thanks.

indiocolifa
January 19th, 2004, 11:54 PM
WOW.

:rolleyes:

the problem was with the initialization of a RichEdit control...

:rolleyes: :rolleyes:

Myself dot NET
January 23rd, 2004, 09:39 PM
You shouldn't use the HANDLE_MSG macro for handling dialog messages because it is designed to return an LRESULT value for a window procedure, not a BOOL for a dialog procedure. Instead, you can define the following macro (from Jeffrey Richter's "Programming Applications for Microsoft Windows"):


#define HANDLE_DLG_MSG(hDlg, msg, fn) \
case(msg): \
return SetDlgMsgResult(hDlg, msg, HANDLE_##msg(hDlg, wParam, lParam, fn))


SetDlgMsgResult() is another macro in windowsx.h which for most messages calls SetWindowLongPtr() and returns its success/failure, but for dialog-specific messages returns the result value cast directly to a BOOL. Used in this manner, the function allows you to handle dialog messages with the message crackers.

The only limitation I've encountered with this method is when you want to perform some processing on a message, but also have the default processing done. With a cracked window procedure, you can just use the FORWARD_WM_ macros, but for a dialog you must return FALSE in the dialog procedure. When I need to do this, I just set up the case statement manually.

Anyway, sorry to ramble on about something you weren't even asking for

indiocolifa
January 23rd, 2004, 10:17 PM
thanks!

that will help in my Message Cracker Wizard utility.

check it out at my home page http://usuarios.lycos.es/hernandp

give it a try if you're using WINDOWSX.H message crackers. If you try my utility, post your suggestions, criticism, etc. at my page forum boards. ;)


thank you very much,really.
:thumb: :thumb:

indiocolifa
January 29th, 2004, 01:54 AM
using HANDLE_DLG_MSG gives me:

warning C4244: 'argument' : conversion from 'LPARAM' to 'LONG'; possible data loss

how I can handle this?

Myself dot NET
January 29th, 2004, 03:15 AM
It looks like this warning comes about because SetDlgMsgResult() in windowsx.h does not correctly cast the return value of the message cracker function to LONG_PTR when calling SetWindowLongPtr() (it instead casts it (LPARAM)(LRESULT)). The only way to fix this would be to edit windowsx.h or write your own SetDlgMsgResult() logic.