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.






0
jeff6755 (9)
5/25/2004 6:18:26 AM
vc.mfc 33608 articles. 0 followers. Follow

3 Replies
1575 Views

Similar Articles

[PageSpeed] 35

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 processing here
    // If you are handling special messages, you might
    // want to move them down to the switch

    switch( message )
    {
        case WM_...
    }
}

Johan Rosengren
Abstrakt Mekanik AB

"Jeff R." <jeff@aol.com> skrev i meddelandet
news:O3y1cAiQEHA.3748@TK2MSFTNGP09.phx.gbl...
> 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.
>
>
>
>
>
>


0
5/25/2004 7:20:52 AM
PreTranslateMessage is an artifact of MFC. There is no "message" that does this; it is a
virtual method.

First, there is rarely a need to use it, particularly in something like a custom edit
control. What is it handling that cannot be done in OnKeyDown, for example? I find
PreTranslateMessage to be one of the most badly abused methods, since it is almost always
used incorrectly to solve problems that it should not be used to solve. 

What you would have to do is interpose a call to it after the GetMessage, and before the
TranslateMessage. But you should have some good reason to need to do this.

You will have to use "classical" window subclassing, that is, use
SetWIndowLong(GWL_WNDPROC) to point to your own handler for the edit control, write a
normal window procedure, but then do CallWIndowProc on the pointer you saved from the
SetWIndowLong (which returns the previous pointer). Petzold or our WIn32 Programming give
examples of how to do this.
				joe

On Tue, 25 May 2004 01:18:26 -0500, "Jeff R." <jeff@aol.com> wrote:

>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.
>
>
>
>
>

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)
5/25/2004 8:55:20 AM
"Jeff R." <jeff@aol.com> wrote in message
news:O3y1cAiQEHA.3748@TK2MSFTNGP09.phx.gbl
> 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.

Your Win32 app will have a message loop. A simple version is:

while (GetMessage (&msg, NULL, 0,0))
{
    if (!TranslateAccelerator(hwndFrame, hAccel, &msg))
    {
        TranslateMessage (&msg) ;
        DispatchMessage (&msg) ;
    }
}

Considerably more complicated versions are possible.

The most obvious place to put PreTranslateMessage is immediately before
TranslateMessage :). However, the appropriate location depends on what
PreTranslateMessage does (specifically, what does it need to be prior to)
and what arguments it requires.


-- 
John Carson
1. To reply to email address, remove donald
2. Don't reply to email address (post here instead)

0
5/25/2004 9:07:42 AM
Reply:

Similar Artilces:

avalon from within mfc ?
Hello, I am working for a bigger company that has a large win32 (mainly MFC) codebase. Their products mainly are audio- and multimedia authoring applications for the home user market (allthough there are some pro tools too ). Since most of those apps rely heavily on performance and they need to support older OSes too they don't see themselfes moving to .NET anytime soon. As Longhorn with Aero and Avalon emerges they are starting to get worried about if their win32/MFC applications will be able to benefit fromt the rich userexperience that Aero and Avalon promise. I think this a situiati...

VLookup VBA error trapping
Can anyone tell me how to modify this formula to trap errors? I tried wrapping it in IsError (code) Then...but it doesn't work. Public Sub RunMeNow() Dim i As Long Dim iLastRow As Long With Sheets("Sheet2") iLastRow = .Cells(.Rows.Count, "A").End(xlUp).Row For i = 3 To iLastRow 'iLastRow to 1 Step -1 .Cells(i, "B").Value = Application.VLookup( _ .Cells(i, "A").Value, Range("RegionGrouping"), 2, False) Next i End With End Sub Or any other way I can handle an error with this type of pr...

trapping LVN_ENDSCROLL
Hi there, I'm trying to trap the LVN_ENDSCROLL notification in my parent, but don't seem to get it. Here's what I have. In my parent's header: void OnLvnEndScroll(NMHDR *pNMHDR, LRESULT *pResult); In the source: void CSKListCtrl::OnLvnEndScroll(NMHDR *pNMHDR, LRESULT *pResult) { Invalidate(); UpdateWindow(); *pResult = 0; } In the message map: ON_NOTIFY(LVN_ENDSCROLL, WM_QUICKLIST, OnLvnEndScroll) where WM_QUICKLIST is mapped to my child's ID. What am I doing wrong? Thank you. Well since I couldn't find a way of trapping LVN_ENDSCROLL, I just used the HSCROL...

non-integer scrollbar
I have an x-y (scatter) graph with non-integer, all positive x values and a scrollbar set with an upper and lower limit. As I scroll, a vertical cursor is moved through the chart but only to integer values. I'd like the vertical cursor bar to move to each of the actual non-integer x values in my data as I move the scrollbar. Can anyone point me to VBA code or a formula solution to alter the scrollbar so that it can handle non-integers? My thanks in advance for any suggestions. Cheers! Brad On Mon, 5 Nov 2007, in microsoft.public.excel.charting, Brad <lreid@flash.net> sa...

MFC Project with /clr and CWinFormsControl
I have a VS2005 C++ MFC project that I modified to use /clr. The program still worked ok. Then using an example I found I created a button in a dialog box using CWinFormsControl<Button> Button1; and instantiated it in the dialog by using Button.CreateManagedControl I added a click event and all worked ok, so I thought great, now I can go for it. I then used CWinFormsControl<DataGrid> Grid1; and Grid1.CreateManagedControl (WS_VISIBLE | WS_CHILD, IDC_GRID1, this); The datagrid does display in my dialog, but I am unable to figure out how to load it or give it columns, et...

Calling .NET from MFC
Hi, Could somebody point me to some sample code to call a .NET from MFC (no managed extensions please) ? I understand that this involves using COM Interop but a complete example will be a great help because I believe there has to be some additional plumbing on the .NET side. Thanks in advance. regards, T ---- Because things are the way they are, things will not stay the way they are. -- Bertolt Brecht The answer lies here: http://www.codeproject.com/dotnet/nettocom.asp On May 12, 10:33 am, T <sw.tejasvi...@gmail.com> wrote: > Hi, > > Could somebody point me to some sample ...

I am not receiving non-delivery receipts
I've recently moved from Outlook Express to Outlook 2007 and am not receiving any non-delivery receipts for emails sent to the wrong email address. Any suggestions? "las42479" <las42479@discussions.microsoft.com> wrote in message news:1D46ECF9-63AB-441C-977A-FB32537EB136@microsoft.com... > I've recently moved from Outlook Express to Outlook 2007 and am not > receiving > any non-delivery receipts for emails sent to the wrong email address. Any > suggestions? Well you wouldn't if the email address actually exists or is swept by a &quo...

Trapping errors
How do write a piece of code that traps VBA error messages and ignores them? See my post on 22/07/07 about an Automation error message Thanks Tony Take a look at what Allen Browne has at http://www.allenbrowne.com/ser-23a.html -- Doug Steele, Microsoft Access MVP http://I.Am/DougSteele (no e-mails, please!) "Tony Williams" <tw@invalid.com> wrote in message news:uWKdkqVzHHA.5992@TK2MSFTNGP02.phx.gbl... > How do write a piece of code that traps VBA error messages and ignores > them? > See my post on 22/07/07 about an Automation error message > Thanks >...

Outlook 2002 attachment problems to non-Outlook users
When sending Word files (.doc) as attachments in Outlook 2002 to users who don't have Outlook the attachment shows up as a winmail.dat file. Any suggestions, anyone? Send it using plain test formatting. -- Diane Poremsky [MVP - Outlook] Author, Teach Yourself Outlook 2003 in 24 Hours http://www.poremsky.com - http://www.cdolive.com Outlook Tips: http://www.outlook-tips.net/ Expert Zone http://www.microsoft.com/windowsxp/expertzone Search for answers: http://groups.google.com Most recent posts to the Outlook newsgroups: http://groups.google.com/groups?as_ugroup=microsoft.public.outl...

SLP in MFC
Hi all, Could any one please explain me how to multicast SLP packet in MFC? Is there any sample code for this? Nas If I knew what SLP was, I might have a chance to answer the question. Is it some protocol implemented using UDP? If it involves UDP, I'd use CAsyncSocket. If not, since I don't recognize the acronym, I'm otherwise at a loss. joe On Sun, 14 Oct 2007 21:43:51 -0700, "doublemaster007@gmail.com" <doublemaster007@gmail.com> wrote: >Hi all, > >Could any one please explain me how to multicast SLP packet in MFC? Is >there any sample co...

Combo showing non current employee
Hello, I have employees in a table. For a given job sheet form, the employee is selected with a combobox listing all current employees. All fine. If an employee leaves, they are marked as no longer current. My problem is, if an old job record is looked at, the employee is not listed since they are not current. The combo is blank. I have gotten around this prior by editing the rowsource for [all current employees] OR [selected employee]. But this only works in single form. I need it in a continuous form, and not sure whether the best option is to reference the field in ...

Trapping for keystrokes...
Is there a way I can write a little program that will trap the keyboard and save whatever is being typed to a file? In other words, I need to write something that will run in the background but will be able to know whatever is typed on the keyboard and then save those keystrokes to a file on the hard drive. Thanks, Fred A keyboard hook. joe On Tue, 30 Sep 2003 03:41:26 GMT, "sftwrdvlpr" <bogus@news.com> wrote: >Is there a way I can write a little program that will trap the keyboard and >save whatever is being typed to a file? In other words, I need to write &g...

Trapping a value to use in my form
I am quite new to this and need some help. I have a form with a record source of a query. In the query I have the criteria set to ask the user a question in a popup box which searches a table for that input which is then reported back to the form to view EmployeeNumberQuery is as follows: Field: Employee Table: Employee_Number Criteria: [Enter the Employee Number] <-this is the value I want to capture and display in the form This query also has other fields that are reported back to the form that match the entered value The Employee_Listing_Table is as follows: Form Hea...

Deny email to non users
Much as I hate to ask, but why doesn't someone at Microsoft build a patch so Exchange 5.5 can refuse email to non users like most mail software. Flood of non user mail in outbound queue is getting a little out of hand. I don't think that would be so hard for them to do. Give us one last fix.. If we all would monitor our users traffic their would probably be less spam on the net from these damn worms. Thanks Tom flustered ISP Microsoft has included this feature in Exchange 2003. Craig -- Craig Philbeck a-cphil@online.microsoft.com Microsoft PSS Please do not send email dir...

Where to find the msdn of the new edition MFC
thanks. "eric" <sound_of_nature@hotmail.com> wrote in message news:Ows2bnR1IHA.4220@TK2MSFTNGP02.phx.gbl... > thanks. It's called MFC Feature Pack for Visual Studio 2008 http://www.microsoft.com/downloads/details.aspx?FamilyId=D466226B-8DAB-445F-A7B4-448B326C48E7 -- David ...

windows resize event trap
I am trying to resize a form inside of excel base on windows resize event (not workbook resize)... I've already try Private Sub appevent_WindowResize(ByVal Wb As Excel.Workbook, ByVal Wn As Excel.Window) MsgBox "you have resized excel" End Sub and it works only with workbook resize... I'll appreciate any help on this... thanks LH ...

MFC 7 Merge module
I can't find the merge module to distribute MFC 7.1 DLLs. Can anyone help? Hi Gunnar, You may check the folder "Program Files\Common Files\Merge Modules" it is usually located on the same driver as your windows. Peter Huang Microsoft Online Partner Support Get Secure! �C www.microsoft.com/security This posting is provided ��as is�� with no warranties and confers no rights. -------------------- >Reply-To: "Gunnar Skogsholm" <gun@high-rustler.com> >From: "Gunnar Skogsholm" <gun@high-rustler.com> >Subject: MFC 7 Merge module >Da...

Starting Excel from a non-MS application
What is the command line syntax for invoking Excel to open to a specific place (i.e. either a specific cell or a named bookmark)? Hi see your post in Excel.misc P.S.: please don't multipost -- Regards Frank Kabel Frankfurt, Germany Rob Gordon wrote: > What is the command line syntax for invoking Excel to > open to a specific place (i.e. either a specific cell or > a named bookmark)? Sorry. Wasn't sure which category was more appropriate >-----Original Message----- >Hi >see your post in Excel.misc >P.S.: please don't multipost > >-- >Regards ...

VC++ 2005 - MFC
Hello, Can someone please explain how to get accelerator keys to work in a MFC application. I'm using CFormview. I have a menu and a toolbar (both with the id ID_VIEW_REFRESHDATABASE) and they work perfectly Both are called in MyFormView. I then added the accelerator key with the same id. but NOTHING HAPPENS. What am I missing? // Anders -- English is not my first, or second, language so anything strange, or insulting, is due to the translation. Please correct me so I may improve my English! It probably depends are where you put the handler and which window is active at the time y...

Non Inventory Item in Invoicing
for non-inventory item entered in Trx>Sales>Invoicing, the edit list show error: One or more line items containing error. what is the minimum posting a/c that need to be set for non-inventory items? thks In Posting Accounts setup, Sales series, you need to set the account for Non-Inventoried Items. However, some companies choose to leave this account blank in Posting Accounts Setup to force account selection at transaction processing time because different accounts may need to be used based on different non-inventory items. Frank Hamelly MCP-GP, MCT East Coast Dynamics www.eastcoas...

Trapping Ligitimate Mail
Have IMF installed on Exch 2k3. I know I can adjust the sensitivity of the filter. It seems to be catching most spam, however, one person's mail always seems to be trapped. This person usually has to send zip files. Is is possible force exchange to accept mail from this person? Is the file attachment the issue? Thank you, Justin You could add them to the safe senders list within the IMF filter. "Justin" wrote: > Have IMF installed on Exch 2k3. I know I can adjust the > sensitivity of the filter. It seems to be catching most > spam, however, one person&#...

non exact match
=AND($A$1 = $A1,ROW()>1,$A$1<>"") I am using the above formula for conditional formating. I need i modified to work if whatever is in A1 appears anywhere within th coloumn. Currentlly it only does exact match but i have multiple word in each cell Hope this is possible Rober -- Message posted from http://www.ExcelForum.com I'm not sure how you're using the your current formula, but you can use this: =COUNTIF(A:A,"*"&A1&"*") HTH Jason Atlanta, GA >-----Original Message----- >=AND($A$1 = $A1,ROW()>1,$A$1<>"") ...

Non US Dollar accounts do not show in Settings for Active Sync
I am currently using Microsoft Money 2006 for both my desktop and my pocket pc device. I am attempting to sync some of my accounts to my pocket pc device. However, it seems that the options for Active Sync is only shows acocunts that are using US Dollar as the currency. I would like to sync accounts that are using Singapore dollars. Any way I can do this? No. You can only synchronize accounts which are in your base currency, which appears to be US Dollars in your case. -- Glyn Simpson, Microsoft MVP - Money http://money.mvps.org Check http://money.mvps.org/faq/default.aspx for ...

installing a non-MS font into word
Version: 2008 Operating System: Mac OS X 10.5 (Leopard) Hi, I'm trying to download a free font called scriptina <http://www.1001fonts.com/font_details.html?font_id=2873> into word. It won't show up? I was able to get it to install into the text editor. any suggestions?? thanks! heatherc heatherc@officeformac.com wrote: > I'm trying to download a free font called scriptina > <http://www.1001fonts.com/font_details.html?font_id=2873> > into word. > > It won't show up? I was able to get it to install into the text editor. Install fonts in your ma...

Migrating from MFC 7 to 8 (error C2440)
Hello everybody. I'am migrating a project from MFC 7 to 8, and the compiler gives me the error: ....\MyCode.cpp(53) : error C2440: 'static_cast' : cannot convert from 'UINT (__thiscall CMyDerivedCwndClass::* )(CPoint)' to 'LRESULT (__thiscall CWnd::* )(CPoint)' Cast from base to derived requires dynamic_cast or static_cast The error is in the message map: BEGIN_MESSAGE_MAP(CMyDerivedCwndClass, CWnd) //{{AFX_MSG_MAP(CMyDerivedCwndClass) ON_WM_NCHITTEST() //Here is the error!!! //}}AFX_MSG_MAP END_MESSAGE_MAP() I need the MFC 7 version too, so, the c...