PreTranslateMessage and controls

I have a member function in my project that is in place to prevent the
dialog box from closing when ENTER or ESCAPE is pressed inside an edit
box. However, in the process, the push buttons are (expectedly) no
longer triggered when they have input focus and the user pressed
ENTER. I want the program to tab only from edit boxes if enter is
pressed, otherwise perform the default windows action. How do I test
for the current selected Dialog item? The block in question has the
C-Style comments.

BOOL CMainDlg::PreTranslateMessage(MSG* pMsg) 
{
    if( pMsg->message == WM_KEYDOWN )
    {
        if( pMsg->wParam == VK_RETURN )
        {
            if (/******* Is this an edit box? ********/)
            {
                pMsg->wParam = VK_TAB;
            }
            else
            {
            ::TranslateMessage(pMsg);
            ::DispatchMessage(pMsg);
            return TRUE; 
            }
        } else if (pMsg->wParam == VK_ESCAPE )
        {
            ::TranslateMessage(pMsg);
            ::DispatchMessage(pMsg);
            return TRUE; 
        }
    }
    
    return CDialog::PreTranslateMessage(pMsg);
}


Thanks for any help.
-Mike-
0
guest (34)
8/2/2003 7:59:36 PM
vc.mfc 33608 articles. 0 followers. Follow

4 Replies
962 Views

Similar Articles

[PageSpeed] 44

I consider using PreTranslateMessage for this purpose a misuse of the mechanism. It is so
trivial to solve the problem without it that it makes the complexity impossible to
justify. Read my essay on dialog-based apps on my MVP Tips site.
					joe

On Sat, 02 Aug 2003 15:59:36 -0400, Mike009 <guest@unknown.com> wrote:

>I have a member function in my project that is in place to prevent the
>dialog box from closing when ENTER or ESCAPE is pressed inside an edit
>box. However, in the process, the push buttons are (expectedly) no
>longer triggered when they have input focus and the user pressed
>ENTER. I want the program to tab only from edit boxes if enter is
>pressed, otherwise perform the default windows action. How do I test
>for the current selected Dialog item? The block in question has the
>C-Style comments.
>
>BOOL CMainDlg::PreTranslateMessage(MSG* pMsg) 
>{
>    if( pMsg->message == WM_KEYDOWN )
>    {
>        if( pMsg->wParam == VK_RETURN )
>        {
>            if (/******* Is this an edit box? ********/)
>            {
>                pMsg->wParam = VK_TAB;
>            }
>            else
>            {
>            ::TranslateMessage(pMsg);
>            ::DispatchMessage(pMsg);
>            return TRUE; 
>            }
>        } else if (pMsg->wParam == VK_ESCAPE )
>        {
>            ::TranslateMessage(pMsg);
>            ::DispatchMessage(pMsg);
>            return TRUE; 
>        }
>    }
>    
>    return CDialog::PreTranslateMessage(pMsg);
>}
>
>
>Thanks for any help.
>-Mike-

Joseph M. Newcomer [MVP]
email: newcomer@flounder.com
Web: http://www.flounder.com
MVP Tips: http://www.flounder.com/mvp_tips.htm
0
newcomer (15974)
8/2/2003 9:18:52 PM
Thanks, I'll try GetFocus(). Just to clarify, you suggest deriving
from CEdit and overriding OnOK() and/or OnCancel() to perform the
appropriate action for text boxes? Sounds like a good idea, but I just
want to be sure I fully understand what you're saying. I'm still new
with MFC and VC.

Thanks.


On Sat, 2 Aug 2003 17:57:03 -0500, Scot T Brennecke
<ScotBspamhater@MVPs.org> wrote:

>GetFocus should give you the HWND of the selected control.  However, 
>this sounds like you really want to have a class derived from CEdit that 
>takes care of processing the messages when its window has focus.
>
>In article <2mdoiv4acp9jr4s1p7tbjio0not79kp2fk@4ax.com>, Mike009 says...

0
guest (34)
8/2/2003 11:22:37 PM
Not OnOK or OnCancel, as those are methods of CDialogs, not CEdits.  I'm 
not sure exactly what action you need to take, so giving more specifics 
is difficult, but I'd imagine your solution would involve handling the 
WM_SETFOCUS message.  If you set your edit to trap keystrokes in its 
handler for WM_GETDLGCODE, you can handle the keypresses of enter or 
escape in your edit class. 

In article <nghoiv8s6hmlhol8hnl6mck9am11mlmo80@4ax.com>, Mike009 says...
> Thanks, I'll try GetFocus(). Just to clarify, you suggest deriving
> from CEdit and overriding OnOK() and/or OnCancel() to perform the
> appropriate action for text boxes? Sounds like a good idea, but I just
> want to be sure I fully understand what you're saying. I'm still new
> with MFC and VC.
0
8/2/2003 11:47:51 PM
I would tend to put an OnChar handler in the subclass of the edit control and have it
either do the action or PostMessage/SendMessage a message to the parent control to perform
the action. Note that to do this you will have to declare the edit control to be multiline
(so the message is seen) and add an OnGetDlgCode which will |-in the bit that says this
control wants to see carriage returns. In the case of the OnChar handler, if you see a
return (which is NOT \n, but is actually \r, but is really VK_RETURN as far as you are
concerned), you must NOT call the superclass...

void CMyEdit::OnChar(UINT nChar, ...other stuff here...)
   {
    if(nChar == VK_RETURN)
       { /* notify parent */
        GetParent()->SendMessge(UWM_HANDLE_THIS_EVENT, ....maybe parameters...);
        return;
       }
    CEdit::OnChar(...etc...);
   }

				joe

On Sat, 02 Aug 2003 18:18:05 -0400, Mike009 <guest@unknown.com> wrote:

>Thank you; very helpful. Now I can present you and the group with a
>more simplied question. When OnOK is called, I want an action
>performed only if one of my textboxes has input control (focus?). How
>does one determine if the currently selected control on the dialog
>equals a particular control (which is mapped to a control member
>variable I assume) ?
>
>
>
>On Sat, 02 Aug 2003 17:18:52 -0400, Joseph M. Newcomer
><newcomer@flounder.com> wrote:
>
>> Read my essay on dialog-based apps on my MVP Tips site.
>>					joe
>>
>>On Sat, 02 Aug 2003 15:59:36 -0400, Mike009 <guest@unknown.com> wrote:
>
>>><snip>
>
>>Joseph M. Newcomer [MVP]
>>email: newcomer@flounder.com
>>Web: http://www.flounder.com
>>MVP Tips: http://www.flounder.com/mvp_tips.htm

Joseph M. Newcomer [MVP]
email: newcomer@flounder.com
Web: http://www.flounder.com
MVP Tips: http://www.flounder.com/mvp_tips.htm
0
newcomer (15974)
8/3/2003 2:23:30 AM
Reply:

Similar Artilces:

Field control
Hello! I have set up an emailable spreadsheet that acts as a form. This "form" is sent to myself to consolidate the data. Would it be possible for this form to stop the macro (and subsequently not being emailed) until certain "compulsary" fields are filled in by the user? Thanks in advance. CorreoMaster Hi correomaster You can use the Counta function in VBA to test if all cells have a value in the range Example for A1, A3 and A5 If Application.WorksheetFunction.CountA(Range("A1,A3,A5")) = 3 Then 'mail code here Else MsgBox "...

PostMessage with WM_ENABLE to control in parent dialog
In the modeless dialog class I used the following code: HWND control = ::GetDlgItem( ::GetParent( m_hWnd ), IDC_BUTTON_1 ); ::PostMessage( control, WM_ENABLE, (WPARAM) TRUE, 0 ); But the button (IDC_BUTTON_1) is never enabled on the parent dialog. I want to use PostMessage (and only postmessage). How do I do this? Thanks > In the modeless dialog class I used the following code: > > HWND control = ::GetDlgItem( ::GetParent( m_hWnd ), IDC_BUTTON_1 ); > ::PostMessage( control, WM_ENABLE, (WPARAM) TRUE, 0 ); > > But the button (IDC_BUTTON_1) is never enabled on the parent di...

Safe user control hosted in IE 8
Hi everyone, Since Internet Explorer 8 has added its new UI-less URLAction to check the .NET MIME Filter, mscorie.dll, for content from the Internet zone (http://blogs.msdn.com/askie/archive/2009/05/22/net-control-no-longer-loads-in-ie8-in-internet-zone.aspx), i have to register my web server to the trusted site's list to load my user control (C# framework 3.5). But I can't touch the client machine's configuration, so i need to make this works without changing the Microsoft .NET Framework's configuration nor the IE's configuration. I try with a "Strong name"...

Edit text in List Control
Dear friends, I have implemented a List Control using List View with the detailed style having several columns containing subitmes. Now i want to let users change subitmes listed under two columns only. Please, help me to figure out how to do this. Thank you. Varuna. http://www.codeguru.com/Cpp/controls/listview/editingitemsandsubitem/article.php/c4175/ http://www.codeproject.com/listctrl/listeditor.asp http://www.codeproject.com/listctrl/editing_subitems_in_listcontrol.asp Tom <varuna82lk@gmail.com> wrote in message news:1125679899.375109.107300@o13g2000cwo.googlegroups.com... &g...

Bitmap and Picture Control ???
I'm trying to write a simple example program to learn more about using bitmaps and picture controls. It is a dialog-based program with only two buttons and one picture control. One button is to display a bitmap, and the other is to erase the bitmap. The bitmap is displayed correctly and does erase with the other button, but I am not able to click on the display button again without an Assertion Error. Although I have found that if I declare the bitmap locally in the display button handler and put another bitmap declaration in the erase button handler, it is possible to click the disp...

Control ID questron
Hi all: I'm creating an edit control on the fly, to implement in-place editing on a CListCtrl, and I was wondering wether I need to define an ID for it in resource.h or I can use whatever value I choose safely. The CEdit::Create reference has this example, where they use '1' as the ID: void CMyView::OnInitialUpdate() { CView::OnInitialUpdate(); // dynamically create an edit control on the view CEdit* pEdit = new CEdit; pEdit->Create(ES_MULTILINE | WS_CHILD | WS_VISIBLE | WS_TABSTOP | WS_BORDER, CRect(10, 10, 100, 100), this, 1); } I don't usually create...

How to trap PreTranslateMessage in Win32 (non-MFC) app?
How do you trap PreTranslateMessage in a Win32 (non-MFC) app? I have an existing MFC class called CCustomEditCtrl that I have to convert to pure Win32. I am doing some processing in it's PreTranslateMessage event. Can someone tell me where to put this code in the Win32 version? Do I hvae to trap some WM_ event ? Thanks. Jeff, You would just handle the messages in the control window function. If you want to do something before all other messages, take care of it towards the top of the window function. In pseudo-code: control_function() { // You can, for example, add your proces...

Using radio button controls in a Word form
I'm creating forms for users to download from a website. The first form I developed contained a drop-down list and numerous radio buttons from the Controls toolbar, and works perfectly for everyone who has downloaded one. And they open ok for me, i.e. NOT in design view, when they are e-mailed to me by users. The second one I'm developing is similar and has no drop-down list and only 3 radio buttons. But after downloading to my PC this second form frustratingly opens in controls design view so the buttons don't work. Why is this? How can one form work perfectly an...

how to draw a picture control on a dialog?
Hi, I cannot draw a picture on a picture control below. My bitmap simply does not show up. Could you give me a hit where I did wrong below? Thanks for your help. Tony void CMyDlg::OnPaint() { CWnd* pPicture = GetDlgItem(IDC_MY_PICTURE_CONTROL); CClientDC dc(pPicture); CDC dcMemory; dcMemory.CreateCompatibleDC((CDC*)&dc); // m_bitmap below was loaded with a resource bitmap at the beginning CBitmap *pOldBitmap = dcMemory.SelectObject(&m_bitmap); dc.BitBlt(100, 100, 100, 100, &dcMemory, 0, 0, SRCCOPY); dcMemory.SelectObject(pOldBitmap); ... Your b...

active x controls
I am new to Outlook. Whenver I try to send an email in html I get a message saying that my security settings prohibit running Active X controls and my page may not display properly. How do I change this setting or get rid of message? Could it have anything to do with recently downloading a smiley toolbar? Any help much appreciated. In news:3A3F139B-0D0E-4FD0-BFD3-A850C99E05C8@microsoft.com, yushilot <yushilot@discussions.microsoft.com> had this to say: My reply is at the bottom of your sent message: > I am new to Outlook. Whenver I try to send an email in html I get a > me...

Lebans tooltip control 10-25-07
I am trying to use the tooltip control on a form with a tab control, on which are the other controls I want to show information for. On controls that are outside the tab control, it works fine; on controls inside the tab control, the tooltip shows on text boxes only when they have the focus, and on check boxes not at all. I've tried every naming scheme for controls I can think of, without any luck. Anybody have any ideas about this??? Is it the same problem as using a subform???? -- Jack Walsh ...

Feature control
Is there a way to lock Outlook down, so that only the email features are available to users? What version of Outlook? -- Aloha, -Ben- Ben M. Schorr, OneNote-MVP http://home.hawaii.rr.com/schorr **I apologize but I am unable to respond to direct requests for assistance. Please post questions and replies here in the newsgroup. Mahalo! "Candace" <anonymous@discussions.microsoft.com> wrote in message news:01ed01c3a7c5$0bac6830$a401280a@phx.gbl... > Is there a way to lock Outlook down, so that only the > email features are available to users? Version 2003 >----...

Backup Schedule for 2003 Domain Controllers
We are a small company with only 2 domain controllers both using Windows 2003 Server Standard. Currently we back them with a full backup on Fridays and incremental backups Mon - Thurs. Since we use Active Directory should we be running a full backup every night? If so what folders/files should be backed up each night or do we just backup the entire C drive? Hello raz4183, The minimum backup you need to restore AD is the system state of a DC. http://technet.microsoft.com/en-us/library/cc778772(WS.10).aspx http://support.microsoft.com/kb/216993 The schedule depends on your am...

Owner draw CListCtrl, EnsureVisible, PreTranslateMessage
There is Owner draw CListCtrl with overriden DrawItem. This class has subitems arbitrary controls (CEdit, CButton...). It should be fine to detect arrows keys in controls to jump with caret in CEdit boxes in one column by pressed arrow key. I tried to catch it in CEdit -> PreTranslateMessage() in block if(pMsg->wParam == VK_UP) then to call EnsureVisible() to parent CListCtrl to be caret always visible and CListCtrl scrolls if needed. Problem is when first time it scrolls up, some infinite loop begins and CPU 100% . It seems that something wrong with this... Can be EnsureVisible(...

greater control of date/time stamps on line charts in excel
It works in 97. 1st column had date stamps. 2nd column has time stamps. Columns 3 through x have data (x = 7 for my application). When graphing large amounts of data (greater than 10 rows), excel does not allow me to set attractive increments for the date time stamp on the X-axis when using the 2-D line chart (smooth line). I have tried the same graphing in 2000 and 2003 with no success. Excel 97 formats these number automatically. Can I get the formating right in 2000 or 2003? ---------------- This post is a suggestion for Microsoft, and Microsoft responds to the suggestions with the...

pretranslatemessage behaviour
Hi, I have a problem when I press CTRL+ALT+D keys the PreTranslateMessage function is not fired for WM_KEYDOWN, only for WM_KEYUP. Any suggestions? Thanks! Hey Luis, check out this article and see it if helps (talks about disabling that key combination by setting up a hotkey so you get the message instead of the OS) http://www.codeguru.com/Cpp/misc/misc/keyboard/article.php/c433 "Luis Porras" <luis.porras@dakotaimaging.com> wrote in message news:OiUM1tkVFHA.2960@TK2MSFTNGP15.phx.gbl... > Hi, > > I have a problem when I press CTRL+ALT+D keys the PreTranslateM...

How do i re-download my volume control?
I accidently deleted my volume control on my tool bar and i need it back...is there some way that i could re-download it or get it back? L, This is an Excel newsgroup, not a Windows group however... you could try: Start (button) | Control Panel | Sounds and Audio Devices | Volume (tab) | and checkmark "Place volume icon in the taskbar" Jim Cone San Francisco, USA "Luver_not_a _fighter" <Luver_not_a _fighter@discussions.microsoft.com> wrote in message news:4E699181-6E31-44E4-A435-985895D896F1@microsoft.com I accidently deleted my volume control on my tool bar ...

PreTranslateMessage
Hi I'm trying to catch a CTRL+V event in my PreTranslateMessage function. Now when V is pressed pMsg->wParam == 86 but what is it when CTRL+V is pressed. Or is there some other way of catching the CTRL+V key press Thanks. If there's another way, we'll hear about it. Here's what I do: When you get a WM_KEYDOWN and a VK_SHIFT, set m_shiftdown=1. When you get a 'V', check if m_shifdown==1 When you get a WM_KEYUP and a VK_SHIFT, set m_shiftdown=0. Tom, > Hi I'm trying to catch a CTRL+V event in my PreTranslateMessage function. > Now when V is pressed p...

rights for dropdown control ....
Hi, I have created an dropdown control in contacts form. and i have 2 items in the dropdown list. now when user1 logs in i want to show only the 1st item in the dropdown control or i should able to disable the control. but when user2 logs in i should show all the items in the dropdown control. Now how to hide dropdown items according to users ? Regards, Your not going to be able to do this Richard without a major rewrite of the code. "Richard I.P" <iamiamiam_77@yahoo.com> wrote in message news:68b0f2fd.0402110148.7039756b@posting.google.com... > Hi, > > I have cre...

Where to Hide Page in Tab Control
I have a Form, which has a tab control on it. When I open the Form, I want to hide a page in the tab control, based on some other conditions. During the Form Load event, I check for the condition and then try to hide the specific page. I get an error that the tab control object is closed or doesn't exist. What event would be the appropriate place to put this check and hide the page? Thanks, Steve "Steve Haack" <SteveHaack@discussions.microsoft.com> wrote in message news:1EFF5F65-41C6-4D7F-992B-42C51B827E3C@microsoft.com... >I have a Form, which has a...

How do you control the color/pattern of a pie chart?
I need help with my pie charts. I need to create pie charts that are easily understood in B&W. How do I set the color or pattern for each portion of my pie chart? Hi, To format a slice you need to select it first. Click the pie once to select all slices. Click again to select individual slice. You can use the Fill Effects > Patterns to fill with b/w patterns. Also in print preview the Setup dialog has a Print Black & White option on the Chart Tab. Note this is only visible if you have a chart sheet or select the chartobject before print preview. If you are printing chartobje...

Version Control and GAC
This post is an attempt to find best practice for version control of assemblies in a solution with a view to installing them in the gac and have clients reference the correct version of a dll I have a solution that contains a number of projects (approx 25). One of the projects is my web application (TZ_WebApp) There are 4 console apps that run as scheduled tasks (TZ_Task1, TZ_Task2, TZ_Task3, TZ_Task4) There are a number of Windows Services (TZ_Service1, TZ_Service2, TZ_Service3, TZ_Service4) The above apps are currently installed on an iis server There is also a single winforms ...

Spinner control to increment percentages
How can I use a spinner control to increment % numbers in the linked cell? I believe I need to use a second cell for the calculations but I don't remember the technique Link the spinner to cell A1 (for example); set MIN to 0, MAX to 100 In cell B1 (say) use =A1/100 to get values from 0 to 1. Remember that 25% is really 0.25 when you do any math with it; if you wish you could format B1 with the % tool. This will give you steps 0, 0.1, 0.02..... 0.99, 1 To get more precision set MAX to 1000 and use =A1/1000. best wishes -- Bernard V Liengme www.stfx.ca/people/bliengme remove caps from e...

control command
My Control command has stopped funtioning to allow me to select a group of non adjacent cells in Excle. Both control keys? If you swap out keyboards, do you still have the problem? mtvlgl wrote: > > My Control command has stopped funtioning to allow me to select a group of > non adjacent cells in Excle. -- Dave Peterson Have you checked that the CNTRL key is working outside of Excel? May be the keyboard is broken. -- Gary's Student "mtvlgl" wrote: > My Control command has stopped funtioning to allow me to select a group of > non adjacent cells in Ex...

How to prevent item changing in a list control with cached data?
Hello, Im using a virtual list control with cached data items (CListCtrl and style 'LVS_OWNERDATA' set). The selected item's data (row) might be modified by user interaction, so that any following item (row) changing should be avoided, until data has been written to the data storage. How can I achieve this, since LVN_ITEMCHANGED seems to be too late to reject item (row) changing? Thanks Edgar LVN_ITEMCHANGING is sent before change. Return TRUE to prevent changes or FALSE to allow. Normand "Edgar Geisler" <e.ge@nospam.gmx.net> a �crit dans le message de news: ...