no more PreTranslateMessage

All my Dialogs are derived from AbstractDialog.
This AbstractDialog overrides PreTanslateMessage
so I can catch keystrokes in all my Dialogs.


BOOL AbstractDialog::PreTranslateMessage(MSG* pMsg)
{
     if(pMsg->message==WM_KEYDOWN)
     {
        DEBUG(_T("WM_KEYDOWN"));
        ...
        OnKey();
        ...
     }	
     return CDialog::PreTranslateMessage(pMsg);
}

Now in a particular Dialog I override the virtual
OnKey() function and execute whatever should happen
in that Dialog on a particular keystroke.

Works like charm! Now I have also a CButton handler
which creates a worker thread:

void MyDialog::OnButton()
{
   delete worker;
   worker = new Worker();
}

As soon as the worker thread is alive, I no longer
get the WM_KEYDOWN messages in PreTranslateMessage()

I don't get it - where is the connection?
Anyone an idea?
--
Torsten

0
tcurdt (13)
2/6/2004 12:16:45 AM
vc.mfc 33608 articles. 0 followers. Follow

0 Replies
984 Views

Similar Articles

[PageSpeed] 22

Reply:

Similar Artilces:

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

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

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

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

Strange PreTranslateMessage Behavior
Hi: I have a vc++ 6.0 dialog-based application where I'm using PreTranslateMessage to send keyboard characters out the serial port with the following code: BOOL CMyDlg::PreTranslateMessage(MSG* pMsg) { if (pMsg->message == WM_CHAR ) { WPARAM wp = pMsg->wParam; char by = (char) wp; char *p_cs; p_cs = &by; pSPort->WriteData( p_cs, 1 ); } return CDialog::PreTranslateMessage(pMsg); } I also have a couple of buttons that perform some functions and are enabled and/or disabled after the functions are complete. Stripped of all irrelevant code these functions are: v...

no more PreTranslateMessage
All my Dialogs are derived from AbstractDialog. This AbstractDialog overrides PreTanslateMessage so I can catch keystrokes in all my Dialogs. BOOL AbstractDialog::PreTranslateMessage(MSG* pMsg) { if(pMsg->message==WM_KEYDOWN) { DEBUG(_T("WM_KEYDOWN")); ... OnKey(); ... } return CDialog::PreTranslateMessage(pMsg); } Now in a particular Dialog I override the virtual OnKey() function and execute whatever should happen in that Dialog on a particular keystroke. Works like charm! Now I have also a CButton handler which creates a w...

PreTranslateMessage and Ctrl + A
Hello NG, how can I check in PreTranslateMessage, if the user has pressed Ctrl and A? if(pMsg->message==WM_KEYDOWN) { pMsg->wParam; //?? Ctrl+A ? pMsg->lParam; //?? Ctrl+A ? } Thanks for help, Guido On Wed, 25 Jul 2007 18:42:17 +0200, "Guido Franzke" <guidof73@yahoo.de> wrote: >Hello NG, > >how can I check in PreTranslateMessage, if the user has pressed Ctrl and A? > > if(pMsg->message==WM_KEYDOWN) > { > pMsg->wParam; //?? Ctrl+A ? > pMsg->lParam; //?? Ctrl+A ? > } > >Thanks ...

PreTranslateMessage question
I have an MFC application which is based on a modal CDialog. It contains a Picture control which is resized if the parent dialog size changes - this keeps the picture control occupying the full width of the CDialog's client area. The Picture Control is used to display video, but when the dialog box size is stretched it causes a lot of flickering because the Picture Control repeatedly redraws its background while also displaying the video. According to the documentation, I just have to trap WM_ERASEBKGND messages for the Picture Control to prevent it drawing its background. So I created ...

preTranslateMessage error
I'm learning how to use pretranslateMessage in c++ for an mfc app. but it keeps giving me two errors and I can't find a good tutorial on it. it says: PhysicsMath error LNK2005: "public: virtual int __thiscall CPhysicsMathDlg::PreTranslateMessage(struct tagMSG *)" (?PreTranslateMessage@CPhysicsMathDlg@@UAEHPAUtagMSG@@@Z) already defined in PhysicsMath.obj and PhysicsMath fatal error LNK1169: one or more multiply defined symbols found anyone know what it means? dave "Deej" <davidhere40@hotmail.com> wrote in message news:7sednROg4_wLPmmiRVn-jg@comcast.com.....

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

CFileDialog and PreTranslateMessage
Hello, I have a CFileDialog derived class. I want to handle the backspace key down in my derived class. I added PreTranslateMessage handler to my class but it never gets in there (Why?). What can I do in order to handle the Back_Space key down in my derived class? Thanks, Janiv Ratson. First of all you did not mention what control you want to receive notification when del key was pressed. Secondly you should not use PreTranslateMessage in this manner; it was not designed for that and it is a source of many problems that usually are not foreseen. You have to provide more detailed infor...

Keyboard Messages not intercepted when PreTranslateMessage is used
Hi Mine is a MFC ActiveX Ctrl. I am using PreTranslateMessage as follows so that keystrokes like backspace can be detected in IE, but though SendMessage gets called, the Keystrokes like Arrow keys, delete backspace don't function at all in ActiveX container as well as IE. Am I missing something or do I need to explicitly write WM_KEYDOWN (KEYUP) message handlers? Please let me know. BOOL CMegafleetPluginCtrl::PreTranslateMessage(MSG* pMsg) { switch (pMsg->message) { case WM_KEYDOWN: case WM_KEYUP: switch (pMsg->wParam) { c...

PreTranslateMessage in the DLL is not called
Hi there. I have a strange thing in my code. I have a class which is derived from CEdit. In that class there is a PreTranslateMessage method. It is called when I compile this class in the Exe. But it is not never called when I compile this class as a DLL and load it dynamically by LoadLibrary and use the class. Please do you have any ideas what is wrong there? What is the difference of using derived class as a exe or as a dll? Thanks! German Koninin Is it a Regular DLL? Is the CEdit derived object in a modeless dialog? --- Ajay German Koninin wrote: > Hi there. > I have a stra...

PreTranslateMessage and m_msgCur problem
I have noticed an odd problem in our DLL module. One of my CWnd-based classes overwrites PreTranslateMessage and checks for WM_KEYDOWN with VK_TAB. When this message comes, the code does some processing and shows a modal dialog box or property sheet. After the user closes the popup window, my PreTranslateMessage continues executing and it calls CWnd's PreTranslateMessage with the supplied pMsg. The problem is that the message passed to CWnd::PreTranslateMessage is not the same as the message that came in indicating that the module state's m_msgCur was changed during showing the...

CPropertySheet::PreTranslateMessage in VS2005
I have converted over my MFC application from VS2003 to VS2005. I was getting some inconsistent crashing due to a change made in the MFC library to the CPropertySheet::PreTranslateMessage method. Added to the method was the following code if (NULL == PropSheet_GetCurrentPageHwnd(m_hWnd)) { DestroyWindow(); return TRUE; } I think the code was added for modeless windows, but it caused my modal sheet to crash, because it was being destroyed behind my back. I overrode the method to work around it, but thought I would mention it if anyone else happened to have the problem. How...

WM_ERASEBGND not caught by CWinApp::PreTranslateMessage
Hi, I am having a problem with a handler for WM_ERASEBGND and wanted to intercept WM_ERASEBGND in an overriden CWinApp::PreTranslateMessage. However, for some reason, WM_ERASEBGND is NEVER received in PreTranslateMessage!! Am I doing something wrong? -- Thanks in advance, Juan Dent, M.Sc. Juan Dent wrote: > Hi, > > I am having a problem with a handler for WM_ERASEBGND and wanted to > intercept WM_ERASEBGND in an overriden CWinApp::PreTranslateMessage. > However, for some reason, WM_ERASEBGND is NEVER received in > PreTranslateMessage!! > Am I doing something wrong...

Strange PreTranslateMessage Behavior (2)
Hi: I have a vc++ 6.0 dialog-based application where I'm using PreTranslateMessage to send keyboard characters out the serial port with the following code (thank you, Joseph M. Newcomer): BOOL CMyDlg::PreTranslateMessage(MSG* pMsg) { if (pMsg->message == WM_CHAR ) { TCHAR ch = (TCHAR)pMsg->wParam; pSPort->WriteData(&ch, sizeof(TCHAR)); } return CDialog::PreTranslateMessage(pMsg); } I also have a couple of buttons that perform some functions and are enabled and/or disabled after the functions are complete. Stripped of all irrelevant code these functions are: voi...

Trapping Enter key in FormView of SDI -PreTranslateMessage
Hai I Have a Owner Drawn button in a FormView and on clicking on the EnterKey i need to make that Button to handle some thing and i have used PreTranslateMessage and can i use PreTranslateMessage in FormView and please let me know the details suresh If you want the clicking action to be in button, OnLButtonDown in your button should work. If you want to handle it in the form, PreTranslateMessage will work fine. -- Ajay Kalra [MVP - VC++] ajaykalra@yahoo.com "Suresh" <suresh_vcplusplus@hotmail.com> wrote in message news:#IW0FkGqEHA.1712@tk2msftngp13.ph...

PreTranslateMessage not called in modeless dialog
This is a really tricky one! Please read on ;) I have a dialog-based MFC application with a main window A which fires up a modeless dialog B exported by an MFC extension DLL. Now, when I press <TAB> to change focus, nothing happens and this is printed in the Output window: Warning: constructing COleException, scode = DISP_E_MEMBERNOTFOUND ($80020003). First-chance exception at 0x7c812a5b in MedSpeech.exe: Microsoft C++ exception: COleException @ 0x0012f8e0. This is due to GetNextDlgTabItem() returning NULL (winocc.cpp, line 536). Basically, none of the standard dialog keys are work...

PreTranslateMessage is called before data is changed.
I am tring to update my control while user edits label of CListCtrl. I implemented it and realized this handler is called before data of CEdit control is updated. How can I implement it after the edit control is updated? BOOL CMyDlg::PreTranslateMessage(MSG* pMsg) { if( pMsg->message != WM_KEYDOWN ) return CDialog::PreTranslateMessage(pMsg); CEdit *pEdit = m_listCtrl.GetEditControl(); if( pEdit ) { CString sText; pEdit->GetWindowText( sText ); //... UpdateData( FALSE ); } return CDialog::PreTranslateMessage(pMsg); } >I am tring to...

Debug ASSERT when CDialog::DoModal() from PreTranslateMessage()
I am creating and invoking a DialogBox within the PreTranslateMessage() hander of another DialogBox. If I comment out the DoModal() invocation, the exception is not thrown. If I leave it in, the Debug Assertion Failed! message appears. The ASSERT statement is located within MS Windows void CWnd::AssertValid(). What is going on here? What can I do to make it work correctly? "PeteOlcott" <PeteOlcott@gmail.com> wrote in message news:144afc43-847a-434a-b890-75eda4a10b6f@v17g2000hsa.googlegroups.com... >I am creating and invoking a DialogBox within the > PreTranslateMessage...

PreTranslateMessage wont work for CListBox in dynamically loaded DLL
Hi there. I have a DLL where I have a CDialog derived window where is CListBox derived class. On that class I override PreTranslateMessage. Ok. I load this library dynamicallyby in my application by calling LoadLibrary. And this damn PreTranslateMessage is not called at all! First I set a breakpoint there. But then tried to put a MessageBox inside this method since I was thinking that my debugger probably could be broken. Ok. The same CListBox derived class I use in the main application also and there PreTranslateMessage is working fine. Is there some known problems with deriving this ...

PreTranslateMessage getting called with wrong class type: ASSERT f
Hi there, I'm developing an MFC app and I have just added a PreTranslateMessage override to one of my views, to handle dialog messages like tabs since the view has child controls and I want to be able to use keyboard navigation. My problem is that one of the controls is a (custom) button which causes the view to change to another one, when I click the button I get an ASSERT failure in CWnd::IsChild, the failure is in ASSERT(IsWindow(m_hWnd); So, fair enough I thought, simply check in my PreTranslateMessage function that this->IsWindow(m_hWnd) before calling IsChild(pAnotherWindow). Ho...