|
-
October 31st, 2010, 12:35 AM
#1
Default Dialog Button not working
I make a modeless dialog with this...
CreateDialogParam
my dialog has 2 richedit controls, and 1 button, I want the ENTER key to activate the button,
I have the button set as default in the Resource style, and by code, and still it does not work, pressing enter makes a WANT RETURN on the rich edit control (even though I have WANT RETURN disabled in the style for it) The codes works in MFC but I cant get it working in win32api
this is not working...
case WM_INITDIALOG:
{
//set the default button
::SendMessage(hwnd,DM_SETDEFID,IDC_BTN1,0);
HWND hButton = ::GetDlgItem(hwnd,IDC_BTN1);
SendMessage(hButton,BM_SETSTYLE,BS_DEFPUSHBUTTON,TRUE);
I cant get WM_KEYDOWN or WM_CHAR to work in the dialogProc eithor :-(
//here is my message loop
while(GetMessage(&Msg, NULL, 0, 0) > 0)
{
if(!IsDialogMessage(Msg.hwnd, &Msg))//needed to handle modeless dlg messages
{
TranslateMessage(&Msg);
DispatchMessage(&Msg);
}
}
//according to msdn I am doing everything correctly :-( ??
[ http://msdn.microsoft.com/en-us/libr...keyboard_iface ]
Last edited by 12oclocker; October 31st, 2010 at 01:11 AM.
-
October 31st, 2010, 01:43 AM
#2
Re: Default Dialog Button not working
Are you using CreateDialog or CreateDialogEx?
Last edited by Morbane; October 31st, 2010 at 01:45 AM.
-
October 31st, 2010, 09:51 AM
#3
Re: Default Dialog Button not working
Im using CreateDialogParam, to make a modeless dialog,
I did figure out a work around, I trap the VK_RETURN message inside the richedit control, and use DM_GETDEFID to get the default button ID in the main dlg, then I post a simulated button press back to the main dialog, kind of a sloppy way to do things, but its working
here is my workaround code inside the rich edit control...
Code:
case WM_KEYDOWN:
{
if(wParam == VK_RETURN)
{
//MessageBox(NULL, "test Rich", "test Rich", MB_ICONWARNING);
//post back a message to parent dialog of a simulated default button click
HWND hParent = ::GetParent(hwnd);
LRESULT ret = ::SendMessage(hParent,DM_GETDEFID,0,0);
WORD wCtrlID = LOWORD(ret); //will contain the control ID
WORD wHasDef = HIWORD(ret); //will contain DC_HASDEFID
if(wCtrlID && wHasDef == DC_HASDEFID)
{
HWND hCtrl = ::GetDlgItem(hParent,wCtrlID);
::SendMessage(hParent,WM_COMMAND,MAKEWPARAM(wCtrlID,BN_CLICKED),(LPARAM)hCtrl);
return 0;//dont process VK_RETURN in our control
}
}
break;
}
Last edited by 12oclocker; October 31st, 2010 at 10:12 AM.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|