Posts: 1,036
Threads: 246
Joined: Jul 2022
Hi,
I want to achieve an effect where the text inside the edit box is selected while the edit box is in focus
How to use the following code?
PostMessage(EM_SETSEL, 0, -1)
Thanks in advance for any advice and help
david
Macro Macro3
str dd=
;BEGIN DIALOG
;0 "" 0x90C80AC8 0x0 0 0 224 136 "Dialog" "4"
;3 Edit 0x54020080 0x200 16 24 96 12 ""
;4 Edit 0x54020080 0x200 16 48 96 12 ""
;5 Edit 0x54020080 0x200 16 72 96 12 ""
;1 Button 0x54030001 0x4 116 116 48 14 "OK"
;2 Button 0x54030000 0x4 168 116 48 14 "Cancel"
;END DIALOG
;DIALOG EDITOR: "" 0x2040C02 "*" "" "" ""
str controls = "3 4 5"
str e3 e4 e5
e3="hello"
e4="world"
e5="hello"
if(!ShowDialog(dd &sub.DlgProc &controls)) ret
#sub DlgProc
function# hDlg message wParam lParam
sel message
,case WM_INITDIALOG
,case WM_DESTROY
,case WM_COMMAND goto messages2
ret
;messages2
sel wParam
,case IDOK
,case IDCANCEL
ret 1
Posts: 1,336
Threads: 61
Joined: Jul 2006
str dd=
;BEGIN DIALOG
;0 "" 0x90C80AC8 0x0 0 0 224 136 "Dialog" "4"
;3 Edit 0x54020080 0x200 16 24 96 12 ""
;4 Edit 0x54020080 0x200 16 48 96 12 ""
;5 Edit 0x54020080 0x200 16 72 96 12 ""
;1 Button 0x54030001 0x4 116 116 48 14 "OK"
;2 Button 0x54030000 0x4 168 116 48 14 "Cancel"
;END DIALOG
;DIALOG EDITOR: "" 0x2040C02 "*" "" "" ""
str controls = "3 4 5"
str e3 e4 e5
e3="hello"
e4="world"
e5="hello"
if(!ShowDialog(dd &sub.DlgProc &controls)) ret
#sub DlgProc
function# hDlg message wParam lParam
sel message
,case WM_INITDIALOG
,case WM_DESTROY
,case WM_COMMAND goto messages2
ret
;messages2
sel wParam
,case IDOK
,case IDCANCEL
,case else
,int loword=wParam&0xFFFF
,int hiword=wParam>>16
,sel hiword
,,case EN_SETFOCUS
,,PostMessage(lParam EM_SETSEL, 0, -1)
ret 1
Posts: 1,036
Threads: 246
Joined: Jul 2022
It works well, thank you so much!
Posts: 1,036
Threads: 246
Joined: Jul 2022
If the text is too long, only the text before the insertion point is selected
Posts: 1,336
Threads: 61
Joined: Jul 2006
I am not sure what you mean. all text is selected when controls gets focus
Posts: 1,036
Threads: 246
Joined: Jul 2022
02-03-2023, 01:45 AM
(This post was last modified: 02-03-2023, 02:32 AM by Davider.)
Click in the edit box to bring it into focus
Demo:
https://download.ru/g/3uN0sBgk/GRSQorVNI...1675648069
Macro Macro1
str dd=
;BEGIN DIALOG
;0 "" 0x90C80AC8 0x0 0 0 224 136 "Dialog" "4"
;3 Edit 0x54020080 0x200 16 24 96 12 ""
;4 Edit 0x54020080 0x200 16 48 96 12 ""
;5 Edit 0x54020080 0x200 16 72 96 12 ""
;1 Button 0x54030001 0x4 116 116 48 14 "OK"
;2 Button 0x54030000 0x4 168 116 48 14 "Cancel"
;END DIALOG
;DIALOG EDITOR: "" 0x2040C02 "*" "" "" ""
str controls = "3 4 5"
str e3 e4 e5
e3="hello world hello world hello world"
e4="world"
e5="hello"
if(!ShowDialog(dd &sub.DlgProc &controls)) ret
#sub DlgProc
function# hDlg message wParam lParam
sel message
,case WM_INITDIALOG
,case WM_DESTROY
,case WM_COMMAND goto messages2
ret
;messages2
sel wParam
,case IDOK
,case IDCANCEL
,case else
,int loword=wParam&0xFFFF
,int hiword=wParam>>16
,sel hiword
,,case EN_SETFOCUS
,,PostMessage(lParam EM_SETSEL, 0, -1)
ret 1
Posts: 1,036
Threads: 246
Joined: Jul 2022
02-04-2023, 11:26 PM
(This post was last modified: 02-04-2023, 11:26 PM by Davider.)
@ Kevin
I also found a problem:
I added the EM_SETCUEBANNER code, but the first edit box is not displayed by default, need to move the mouse pointer to display, is there a solution?
demo Gif:
https://download.ru/g/mttFLmSS/3tGl645iz...1675812332
Macro Macro5
str dd=
;BEGIN DIALOG
;0 "" 0x90C80AC8 0x0 0 0 224 136 "Dialog" "4"
;3 Edit 0x54030080 0x200 16 16 96 12 ""
;4 Edit 0x54030080 0x200 16 40 96 12 ""
;5 Edit 0x54030080 0x200 16 64 96 12 ""
;1 Button 0x54030001 0x4 116 116 48 14 "OK"
;2 Button 0x54030000 0x4 168 116 48 14 "Cancel"
;END DIALOG
;DIALOG EDITOR: "" 0x2040C02 "*" "" "" ""
str controls = "3 4 5"
str e3 e4 e5
if(!ShowDialog(dd &sub.DlgProc &controls)) ret
#sub DlgProc
function# hDlg message wParam lParam
sel message
,case WM_INITDIALOG
,SendMessage id(3 hDlg) EM_SETCUEBANNER 1 @"input name"
,SendMessage id(4 hDlg) EM_SETCUEBANNER 1 @"input file name"
,SendMessage id(5 hDlg) EM_SETCUEBANNER 1 @"input folder name"
,case WM_DESTROY
,case WM_COMMAND goto messages2
ret
;messages2
sel wParam
,case IDOK
,case IDCANCEL
,case else
,int loword=wParam&0xFFFF
,int hiword=wParam>>16
,sel hiword
,,case EN_SETFOCUS PostMessage(lParam EM_SETSEL, 0, -1)
ret 1
Posts: 1,336
Threads: 61
Joined: Jul 2006
not having that problem on win10
Posts: 1,036
Threads: 246
Joined: Jul 2022
kevin,
I tested the win7 win10 win11 system version. I must add the following code to always select the text
Is there a better solution? thank you.
,case EN_SETFOCUS<<16|3
,'E
,0.5
,PostMessage(lParam EM_SETSEL 0 -1)
Macro Macro20
str dd=
;BEGIN DIALOG
;0 "" 0x90CC0AC8 0x0 0 0 224 136 "Dialog" "4"
;3 Edit 0x54030080 0x200 16 16 96 12 ""
;4 Edit 0x54030080 0x200 16 40 96 12 ""
;1 Button 0x54030001 0x4 116 116 48 14 "OK"
;2 Button 0x54030000 0x4 168 116 48 14 "Cancel"
;END DIALOG
;DIALOG EDITOR: "" 0x2040C02 "*" "" "" ""
str controls = "3 4"
str e3 e4
e3=
;hello world hello world hello world hello world
e4=e3
if(!ShowDialog(dd &sub.DlgProc &controls)) ret
#sub DlgProc
function# hDlg message wParam lParam
sel message
,case WM_INITDIALOG
,DT_SetAutoSizeControls hDlg "3sh 4sh"
,case WM_DESTROY
,case WM_COMMAND goto messages2
ret
;messages2
sel wParam
,case IDOK
,case IDCANCEL
,case EN_SETFOCUS<<16|3
,'E
,0.5
,PostMessage(lParam EM_SETSEL 0 -1)
,
,case EN_SETFOCUS<<16|4
,'E
,0.5
,PostMessage(lParam EM_SETSEL 0 -1)
,
ret 1
|