Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
getwintext in dialog on Return instead of close dialog
#1
Hi Gintaras,

In short, I have made a dialog like the google toolbar but with multiple entry zones and want return to act on whichever entry field was last entered into or has cursor blinking in it (activated).

I think I have struggled with this before and never quite got a handle on it:

I have an editable combobox or edit field in a dialog which I want to grab the text from when the user hits return, presumably right after they have activated it to enter text. When they are finished entering text, they hit return to act on that text (a search box for example like in Google toolbar).
Function Dialog2
Code:
Copy      Help
\Dialog_Editor

function# hDlg message wParam lParam
if(hDlg) goto messages

;BEGIN DIALOG
;0 "" 0x90C80AC8 0x0 0 0 223 135 "Dialog"
;1 Button 0x54030001 0x4 120 116 48 14 "OK"
;2 Button 0x54030000 0x4 170 116 48 14 "Cancel"
;3 Edit 0x54031000 0x200 12 20 90 16 ""
;4 Edit 0x54031000 0x200 12 40 90 16 ""
;END DIALOG
;DIALOG EDITOR: "" 0x2030109 "" "" ""

str controls = "3 4"
str e3 e4
if(!ShowDialog("Dialog2" &Dialog2 &controls)) ret


ret
;messages
sel message
,case WM_INITDIALOG
,case WM_DESTROY
,case WM_COMMAND goto messages2
,
,case WM_SETCURSOR
,,int+ FieldSelected = 0
,,if wParam = id(3 hDlg); FieldSelected = 3
,,if wParam = id(4 hDlg); FieldSelected = 4

,
ret
;messages2
sel wParam
,case IDOK
,,if FieldSelected = 3
,,,str Field3Text.getwintext(id(3 hDlg))
,,,OnScreenDisplay Field3Text 1
,,,ret
,,if FieldSelected = 4
,,,str Field4Text.getwintext(id(4 hDlg))
,,,OnScreenDisplay Field4Text 1
,,,ret
,case IDCANCEL
ret 1

There can be more than one field to act from, depending on which was last activated (see example above).

It confuses me that sometimes when user hit return after filling field 3 or 4, it works to just perform the OSD, without closing the dialog and sometimes it also closes the dialog.

I want it not to close the dialog.

Changing it to non-modal dialog (flag 1) doesn't seem to work.

I haven't yet tried making this a hook dialog function on a toolbar but maybe that is the way to go.



Thanks!!!
Stuart
#2
WM_SETCURSOR - on mouse move and click.

----------------

Function Dialog210
Code:
Copy      Help
\Dialog_Editor

function# hDlg message wParam lParam
if(hDlg) goto messages

;BEGIN DIALOG
;0 "" 0x90C80AC8 0x0 0 0 223 135 "Dialog"
;1 Button 0x54030001 0x4 120 116 48 14 "OK"
;2 Button 0x54030000 0x4 170 116 48 14 "Cancel"
;3 Edit 0x54031000 0x200 12 20 90 16 ""
;4 ComboBox 0x54230242 0x0 12 42 96 213 ""
;END DIALOG
;DIALOG EDITOR: "" 0x2030109 "" "" ""

str controls = "3 4"
str e3 e4
if(!ShowDialog("" &Dialog210 &controls)) ret


ret
;messages
sel message
,case WM_INITDIALOG
,case WM_DESTROY
,case WM_COMMAND goto messages2
ret
;messages2
sel wParam
,case IDOK
,int h=GetFocus; if(!h or h=hDlg) ret
,int hh=GetParent(h); if(hh!=hDlg) h=hh ;;combo
,str s
,sel GetWinId(h)
,,case [3,4]
,,s.getwintext(h)
,,OnScreenDisplay s 1
,,ret
,case IDCANCEL
ret 1

or

Function Dialog85
Code:
Copy      Help
\Dialog_Editor

function# hDlg message wParam lParam
if(hDlg) goto messages

;BEGIN DIALOG
;0 "" 0x90C80AC8 0x0 0 0 223 135 "Dialog"
;1 Button 0x54030001 0x4 120 116 48 14 "OK"
;2 Button 0x54030000 0x4 170 116 48 14 "Cancel"
;3 Edit 0x54031000 0x200 12 20 90 16 ""
;4 ComboBox 0x54230242 0x0 12 42 96 213 ""
;END DIALOG
;DIALOG EDITOR: "" 0x2030109 "" "" ""

str controls = "3 4"
str e3 e4
if(!ShowDialog("" &Dialog85 &controls)) ret


ret
;messages
sel message
,case WM_INITDIALOG
,int-- FieldSelected
,FieldSelected=0
,case WM_DESTROY
,case WM_COMMAND goto messages2
ret
;messages2
sel wParam
,case [EN_SETFOCUS<<16|3,CBN_SETFOCUS<<16|4]
,FieldSelected=GetWinId(lParam)
,case IDOK
,str s
,sel FieldSelected
,,case [3,4]
,,s.getwintext(id(FieldSelected hDlg))
,,OnScreenDisplay s 1
,,ret
,case IDCANCEL
ret 1

-----------

nonmodal
Function Dialog86
Code:
Copy      Help
\Dialog_Editor

function# hDlg message wParam lParam
if(hDlg) goto messages

;BEGIN DIALOG
;0 "" 0x90C80AC8 0x0 0 0 223 135 "Dialog"
;1 Button 0x54030001 0x4 120 116 48 14 "OK"
;2 Button 0x54030000 0x4 170 116 48 14 "Cancel"
;3 Edit 0x54031000 0x200 12 20 90 16 ""
;4 ComboBox 0x54230242 0x0 12 42 96 213 ""
;END DIALOG
;DIALOG EDITOR: "" 0x2030109 "" "" ""

str controls = "3 4"
str e3 e4
hDlg=ShowDialog("" &Dialog86 &controls 0 1)
MessageLoop 2

ret
;messages
sel message
,case WM_INITDIALOG
,int-- FieldSelected
,FieldSelected=0
,case WM_DESTROY
,PostThreadMessage GetCurrentThreadId 2000 0 0
,case WM_COMMAND goto messages2
ret
;messages2
sel wParam
,case [EN_SETFOCUS<<16|3,CBN_SETFOCUS<<16|4]
,FieldSelected=GetWinId(lParam)
,case IDOK
,str s
,sel FieldSelected
,,case [3,4]
,,s.getwintext(id(FieldSelected hDlg))
,,OnScreenDisplay s 1
,,ret
,case IDCANCEL
ret 1
#3
beautiful!!!!!!
amazing!!!
Thanks!!!!
Stuart


Forum Jump:


Users browsing this thread: 1 Guest(s)