Click here to Skip to main content
15,891,567 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
Question[MFC] Creation of a new control class Pin
alitokmen11-Jul-06 6:09
alitokmen11-Jul-06 6:09 
AnswerRe: [MFC] Creation of a new control class Pin
Jun Du11-Jul-06 9:23
Jun Du11-Jul-06 9:23 
QuestionRe: [MFC] Creation of a new control class Pin
alitokmen11-Jul-06 9:43
alitokmen11-Jul-06 9:43 
AnswerRe: [MFC] Creation of a new control class Pin
PJ Arends11-Jul-06 10:46
professionalPJ Arends11-Jul-06 10:46 
AnswerRe: [MFC] Creation of a new control class Pin
ThatsAlok11-Jul-06 21:55
ThatsAlok11-Jul-06 21:55 
AnswerRe: [MFC] Creation of a new control class Pin
PJ Arends12-Jul-06 7:02
professionalPJ Arends12-Jul-06 7:02 
JokeRe: [MFC] Creation of a new control class Pin
alitokmen12-Jul-06 11:24
alitokmen12-Jul-06 11:24 
AnswerRe: [MFC] Creation of a new control class Pin
alitokmen12-Jul-06 6:33
alitokmen12-Jul-06 6:33 
OK, I've solved the issue... Here's how it goes:

Problem: when there's a control in a dialog box replacing a STATIC resource, it will lose focus as soon as a key is pressed (things move in the dialog box) and it will never receive the OnKeyDown call.

Reason: STATIC is not supposed to be doing input/output, as a result it cannot receive keyboard events. As a result, you won't receive the OnKeyDown call (even if you do put it in the message map) and any pressed key, since not captured by the STATIC, will get dispatched to the parent (the dialog box) and this will make it take the default action -changing the selected button.

Solution: in the class that wants to go into a STATIC, overload the PreTranslateMessage, OnLButtonDown and OnRButtonDown methods (you also need to specify the mouse actions in the message map). PreTranslateMessage shall check if( pMsg->message == WM_KEYDOWN ), and in this case call OnKeyDown followed by CWnd::PreTranslateMessage and return TRUE (so the message doesn't get dispatched). If not, it shall return whatever CWnd::PreTranslateMessage returns. In the mouse handling methods, call SetFocus to get the focus when clicked.

New problem: the call you do to OnKeyDown is ignored (in classes that inherit from our base class, at least).

Reason: Don't know why...

Solution: Create a new virtual OnKeyDown method which would have a different signature from the original method (for example, one that only takes the nChar argument) and call that one. Now, put the key handling stuff in that new OnKeyDown method.

The solution therefore doesn't require you to overload CDialog::PreTranslateMessage or do other things like that. Note that the modification done to PreTranslateMessage is also very small, which makes that the overall behaviour of the control as well as the dialog box remains the same...

S. Ali Tokmen
http://ali.tokmen.com
GeneralOLE process still using directory after releasing handler Pin
hairy_hats11-Jul-06 5:37
hairy_hats11-Jul-06 5:37 
QuestionDisplaying Bitmap on a button [modified] Pin
safigh11-Jul-06 5:20
safigh11-Jul-06 5:20 
AnswerRe: Displaying Bitmap on a button [modified] Pin
led mike11-Jul-06 5:28
led mike11-Jul-06 5:28 
GeneralRe: Displaying Bitmap on a button Pin
safigh11-Jul-06 5:36
safigh11-Jul-06 5:36 
AnswerRe: Displaying Bitmap on a button [modified] Pin
ldaoust11-Jul-06 5:34
ldaoust11-Jul-06 5:34 
AnswerRe: Displaying Bitmap on a button Pin
David Crow11-Jul-06 6:17
David Crow11-Jul-06 6:17 
QuestionHow to add webbrowser controle to visual c++ 6 MFC project Pin
method00711-Jul-06 5:12
method00711-Jul-06 5:12 
AnswerRe: How to add webbrowser controle to visual c++ 6 MFC project Pin
led mike11-Jul-06 5:25
led mike11-Jul-06 5:25 
GeneralRe: How to add webbrowser controle to visual c++ 6 MFC project Pin
method00711-Jul-06 6:03
method00711-Jul-06 6:03 
GeneralRe: How to add webbrowser controle to visual c++ 6 MFC project Pin
led mike11-Jul-06 6:47
led mike11-Jul-06 6:47 
GeneralRe: How to add webbrowser controle to visual c++ 6 MFC project Pin
method00711-Jul-06 7:17
method00711-Jul-06 7:17 
GeneralRe: How to add webbrowser controle to visual c++ 6 MFC project Pin
led mike11-Jul-06 8:50
led mike11-Jul-06 8:50 
QuestionRe: How to add webbrowser controle to visual c++ 6 MFC project Pin
David Crow11-Jul-06 6:16
David Crow11-Jul-06 6:16 
AnswerRe: How to add webbrowser controle to visual c++ 6 MFC project Pin
method00711-Jul-06 6:18
method00711-Jul-06 6:18 
GeneralRe: How to add webbrowser controle to visual c++ 6 MFC project Pin
David Crow11-Jul-06 6:56
David Crow11-Jul-06 6:56 
GeneralRe: How to add webbrowser controle to visual c++ 6 MFC project Pin
method00711-Jul-06 7:22
method00711-Jul-06 7:22 
GeneralRe: How to add webbrowser controle to visual c++ 6 MFC project Pin
David Crow11-Jul-06 7:53
David Crow11-Jul-06 7:53 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.