Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Keeping focus on control
#1
In the example dialog which follows a certain part of the text in control 3 is selected. However,, if you click on button selection is lost. As a matter of fact I use this button in this example to simulate a series of actions in my actual problem.

I wonder whether the selection can be preserved, even after clicking on button.
Many thanks in advance.

Function Dialog43
Code:
Copy      Help
str dd=
;BEGIN DIALOG
;0 "" 0x90C80AC8 0x0 0 0 224 136 "Dialog"
;1 Button 0x54030001 0x4 116 116 48 14 "OK"
;2 Button 0x54030000 0x4 168 116 48 14 "Cancel"
;3 RichEdit20A 0x54233044 0x200 7 0 215 71 ""
;4 Button 0x54032000 0x0 9 77 48 14 "Button"
;END DIALOG
;DIALOG EDITOR: "" 0x2040308 "*" "" "" ""

str controls = "3"
str re3
if(!ShowDialog(dd &sub.DlgProc &controls)) ret


#sub DlgProc
function# hDlg message wParam lParam

sel message
,case WM_INITDIALOG
,_s="abcd efgh ijkl 12345 pqrst"
,_s.setwintext(id(3 hDlg))
,SendMessage(id(3 hDlg) EM_SETSEL 2 11)
,act id(3 hDlg)

,case WM_DESTROY
,case WM_COMMAND goto messages2
ret
;messages2
sel wParam
,case IDOK
,case IDCANCEL
ret 1
#2
Code:
Copy      Help
sel wParam
,case 4
,SetFocus id(3 hDlg)
#3
Suppose now that with button with id 4 a new window is generated, for example with a mes statement, ie :

Quote:mes "New window"

I wonder whether it is still possible to keep the focus in control 3.

Many thanks in advance.
#4
A workaround solution I have given is to include in the thread that launches the second window the following statements :

Quote: case WM_PAINT
int hwndOwner=GetParent(hDlg)
if WinTest(hwndOwner "#32770"); act hwndOwner

It works. However, I am wondering whether there exists a simpler solution.
#5
Macro Macro1074
Code:
Copy      Help
str dd=
;BEGIN DIALOG
;0 "" 0x90C80AC8 0x0 0 0 224 136 "Dialog"
;1 Button 0x54030001 0x4 116 116 48 14 "OK"
;2 Button 0x54030000 0x4 168 116 48 14 "Cancel"
;3 RichEdit20A 0x54233044 0x200 7 0 215 71 ""
;4 Button 0x54032000 0x0 9 77 48 14 "Button"
;END DIALOG
;DIALOG EDITOR: "" 0x2040308 "*" "" "" ""

str controls = "3"
str re3
if(!ShowDialog(dd &sub.DlgProc &controls)) ret


#sub DlgProc
function# hDlg message wParam lParam

sel message
,case WM_INITDIALOG
,_s="abcd efgh ijkl 12345 pqrst"
,_s.setwintext(id(3 hDlg))
,SendMessage(id(3 hDlg) EM_SETSEL 2 11)
,act id(3 hDlg)

,case WM_DESTROY
,case WM_COMMAND goto messages2
ret
;messages2
sel wParam
,case 4
,SetFocus id(3 hDlg)
,sub.Dialog2
ret 1

#sub Dialog2
function# [hwndOwner]

str dd=
;BEGIN DIALOG
;0 "" 0x90C80AC8 0x0 0 0 224 136 "Dialog"
;1 Button 0x54030001 0x4 116 116 48 14 "OK"
;2 Button 0x54030000 0x4 168 116 48 14 "Cancel"
;END DIALOG
;DIALOG EDITOR: "" 0x2040700 "*" "" "" ""

if(!ShowDialog(dd &sub.DlgProc2 0 hwndOwner 128 0 0 0 -1)) ret

ret 1


#sub DlgProc2
function# hDlg message wParam lParam

sel message
,case WM_INITDIALOG
,hid- hDlg
,case WM_DESTROY
,case WM_COMMAND goto messages2
ret
;messages2
sel wParam
,case IDOK
,case IDCANCEL
ret 1
#6
Many thanks for your advice !


Forum Jump:


Users browsing this thread: 1 Guest(s)