Close dialog

Hello,

On my dialog I have a CEdit control. When I type some text in the CEdit
control and then press <ENTER> the dialog closes. I don't want the dialog to
close. Can anybody help me?

Greeting Marco


0
mjonker1 (5)
8/15/2003 12:52:37 PM
vc.mfc 33608 articles. 0 followers. Follow

3 Replies
748 Views

Similar Articles

[PageSpeed] 47

Hi Marco,

You need to override the PreTranslateMessage(..) Virtual 
function into your dialog using the class wizard.
Your can implement this function as shown below, this 
should solve the problem. You'll just have to change 
IDC_YOUREDIT with the name of your CEdit object and 
CYourDialog with your dialog box class name.  

BOOL CYourDialog::PreTranslateMessage(MSG* pMsg) 
{
   if (pMsg->message == WM_KEYDOWN)
   {
      // Check if return key is pressed
      if (pMsg->wParam == VK_RETURN)
      { 
	 CWnd* pWndWithFocus = GetFocus();
	 if (pWndWithFocus == GetDlgItem(IDC_YOUREDIT))
	 {
	   SetFocus();
	 }
	 return true;
      }	
   }		
   return CDialog::PreTranslateMessage(pMsg);
}

please let me know if you have any problems with that.
Regards
Fabrice


>-----Original Message-----
>Hello,
>
>On my dialog I have a CEdit control. When I type some 
text in the CEdit
>control and then press <ENTER> the dialog closes. I don't 
want the dialog to
>close. Can anybody help me?
>
>Greeting Marco
>
>
>.
>
0
8/15/2003 2:51:25 PM
The solution I gave below is a solution that is often used 
to solve this problem. It has been used by many 
programmers before, and was given to me when I went on an 
MFC course given by microsoft, It has work in all the 
applications I have developped so far and has not caused 
any problems.


>-----Original Message-----
>Overriding PreTranslateMessage is usually the worst way 
to do this. This code is so
>incredibly fragile it is almost impossible to maintain. 
Just remove the default button
>property from the OK button. In addition, you can simply 
rename the OK button to something
>else and add a handler that calls CDialog::OnOK(), and 
remove the body of the existing
>OnOK handler.
>
>I consider the solution below to be an abuse of 
PreTranslateMessage, and completely
>unmaintainable.
>					joe
>
>On Fri, 15 Aug 2003 07:51:25 -0700, "Fabrice" 
<fabrice.maillaud@bookham.com> wrote:
>
>>Hi Marco,
>>
>>You need to override the PreTranslateMessage(..) Virtual 
>>function into your dialog using the class wizard.
>>Your can implement this function as shown below, this 
>>should solve the problem. You'll just have to change 
>>IDC_YOUREDIT with the name of your CEdit object and 
>>CYourDialog with your dialog box class name.  
>>
>>BOOL CYourDialog::PreTranslateMessage(MSG* pMsg) 
>>{
>>   if (pMsg->message == WM_KEYDOWN)
>>   {
>>      // Check if return key is pressed
>>      if (pMsg->wParam == VK_RETURN)
>>      { 
>>	 CWnd* pWndWithFocus = GetFocus();
>>	 if (pWndWithFocus == GetDlgItem(IDC_YOUREDIT))
>>	 {
>>	   SetFocus();
>>	 }
>>	 return true;
>>      }	
>>   }		
>>   return CDialog::PreTranslateMessage(pMsg);
>>}
>>
>>please let me know if you have any problems with that.
>>Regards
>>Fabrice
>>
>>
>>>-----Original Message-----
>>>Hello,
>>>
>>>On my dialog I have a CEdit control. When I type some 
>>text in the CEdit
>>>control and then press <ENTER> the dialog closes. I 
don't 
>>want the dialog to
>>>close. Can anybody help me?
>>>
>>>Greeting Marco
>>>
>>>
>>>.
>>>
>
>Joseph M. Newcomer [MVP]
>email: newcomer@flounder.com
>Web: http://www.flounder.com
>MVP Tips: http://www.flounder.com/mvp_tips.htm
>.
>
0
8/18/2003 9:20:30 AM
Lars-Inge,

Just following your comment, please find a few of many 
examples where people have been using this solution:

http://www.codeguru.com/mfc/comments/3605.shtml
http://www.codeproject.com/dialog/pretransdialog01.asp
http://beta.experts-
exchange.com/Programming/Programming_Languages/MFC/Q_206485
58.html

I am not saying it is the best solution, I am saying that 
I am not the only one to use it, and I also know that it 
has worked fine in all the dialog-based applications I 
wrote. I will also have a look at your solution. :o) 

>-----Original Message-----
>I have never seen that solution before.
>
>Please override the  CDialog::OnOK() (enter) and 
CDialog::OnCancel() (Esc).
>This is what all MFC books I have read do.
>
>Maybe he/she (MSFT-instructor) just wanted to show you 
many different ways
>to do the same thing?  =:o)
>
>Lars-Inge
>
>
>"Fabrice" <fabrice.maillaud@bookham.com> wrote in message 
news:066601c36569
>> The solution I gave below is a solution that is often 
used
>> to solve this problem. It has been used by many
>> programmers before, and was given to me when I went on 
an
>> MFC course given by microsoft, It has work in all the
>> applications I have developped so far and has not caused
>> any problems.
>
>
>.
>
0
8/19/2003 9:04:36 AM
Reply:

Similar Artilces:

blind close
The batch list report should be able to be flitered on the blind closed date. Specifically you should be able to print a list of all batches blind closed for a given month. This report would be helpful to reconcile that all batch have been posted to the GL. ---------------- This post is a suggestion for Microsoft, and Microsoft responds to the suggestions with the most votes. To vote for this suggestion, click the "I Agree" button in the message pane. If you do not see the button, follow this link to open the suggestion in the Microsoft Web-based Newsreader and then click &q...

Month-End Closing in Great Plains 8.0
Might I get some information about Month-End Closing? The detailed steps I should take The precautions and cautions I shoud aware of. Thanks, Alexis Hello Alexis, There are so many factors that goes into this depending on which modules you have, but generally speaking, Great Plains doesn't have a "hard" month-end as with many other ERP solutions. Perhaps contact your VAR to help you determine what procedures you need to perform as part of your month-end. Kind Regards Eddie Fourie MBS Specialist A> Might I get some information about Month-End Closing? A> A> Th...

Exchange 5.5 SP4
Hi, I have an NT4 server with Exchange 5.5 SP4 installed. I have followed all the guides for ensuring relaying is prohibited on our server - tried the telnet tests (MAIL FROM, RCPT TO etc) and I get the response 550 relaying is prohibited. However, when online our Exchange outbound queue constantly fills with spam mail, originating from the sender <>. How can I stop this? Any info would be appreciated. Thanks, Paul. On Wed, 10 Nov 2004 13:12:24 -0000, "Paul Kavanagh" <pkavanagh@ntlworld.com> wrote: >Hi, > >I have an NT4 server with Exchange 5.5 SP4 ...

CRgn and dialog boxes
Can I change the window region of a dialog box? usualy I can use SetWindowRgn for that, but on my MFC application, trying to do so on a dialog based application gives me only assert exception and the order never gets executed. is this can be done at all, or this is my bad? was my bad, I solved that. "Donald sorenson" <dony_s@excite.com> wrote in message news:Os8$2mSrDHA.2588@tk2msftngp13.phx.gbl... > Can I change the window region of a dialog box? > usualy I can use SetWindowRgn for that, but on my MFC application, trying to > do so on a dialog based application giv...

Year end closing in payroll
MGPS 8.0 I closed the year in payroll. Now Im trying to payroll for new year. I try to calculate checks and I get the following message. Checks cannot be calculated while the year end closing is in process. -- David You need to change your user date to 2006 "pizzaguy" wrote: > MGPS 8.0 > > I closed the year in payroll. Now Im trying to payroll for new year. I try > to calculate checks and I get the following message. > > Checks cannot be calculated while the year end closing is in process. > > > -- > David ...

Automatic close the Change box
I need help to set change box automaticly close after the transation. Any one can help ? SO Manager --> File menu --> Configuration --> Options tab --> POS Options --> Automatically close change screen If you don't have this option you will need to update the RMS Software to SP2. Rob "Gill" wrote: > I need help to set change box automaticly close after the transation. Any > one can help ? How can I upgrade to sp2 "Gill" wrote: > I need help to set change box automaticly close after the transation. Any > one can help ? Gill, If...

Excel closes more than one worksheet
I'm running XP and the latest Office software. You know how if you have multiple Word docs open, you see multiple bars down on the task bar? And if you close one of them with the red X box at the top right (the one for the application, not the smaller window one), only that one particular Word file closes; all the rest stay open? Why doesn't Excel do that? Whenever I use the big red X to close out of something, it wants to close all Excel worksheets at once. Why is it different only for Excel? I'm so used to it being the other way in other applications that I've lost da...

FRx
Cost of sales is calculated as Opening Stock+Purchase-Closing Stock. Opening/Closing stock are entered and kept in an UNPOST GL Trx Batch and FRx reported is generated with Unpost Trx included. The issue: Jan Opening Stock=0.00 Jan Closing Stock=$100 Feb Opening Stock=$100 (always equal closing stock of previous mth) Feb Closing Stock=$150 Mar Opening Stock=$150 Mar Closing Stock=$200 for FRx to print P&L with CUR, * opening stock=opening stock of that period * closing stock=closing stock of that period with above trx, FRx will report correct figure. now, the issue is with printing ...

Track email in CRM
When in Outlook and you click "Track in CRM" and you go to set the "Regarding" field, the search scope defaults to Account. Is there any way to change this so that it defaults to Contact? I've been able to change this on other forms by using something like: var item = document.getElementById("customerid"); item.defaulttype = "2"; However, I'm not sure where I would add javascript to affect this dialog box that is popped from Outlook. Thanks I have the same issue... On Mar 24, 4:29=A0pm, Brian Cross <BrianCr...@discussions.microsoft.co...

newlines and quotation marks in dialog
Is it possible to use newline characters, quotation marks, ampersands and so forth in a control in my dialog? So far, with static text and with an edit box, I am getting disappointing results. On Mar 21, 5:04 pm, "SteveR" <sruss...@removethisinnernet.net> wrote: > Is it possible to use newline characters, quotation marks, ampersands and so > forth in a control in my dialog? So far, with static text and with an edit > box, I am getting disappointing results. \r\n will insert a newline for a edit control. Make sure you turn the multiline style on in resource(o...

why I can not close DialogBox?
I tried my best to close the DialogBox,but failed. The whole code is below. #include <windows.h> #include"resource.h" INT_PTR CALLBACK DlgProc1(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam); int PASCAL WinMain (HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpszCmdParam, int nCmdShow) { MSG msg; DialogBox(hInstance, MAKEINTRESOURCE(IDD_DIALOG1), NULL,(DLGPROC)DlgProc1); while (GetMessage (&msg, NULL, 0,0)) { TranslateMessage(&msg); DispatchMessage(&m...

Cloning a View in Dialog-based MFC Program, part 2
I've created a toolbar button fort he cloning operation and the function it calls invokes a constructor for a new view. Using the debugger I can see that this new view has all of the right data ... but it has no window! What's my next step? TIA Norm I dont know the context of your action but make sure that you make the view and its parent frame are both visible. -- Ajay Kalra [MVP - VC++] ajaykalra@yahoo.com "Norm Dresner" <ndrez@att.net> wrote in message news:Ex45b.125557$3o3.8831281@bgtnsc05-news.ops.worldnet.att.net... > I've created a toolbar butt...

owa doesnt display a login dialog and wont send picture attachments in exchange 2000
one user out of several doenst get a login dialog when he goes to owa for exchange 2000. it's as if his computer is eternally loged in anyone can walk up to his computer and goto the url server/exchange and go right into his inbox without it prompting for a user name and password. thats' real secure, just what we need here in the "enterprise" the other problem, is that he , unlike all the other users, cannot attach a picture to his email from owa. when he clicks on attach it doesnt do anything. his machine is running xp pro with sp2 just like other users. On 25 May 2006 1...

Change opportunity statuscode after close
There is a way to change the statuscode of a opportunity after close(supported or not)? I can have some steps after close a opportunity... Thank you for pay attention []'s Vin�cius Pitta Lima de Ara�jo Once the status is closed the data becomes read only. You=20 will not be able to change this record via the SDK.=20 >-----Original Message----- >There is a way to change the statuscode of a opportunity=20 after >close(supported or not)? I can have some steps after=20 close a opportunity... > >Thank you for pay attention >[]'s >Vin=EDcius Pitta Lima de Ara=FAjo &...

Skinning dialogs? #2
I have 2 questions about CDialog skinning... 1: I'm handling the OnNcPaint and OnNcCalcSize, but always when it is the first time the window is drawn, when I click on the caption, it draws a border around the caption, and then it doesnt happen anymore... No idea why... 2: How can I draw the Min/Max/X buttons also? Hope you can help... Joe B. ...

Customizing File Dialog
Hi all: I am trying to customize the file dialog. To do this, I have learned, you provide a template that contains only the additional controls that you want. By default, these controls appear below the normal file dialog controls, which is what I want. However, when the Places bar is present, it extends only to the bottom of the original controls, and my controls span the full width of the dialog, which is not what I want. Does anybody know how to fix this? I am actually using VC6, but I have previously customized the normal file dialog to show the Places bar on OS's that permit...

OpenXML - Excel
Hi, I don't see in the documentation any way to close the Excel document without saving the changes. I mean, all the parts have a Save() method, and the SpreadSheet part has a Close() method which also saves. How can the Excel document file be closed without saving? Like in case there's an exception, and we need to cleanup and close the file w/o saving. Thanks in advance, Richard ...

Subclassing a Dialog Control ?
Hi guys, When I put homemade controls in my dialog boxes I usually just use ClassWizard to create a member variable of the control type of my derived class, for example, I create a custom edit box derived from CEdit and ClassWizard recognizes it. Is there a way I can do it without having to have member variables of my derived class, so I can use GetDlgItem() ? I really only want to do this for consistency because for my other controls I don't have dialog member variables (at least not declared explicitly). I think it's called subclassing but am probably wrong. Thanks. "Robe...

Pub 2000 closes when wizard closed on XP Pro system
Gang I am using the same Publisher 2000 that I used successfully with ME for years. Now that I installed XP Pro, when I launch Publisher 200 it opens okay, but when I close the Wizard I receive the following message (Unsaved Publication) Microsoft Publisher: MSPUB.EXE - Application Erro The instruction at ")x77f5310f" referenced memory at ")x00000000". The memory could not be "written" Click on OK to terminate the program When I click OK, Publisher 2000 closes I tried uninstall/reinstall, updating my video card and going to the latest drivers, changed my mothe...

Empty Dialog Box
I am able to post to newsgroups, but when I tried to Reply Group to a message I posted (replying to myself) I got a dialog box with three buttons, a check box, and an "I" icon. There is, however, no text in the dialog box, on the checkbox or on the buttons! Clicking any (or all) of the buttons has no apparent affect. The dialog only goes away if I click the "X" in the corner and it never sends my reply. -Will T Will T <bogusemail@microsoft.com> wrote: > I am able to post to newsgroups, but when I tried to Reply Group to a > message I posted (replying to my...

Creating Modeless dialogs in a DLL
Hi I created a MFC regular DLL using the classwizard I am loading the DLL from a console based Win32 Application In the InitInstance of the CWinApp derived class of the DLL, If I try to create a Modeless Dialog , The dialog seems to be created, but it does not respond to any inputs and non of the controls over it are visible How do I make this work? Basically, I need a dialog box in the DLL just to catch user defined windows messages posted by another application I know for sure that the messge is being posted correctly. Is there an easier way of doing this Thanks in advanc Di. ...

Modala dialog windows
Hello! I just wonder if you can mention any modala dialog windows in windows professional. A modalt dialog windows means that you can't continue without answer the modala dialog window. //Tony If you are talking about a system modal dialog box, they don't exist anymore. AliR. "Tony Johansson" <johansson.andersson@telia.com> wrote in message news:5PxEd.13863$d5.116649@newsb.telia.net... > Hello! > > I just wonder if you can mention any modala dialog windows in windows > professional. > > A modalt dialog windows means that you can't continue ...

show COM Add-In dialog
If a user does not have the Add-Ins... menu item under the Tools menu, you can still bring up that dialog box from VBA code using either Application.Dialogs(xlDialogAddinManager).Show or Application.Dialogs(321).Show (The latter uses its ID property.) Does anyone know if the same is possible with the COM Add-Ins... menu item? I've looked in Help's Dialog collection, and also looped through ID numbers, but without success. I'm trying to leave the user's toolbars alone and show the COM Add-In dialog the same as you can the Add-Ins dialog. Thanks. Try something like the...

How do I close an RTV
I have an RTV for a replacement. I have received and invoiced the PO created from the RTV but I cannot see how to close the RTV. The RTV is not showing that that the item has been received either. I cannot receive thru RTV receiving. Not sure how to proceed. Can someone define the RTV process and let me know what I did wrong. I am using GP2010. Amy ...

cannot get dialog box to disappear
I continue to get an hour glass and cannot get dialog box to disappear. I t continually asks to grant access or not. "bud" <bud@discussions.microsoft.com> wrote in message news:7F59F186-CD12-4122-AEB0-1250DE5D7933@microsoft.com... >I continue to get an hour glass and cannot get dialog box to disappear. I t > continually asks to grant access or not. What dialogue box? What version of Outlook? What account type? What are you trying to do? What is asking? Rather a lack of details here. -- Brian Tillman [MVP-Outlook] ...