Board index » Visual Studio » newbie question

newbie question

Visual Studio105
hi,

how can I disable my dialog from closeing when the esc or enter key is

pressed?


-
 

Re:newbie question

Maximus



There are many ways to attack this problem -- the first one that I recommend

is to provide implementations to the two virtual function that handle this

in the CDialog base class, specifically OnOK and OnCancel. I usutally

provide implementation for these and in the implementationI do nothing, i.e.

{}



Next, I would rename the IDs for the two buttons, and remove the default

setting on the OK button. Then I would provide message map entries and

handlers for the new buttons - ID_MYOK and ID_MYCANCEL, or something like

that.



Other approaches may include something with PreTranslateMessage to consume

the ESC/Enter keys. That would look something like this:



/* ************************** */



BOOL CMyONOK::PreTranslateMessage(MSG* pMsg){

if(pMsg->message == WM_KEYDOWN){

if(pMsg->wParam == VK_ESCAPE)

return 0;

if(pMsg->wParam == VK_RETURN)

return 0;

}

BOOL sts = CDialog::PreTranslateMessage(pMsg);

return sts;

}

/* ************************** */



regards

roy fine



"Maximus" <ikillpeople@videotron.ca>wrote in message

Quote
hi,

how can I disable my dialog from closeing when the esc or enter key is

pressed?









-

Re:newbie question

Maximus wrote:



Quote
hi,

how can I disable my dialog from closeing when the esc or enter key is

pressed?







Add message handers for IDOK and IDCANCEL and do nothing inside the

message handlers.



--

Scott McPhillips [VC++ MVP]



-

Re:newbie question



"Scott McPhillips [MVP]" <scottmcp@mvps.org.nowhere>wrote in message

Quote
Maximus wrote:



>hi,

>how can I disable my dialog from closeing when the esc or enter key is

>pressed?

>

>



Add message handers for IDOK and IDCANCEL and do nothing inside the

message handlers.



--



YIKES -- i did exactly what you said, and now i can not close the dialog box

at all. what shall i do now?



Heres the code:



BEGIN_MESSAGE_MAP(CSecondChance, CDialog)

ON_BN_CLICKED(IDCANCEL, MYCANCEL)

ON_BN_CLICKED(IDOK, MYOK)

END_MESSAGE_MAP()



// CSecondChance message handlers

void CSecondChance::MYCANCEL(){}

void CSecondChance::MYOK(){}





roy





-

Re:newbie question

Quote
>Add message handers for IDOK and IDCANCEL and do nothing inside the

>message handlers.

>

YIKES -- i did exactly what you said, and now i can not close the dialog box

at all. what shall i do now?



Heres the code:



BEGIN_MESSAGE_MAP(CSecondChance, CDialog)

ON_BN_CLICKED(IDCANCEL, MYCANCEL)

ON_BN_CLICKED(IDOK, MYOK)

END_MESSAGE_MAP()



// CSecondChance message handlers

void CSecondChance::MYCANCEL(){}

void CSecondChance::MYOK(){}





roy







Call CDialog::OnOK() to close it.



--

Scott McPhillips [VC++ MVP]



-

Re:newbie question



"Scott McPhillips [MVP]" <scottmcp@mvps.org.nowhere>wrote in message

Quote
>>Add message handers for IDOK and IDCANCEL and do nothing inside the

>>message handlers.

>>

>YIKES -- i did exactly what you said, and now i can not close the dialog

box

>at all. what shall i do now?

>

>Heres the code:

>

>BEGIN_MESSAGE_MAP(CSecondChance, CDialog)

>ON_BN_CLICKED(IDCANCEL, MYCANCEL)

>ON_BN_CLICKED(IDOK, MYOK)

>END_MESSAGE_MAP()

>

>// CSecondChance message handlers

>void CSecondChance::MYCANCEL(){}

>void CSecondChance::MYOK(){}

>

>

>roy

>

>



Call CDialog::OnOK() to close it.



--

Scott McPhillips [VC++ MVP]





do mean something like this?



void CSecondChance::MYOK(){

Call CDialog::OnOK();

}



rlf





-

Re:newbie question

I think he's yanking your chain Scott!



"Roy Fine" <rlfine@twt.obfuscate.net>wrote in message

Quote


"Scott McPhillips [MVP]" <scottmcp@mvps.org.nowhere>wrote in message

news:O19MPT9sDHA.3536@tk2msftngp13.phx.gbl...

>>>Add message handers for IDOK and IDCANCEL and do nothing inside the

>>>message handlers.

>>>

>>YIKES -- i did exactly what you said, and now i can not close the

dialog

box

>>at all. what shall i do now?

>>

>>Heres the code:

>>

>>BEGIN_MESSAGE_MAP(CSecondChance, CDialog)

>>ON_BN_CLICKED(IDCANCEL, MYCANCEL)

>>ON_BN_CLICKED(IDOK, MYOK)

>>END_MESSAGE_MAP()

>>

>>// CSecondChance message handlers

>>void CSecondChance::MYCANCEL(){}

>>void CSecondChance::MYOK(){}

>>

>>

>>roy

>>

>>

>

>Call CDialog::OnOK() to close it.

>

>--

>Scott McPhillips [VC++ MVP]

>



do mean something like this?



void CSecondChance::MYOK(){

Call CDialog::OnOK();

}



rlf









-

Re:newbie question

Yes. you need to add a handler for WM_COMMAND (override

the OnCommand method), and make it something like this:



BOOL CMyDlg::OnCommand(WPARAM wParam, LPARAM lParam)

{

// Dont close child on <enter>/<escape>

if ((wParam == IDOK) || (wParam == IDCANCEL))

return TRUE;

return CDialog::OnCommand(wParam, lParam);

}





Quote
-----Original Message-----

hi,

how can I disable my dialog from closeing when the esc or

enter key is

pressed?





.



-