Click here to Skip to main content
15,921,779 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
AnswerRe: how to size an app to fit a PC's display size Pin
Ryan Binns10-Jun-03 4:35
Ryan Binns10-Jun-03 4:35 
GeneralRe: how to size an app to fit a PC's display size Pin
johnstonsk10-Jun-03 7:43
johnstonsk10-Jun-03 7:43 
GeneralOleCreateFromFile Pin
Florin Ochiana10-Jun-03 3:56
Florin Ochiana10-Jun-03 3:56 
GeneralCRichEditCtrl FormatRange Bounding Rectangle Pin
Larry J. Siddens10-Jun-03 3:48
Larry J. Siddens10-Jun-03 3:48 
GeneralRe: CRichEditCtrl FormatRange Bounding Rectangle Pin
Larry J. Siddens11-Jun-03 2:36
Larry J. Siddens11-Jun-03 2:36 
GeneralCatch the "enter" Pin
Woltan10-Jun-03 3:34
Woltan10-Jun-03 3:34 
GeneralRe: Catch the "enter" Pin
Maximilien10-Jun-03 3:44
Maximilien10-Jun-03 3:44 
GeneralRe: Catch the "enter" Pin
Mike Dimmick10-Jun-03 6:12
Mike Dimmick10-Jun-03 6:12 
PreTranslateMessage is a big hammer that gets recommended probably too often. It's also not too easy to write - it tends to end up as spaghetti code.

When you have a dialog box, you first ask the dialog box if it wants to handle messages, by calling ::IsDialogMessage() for a modeless dialog. This is done automatically by the modal message loop for a modal dialog. MFC 'modal' dialogs are in fact modeless Win32 dialogs - you can see this in CDialog::DoModal(). CDialog::PreTranslateMessage() calls ::IsDialogMessage() for you.

When you press certain keys (TAB, Enter, Escape) ::IsDialogMessage() performs the operation you requested and returns FALSE so that the message isn't dispatched by TranslateMessage()/DispatchMessage().

In order to allow the controls to override this behaviour, ::IsDialogMessage() sends a WM_GETDLGCODE message to the control with the focus. You can handle this message in a subclass window procedure in order to catch the return key - from memory, you should call the original window procedure, OR in the DLGC_WANTMESSAGE flag and handle the message directly in the WM_GETDLGCODE handler.

This has two advantages: this behaviour works in a standard Win32 app (no MFC) without having to add a lot of extra plumbing, and for MFC apps, you can create a class derived from CEdit that has this behaviour and reuse that class elsewhere.

The built-in MFC OnGetDlgCode() handler isn't very helpful for DLGC_WANTMESSAGE, because it doesn't allow access to lParam (which points to the MSG structure). To handle this properly, don't use the ON_WM_GETDLGCODE() message map entry - use ON_MESSAGE, as defined in MFC Technical Note 6 (look for TN006 in the MSDN Library index).

--
Mike Dimmick

GeneralRe: Catch the "enter" Pin
Florin Ochiana10-Jun-03 4:15
Florin Ochiana10-Jun-03 4:15 
Generalget_innerText Pin
Majid Shahabfar10-Jun-03 3:26
Majid Shahabfar10-Jun-03 3:26 
GeneralRe: get_innerText Pin
David Crow10-Jun-03 6:58
David Crow10-Jun-03 6:58 
General#define macro expansions Pin
David Chamberlain10-Jun-03 3:06
David Chamberlain10-Jun-03 3:06 
GeneralRe: #define macro expansions Pin
basementman10-Jun-03 3:55
basementman10-Jun-03 3:55 
GeneralRe: #define macro expansions Pin
David Chamberlain10-Jun-03 4:36
David Chamberlain10-Jun-03 4:36 
GeneralRe: #define macro expansions Pin
Peter Weyzen10-Jun-03 20:26
Peter Weyzen10-Jun-03 20:26 
GeneralRe: #define macro expansions Pin
Iain Clarke, Warrior Programmer10-Jun-03 4:03
Iain Clarke, Warrior Programmer10-Jun-03 4:03 
GeneralIntersecting windows Pin
pankajdaga10-Jun-03 3:02
pankajdaga10-Jun-03 3:02 
GeneralRe: Intersecting windows Pin
basementman10-Jun-03 3:59
basementman10-Jun-03 3:59 
GeneralDo a shift+Tab in PreTranslateMessage() Pin
Claude Gagnon10-Jun-03 3:00
Claude Gagnon10-Jun-03 3:00 
GeneralRe: Do a shift+Tab in PreTranslateMessage() Pin
Ryan Binns10-Jun-03 4:14
Ryan Binns10-Jun-03 4:14 
GeneralRe: Do a shift+Tab in PreTranslateMessage() Pin
valikac10-Jun-03 7:04
valikac10-Jun-03 7:04 
GeneralMoving text Pin
Dennis L10-Jun-03 2:39
Dennis L10-Jun-03 2:39 
GeneralRe: Moving text Pin
Iain Clarke, Warrior Programmer10-Jun-03 3:15
Iain Clarke, Warrior Programmer10-Jun-03 3:15 
GeneralCodewarrior dynamically creation Pin
DuFunk10-Jun-03 2:30
DuFunk10-Jun-03 2:30 
GeneralRe: Codewarrior dynamically creation Pin
Maximilien10-Jun-03 2:39
Maximilien10-Jun-03 2:39 

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.