Board index » Visual Studio » stoping enter from closing the dialogue

stoping enter from closing the dialogue

Visual Studio162
I need my dialogue to only close when the user hits the

close x in the top right corner. I saw a help on how to

do this for visual studio 6, but I couldn't figure out

how to do it in .net 2003 which I am using now. Thanks

in advance for any answers I hope to receive.


-
 

Re:stoping enter from closing the dialogue

There is no change in this from VS6 to VS2003 if you are using MFC. You still would do it

using OnSysCommand/SC_CLOSE and make sure you dont let it close any other way(OnCancel

etc).



--

Ajay Kalra [MVP - VC++]

ajaykalra@yahoo.com





"danny" <danny@meshwerks.com>wrote in message

| I need my dialogue to only close when the user hits the

| close x in the top right corner. I saw a help on how to

| do this for visual studio 6, but I couldn't figure out

| how to do it in .net 2003 which I am using now. Thanks

| in advance for any answers I hope to receive.



-

Re:stoping enter from closing the dialogue



The web help I saw on how to do it was through a wizard

in VS 6 and I could'nt find the equivalent in .net. I

gather than that the OnSysCommand/SC_CLOSE would be part

of the dialog class rather than the application class.

Thanks



Danny

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

There is no change in this from VS6 to VS2003 if you are

using MFC. You still would do it

using OnSysCommand/SC_CLOSE and make sure you dont let

it close any other way(OnCancel

etc).



--

Ajay Kalra [MVP - VC++]

ajaykalra@yahoo.com





"danny" <danny@meshwerks.com>wrote in message

news:2a84001c39265$5af4a300$a601280a@phx.gbl...

| I need my dialogue to only close when the user hits the

| close x in the top right corner. I saw a help on how

to

| do this for visual studio 6, but I couldn't figure out

| how to do it in .net 2003 which I am using now. Thanks

| in advance for any answers I hope to receive.



.



-

Re:stoping enter from closing the dialogue

Yes, you need to do it on the dialog class. You dont really need a wizard to do this. I

rarely, if ever, use a wizard.



--

Ajay Kalra [MVP - VC++]

ajaykalra@yahoo.com





"danny" <danny@meshwerks.com>wrote in message

|

| The web help I saw on how to do it was through a wizard

| in VS 6 and I could'nt find the equivalent in .net. I

| gather than that the OnSysCommand/SC_CLOSE would be part

| of the dialog class rather than the application class.

| Thanks

|

| Danny

|>-----Original Message-----

|>There is no change in this from VS6 to VS2003 if you are

| using MFC. You still would do it

|>using OnSysCommand/SC_CLOSE and make sure you dont let

| it close any other way(OnCancel

|>etc).

|>

|>--

|>Ajay Kalra [MVP - VC++]

|>ajaykalra@yahoo.com

|>

|>

|>"danny" <danny@meshwerks.com>wrote in message

|>news:2a84001c39265$5af4a300$a601280a@phx.gbl...

|>| I need my dialogue to only close when the user hits the

|>| close x in the top right corner. I saw a help on how

| to

|>| do this for visual studio 6, but I couldn't figure out

|>| how to do it in .net 2003 which I am using now. Thanks

|>| in advance for any answers I hope to receive.

|>

|>.

|>



-

Re:stoping enter from closing the dialogue

Ok, but I am not quite sure I understand how to add this.



Do I add the method in the header file

OnSysCommand?



Is it a method that exists by inheritance already? I

just need to know how to get this started and I will be

good. And last question. Does the SC_CLOSE apply when

you click the close x on the window? I need that to

still close the dialog, just not enter or escape.



thanks for the quick reply on the last one.



Danny





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

Yes, you need to do it on the dialog class. You dont

really need a wizard to do this. I

rarely, if ever, use a wizard.



--

Ajay Kalra [MVP - VC++]

ajaykalra@yahoo.com





"danny" <danny@meshwerks.com>wrote in message

news:00f801c39279$a78dc4d0$a401280a@phx.gbl...

|

| The web help I saw on how to do it was through a wizard

| in VS 6 and I could'nt find the equivalent in .net. I

| gather than that the OnSysCommand/SC_CLOSE would be

part

| of the dialog class rather than the application class.

| Thanks

|

| Danny

|>-----Original Message-----

|>There is no change in this from VS6 to VS2003 if you

are

| using MFC. You still would do it

|>using OnSysCommand/SC_CLOSE and make sure you dont let

| it close any other way(OnCancel

|>etc).

|>

|>--

|>Ajay Kalra [MVP - VC++]

|>ajaykalra@yahoo.com

|>

|>

|>"danny" <danny@meshwerks.com>wrote in message

|>news:2a84001c39265$5af4a300$a601280a@phx.gbl...

|>| I need my dialogue to only close when the user hits

the

|>| close x in the top right corner. I saw a help on

how

| to

|>| do this for visual studio 6, but I couldn't figure

out

|>| how to do it in .net 2003 which I am using now.

Thanks

|>| in advance for any answers I hope to receive.

|>

|>.

|>



.



-

Re:stoping enter from closing the dialogue

You need to declar it in your dialog class:



afx_msg void OnSysCommand(UINT nID, LPARAM lParam);





and then define it in the implementation(.cpp):



BEGIN_MESSAGE_MAP(CMyDlg, CDialog)

ON_WM_SYSCOMMAND() // This needs to be in there

END_MESSAGE_MAP()





void CMyDlg::OnSysCommand(UINT nID, LPARAM lParam)

{

........



}



You can close dialog by calling CDialog::OnCancel or EndDialog(if modal dialog).



--

Ajay Kalra [MVP - VC++]

ajaykalra@yahoo.com





"danny" <danny@meshwerks.com>wrote in message

| Ok, but I am not quite sure I understand how to add this.

|

| Do I add the method in the header file

| OnSysCommand?

|

| Is it a method that exists by inheritance already? I

| just need to know how to get this started and I will be

| good. And last question. Does the SC_CLOSE apply when

| you click the close x on the window? I need that to

| still close the dialog, just not enter or escape.

|

| thanks for the quick reply on the last one.

|

| Danny

|

|

|>-----Original Message-----

|>Yes, you need to do it on the dialog class. You dont

| really need a wizard to do this. I

|>rarely, if ever, use a wizard.

|>

|>--

|>Ajay Kalra [MVP - VC++]

|>ajaykalra@yahoo.com

|>

|>

|>"danny" <danny@meshwerks.com>wrote in message

|>news:00f801c39279$a78dc4d0$a401280a@phx.gbl...

|>|

|>| The web help I saw on how to do it was through a wizard

|>| in VS 6 and I could'nt find the equivalent in .net. I

|>| gather than that the OnSysCommand/SC_CLOSE would be

| part

|>| of the dialog class rather than the application class.

|>| Thanks

|>|

|>| Danny

|>|>-----Original Message-----

|>|>There is no change in this from VS6 to VS2003 if you

| are

|>| using MFC. You still would do it

|>|>using OnSysCommand/SC_CLOSE and make sure you dont let

|>| it close any other way(OnCancel

|>|>etc).

|>|>

|>|>--

|>|>Ajay Kalra [MVP - VC++]

|>|>ajaykalra@yahoo.com

|>|>

|>|>

|>|>"danny" <danny@meshwerks.com>wrote in message

|>|>news:2a84001c39265$5af4a300$a601280a@phx.gbl...

|>|>| I need my dialogue to only close when the user hits

| the

|>|>| close x in the top right corner. I saw a help on

| how

|>| to

|>|>| do this for visual studio 6, but I couldn't figure

| out

|>|>| how to do it in .net 2003 which I am using now.

| Thanks

|>|>| in advance for any answers I hope to receive.

|>|>

|>|>.

|>|>

|>

|>.

|>



-

Re:stoping enter from closing the dialogue

The method already existed and this is what it had in it:



if ((nID & 0xFFF0) == IDM_ABOUTBOX)

{

CAboutDlg dlgAbout;

dlgAbout.DoModal();

}

else

{

CDialog::OnSysCommand(nID, lParam);

}





I tried adding a few else conditions to check nID against

SC_CLOSE but none of them did what I need. I tried

adding this before the last else that calles CDialog's

method

else if(nID&0xFF0)==SC_CLOSE)

{

}



That didn't work so I tried

else if(nID==SC_CLOSE)

{

}

but that didn't work either. I just need nothing to

happen when you hit enter.







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

There is no change in this from VS6 to VS2003 if you are

using MFC. You still would do it

using OnSysCommand/SC_CLOSE and make sure you dont let

it close any other way(OnCancel

etc).



--

Ajay Kalra [MVP - VC++]

ajaykalra@yahoo.com





"danny" <danny@meshwerks.com>wrote in message

news:2a84001c39265$5af4a300$a601280a@phx.gbl...

| I need my dialogue to only close when the user hits the

| close x in the top right corner. I saw a help on how

to

| do this for visual studio 6, but I couldn't figure out

| how to do it in .net 2003 which I am using now. Thanks

| in advance for any answers I hope to receive.



.



-

Re:stoping enter from closing the dialogue

Hang on here. What are you trying to do? You started off by asking of X button on the

title and now it appears all you want is Enter key to not close the dialog. If thats all

you want, override OnOk of your dialog and not call base class. In addition, change ID of

your OK button from IDOK to something else and provide a

handler for it. In its handler, call CDialog::OnOk(). For more info, take a look at

followig MSDN article:



How to Disable Default Pushbutton Handling for MFC Dialog

Article ID: Q122489



--

Ajay Kalra [MVP - VC++]

ajaykalra@yahoo.com





"dannny" <danny@meshwerks.com>wrote in message

| The method already existed and this is what it had in it:

|

| if ((nID & 0xFFF0) == IDM_ABOUTBOX)

| {

| CAboutDlg dlgAbout;

| dlgAbout.DoModal();

| }

| else

| {

| CDialog::OnSysCommand(nID, lParam);

| }

|

|

| I tried adding a few else conditions to check nID against

| SC_CLOSE but none of them did what I need. I tried

| adding this before the last else that calles CDialog's

| method

| else if(nID&0xFF0)==SC_CLOSE)

| {

| }

|

| That didn't work so I tried

| else if(nID==SC_CLOSE)

| {

| }

| but that didn't work either. I just need nothing to

| happen when you hit enter.

|

|

|

|>-----Original Message-----

|>There is no change in this from VS6 to VS2003 if you are

| using MFC. You still would do it

|>using OnSysCommand/SC_CLOSE and make sure you dont let

| it close any other way(OnCancel

|>etc).

|>

|>--

|>Ajay Kalra [MVP - VC++]

|>ajaykalra@yahoo.com

|>

|>

|>"danny" <danny@meshwerks.com>wrote in message

|>news:2a84001c39265$5af4a300$a601280a@phx.gbl...

|>| I need my dialogue to only close when the user hits the

|>| close x in the top right corner. I saw a help on how

| to

|>| do this for visual studio 6, but I couldn't figure out

|>| how to do it in .net 2003 which I am using now. Thanks

|>| in advance for any answers I hope to receive.

|>

|>.

|>



-

Re:stoping enter from closing the dialogue

dannny wrote:

Quote
The method already existed and this is what it had in it:



if ((nID & 0xFFF0) == IDM_ABOUTBOX)

{

CAboutDlg dlgAbout;

dlgAbout.DoModal();

}

else

{

CDialog::OnSysCommand(nID, lParam);

}





I tried adding a few else conditions to check nID against

SC_CLOSE but none of them did what I need. I tried

adding this before the last else that calles CDialog's

method

else if(nID&0xFF0)==SC_CLOSE)

{

}



That didn't work so I tried

else if(nID==SC_CLOSE)

{

}

but that didn't work either. I just need nothing to

happen when you hit enter.



The example has three F's in 0xFFF0.

Your code only has two F's.



--

Scott McPhillips [VC++ MVP]



-

Re:stoping enter from closing the dialogue



When I built the dialog in the editor I deleted the ok

button but that didn't get rid of the ability to hit

enter. I am sorry if I misled you on what I want. I

have meant the whole time that I want to make it so that

hitting enter or escape won't close my main dialog.

There is no onButtonOk or anything like that because I

destroyed that button. I want the dialog to be up until

the user closes it using the x on the top right corner.

Sorry about the confusion.

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

Hang on here. What are you trying to do? You started off

by asking of X button on the

title and now it appears all you want is Enter key to

not close the dialog. If thats all

you want, override OnOk of your dialog and not call base

class. In addition, change ID of

your OK button from IDOK to something else and provide a

handler for it. In its handler, call CDialog::OnOk().

For more info, take a look at

followig MSDN article:



How to Disable Default Pushbutton Handling for MFC Dialog

Article ID: Q122489



--

Ajay Kalra [MVP - VC++]

ajaykalra@yahoo.com





"dannny" <danny@meshwerks.com>wrote in message

news:0c6601c392a1$c4a78a10$a001280a@phx.gbl...

| The method already existed and this is what it had in

it:

|

| if ((nID & 0xFFF0) == IDM_ABOUTBOX)

| {

| CAboutDlg dlgAbout;

| dlgAbout.DoModal();

| }

| else

| {

| CDialog::OnSysCommand(nID, lParam);

| }

|

|

| I tried adding a few else conditions to check nID

against

| SC_CLOSE but none of them did what I need. I tried

| adding this before the last else that calles CDialog's

| method

| else if(nID&0xFF0)==SC_CLOSE)

| {

| }

|

| That didn't work so I tried

| else if(nID==SC_CLOSE)

| {

| }

| but that didn't work either. I just need nothing to

| happen when you hit enter.

|

|

|

|>-----Original Message-----

|>There is no change in this from VS6 to VS2003 if you

are

| using MFC. You still would do it

|>using OnSysCommand/SC_CLOSE and make sure you dont let

| it close any other way(OnCancel

|>etc).

|>

|>--

|>Ajay Kalra [MVP - VC++]

|>ajaykalra@yahoo.com

|>

|>

|>"danny" <danny@meshwerks.com>wrote in message

|>news:2a84001c39265$5af4a300$a601280a@phx.gbl...

|>| I need my dialogue to only close when the user hits

the

|>| close x in the top right corner. I saw a help on

how

| to

|>| do this for visual studio 6, but I couldn't figure

out

|>| how to do it in .net 2003 which I am using now.

Thanks

|>| in advance for any answers I hope to receive.

|>

|>.

|>



.



-

Re:stoping enter from closing the dialogue

<anonymous@discussions.microsoft.com>wrote in message

|

| When I built the dialog in the editor I deleted the ok

| button but that didn't get rid of the ability to hit

| enter. I am sorry if I misled you on what I want. I

| have meant the whole time that I want to make it so that

| hitting enter or escape won't close my main dialog.

| There is no onButtonOk or anything like that because I

| destroyed that button. I want the dialog to be up until

| the user closes it using the x on the top right corner.

| Sorry about the confusion.



No problems. The mentioned article should work for you. If it does not, post again. This

is a common issue and has been addressed several times.



--

Ajay Kalra [MVP - VC++]

ajaykalra@yahoo.com







-