I have a dialog that contains a multiline edit control. The dialog is initially invisible. After the edit control is populated with some text, I call ShowWindow(Dialog,SW_SHOW) to show the dialog. If the dialog has an owner, the edit control receives an EM_SETSEL message during the call to ShowWindow. Does anyone know why the edit control receives an EM_SETSEL? Is there any way to stop it? Thanks a lot. David Liebtag PS Here is the sequence of messages that the dialog and edit control receive during the call to ShowWindow: Dialog WM_SHOWWINDOW Dialog WM_NCACTIVATE Dialog WM_ACTIVATE Dialog WM_WINDOWPOSCHANGING Dialog WM_NCACTIVATE Dialog WM_ACTIVATE Dialog WM_IME_SETCONTEXT Dialog WM_IME_NOTIFY Dialog WM_SETFOCUS Edit WM_GETDLGCODE Edit EM_SETSEL wParam: 0 lParam: 2147483647 Dialog WM_KILLFOCUS Dialog WM_IME_SETCONTEXT Edit WM_IME_SETCONTEXT Edit WM_SETFOCUS Dialog DM_GETDEFID Dialog WM_COMMAND Dialog WM_WINDOWPOSCHANGING Dialog WM_NCPAINT Dialog WM_ERASEBKGND Dialog WM_WINDOWPOSCHANGED Dialog WM_NCCALCSIZE Dialog WM_NCPAINT Dialog WM_ERASEBKGND Dialog WM_NCPAINT Dialog WM_ERASEBKGND Note: 2147483647 is 0x7FFFFFFF. This causes the edit control's entire text to be selected.
>If the dialog has an owner, the edit control receives an EM_SETSEL message >during the call to ShowWindow. ... and if it doesn't have an owner? >Does anyone know why the edit control receives an EM_SETSEL? Is the edit control the first (tab order) control on the dialog? i.e. is it the expected normal behaviour that you'd get for any edit control that's on a dialog box and is getting the focus? Dave
If it doesn't have an owner, it does not receive an EM_SETSEL. It does not happen if the edit control is not the first visible enabled control that accepts input. But, default behavior is for the first control get get focus. Does the first control's selection gets changed too? Is that behavior documented somewhere? Why would the behavior depend on whether the dialog has an owner? David
>But, default behavior is for the first control get get focus. Does the >first control's selection gets changed too? Yes, default behaviour for Windows SDK applications is to select the whole contents. VB(6) applications have always differed from the norm. >Is that behavior documented somewhere? It's mentioned in the WM_NEXTDLGCTL message documentation: "This message performs additional dialog box management operations beyond those performed by the SetFocus function WM_NEXTDLGCTL updates the default pushbutton border, sets the default control identifier, and automatically selects the text of an edit control (if the target window is an edit control)." >Why would the behavior depend on whether the dialog has an owner? I don't know, that's what surprised me when you mentioned it, which is why I asked to check it was relevant. Dave
Huh. I knew that WM_NEXTDLGCTL updates button borders, but I never noticed that it also selects the text of edit controls. Thanks. David Liebtag
I just realized,,, the dialog does not receive WM_NEXTDLGCTL. David Liebtag
You can make it so the edit box doesn't get selected when it gets focus if you subclass it and make it to not return DLGC_HASSETSEL on WM_GETDLGCODE. Ivo David Liebtag wrote: > I just realized,,, the dialog does not receive WM_NEXTDLGCTL. > > David Liebtag > >