The MASM Forum Archive 2004 to 2012

General Forums => The Campus => Topic started by: Mr Earl on March 09, 2005, 12:17:36 PM

Title: edit control displays "selected"
Post by: Mr Earl on March 09, 2005, 12:17:36 PM
What causes a multiline edit control to display as "selected" on it's initial display?
I fill the control with "SetWindowText" in the WM_INITDIALOG process.
Issuing a "EM_SETSEL" to de-select it does not work.  Only a click on the screen de-selects it.
I have used exactly the same style dialog in another application and the data did not display "selected"?


InvDisplayDialog DIALOG 0, 0, 329, 280
STYLE 0x0004 | DS_CENTER | WS_CAPTION | WS_MINIMIZEBOX |
WS_SYSMENU | WS_VISIBLE | WS_OVERLAPPED | DS_MODALFRAME | DS_SETFONT
FONT  9, "Tahoma"
CAPTION "Details"

BEGIN
  GROUPBOX "",1000,                   4,  0, 320,259
  EDITTEXT IDC_DETAILS,              12, 10, 305,243, ES_WANTRETURN|ES_MULTILINE|ES_AUTOVSCROLL|WS_VSCROLL
  PUSHBUTTON "Write Tag",IDC_WRITE,  99,262,  55, 14
  PUSHBUTTON "Exit",     IDC_EXIT,  174,262,  55, 14
  END

Title: Re: edit control displays "selected"
Post by: Tedd on March 09, 2005, 12:44:03 PM
Usually, you have to set the selection on WM_SETFOCUS to get that effect.
I don't know how it is done by default :eek
Title: Re: edit control displays "selected"
Post by: Mr Earl on March 09, 2005, 01:51:08 PM
I still don't know why the control displays "selected", but the only way I could get it to display normal was to add a DUMMY control


BEGIN
  GROUPBOX "",1000,                   4,  0, 320,259
  EDITTEXT IDC_DUMMY,                12, 10,   0,  0, ES_READONLY
  EDITTEXT IDC_DETAILS,              12, 10, 305,243, ES_WANTRETURN|ES_MULTILINE|ES_AUTOVSCROLL|WS_VSCROLL
  PUSHBUTTON "Write Tag",IDC_WRITE,  99,262,  55, 14
  PUSHBUTTON "Exit",     IDC_EXIT,  174,262,  55, 14
END
Title: Re: edit control displays "selected"
Post by: Relvinian on March 09, 2005, 04:06:34 PM
Mr. Earl

If you have a single control on your dialog, by default it'll have the "focus" so you'll see the selected state when the dialog shows. If you don't want this to happen, what needs to happen is the follow:

1) On your WM_INITDIALOG handler, set the focus to the dialog if only a single control -- or another control you want.
2) return TRUE from this handler as to instruct Windows that you have set the focus to something else.

Hope this helps

Relvinian
Title: Re: edit control displays "selected"
Post by: Mr Earl on March 09, 2005, 04:52:29 PM
Thanks Relvinian, your suggestion worked.  I still wonder why my de-select didn't work.
Anything wrong with this:    INVOKE SendMessage,hDetails,EM_SETSEL,-1,0
Title: Re: edit control displays "selected"
Post by: Relvinian on March 09, 2005, 05:33:10 PM
Where were you doing the call at?  If it was in WM_INITDIALOG, I am assuming the DefWinProc was doing something to reset focus back to the control.

Relvinian
Title: Re: edit control displays "selected"
Post by: mariø on March 10, 2005, 12:51:15 PM
Changing the order (first the pushbutton, for example), should work I think 

BEGIN
  GROUPBOX "",1000,                   4,  0, 320,259
  PUSHBUTTON "Write Tag",IDC_WRITE,  99,262,  55, 14
  EDITTEXT IDC_DETAILS,              12, 10, 305,243, ES_WANTRETURN|ES_MULTILINE|ES_AUTOVSCROLL|WS_VSCROLL
  PUSHBUTTON "Exit",     IDC_EXIT,  174,262,  55, 14
END