Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Need some help with Dialog
#1
I would like some help with the following Dialog. The TRANSFER button is supposed to copy all text from the edit box, performing an ALT+TAB to switch to the underlying application and then paste the text into that application. After that the dialog has to close. 
I tried to put focus to the edit section, but that didn't work. The only part that does work is the ALT+TAB command:

Function SIMPLE TEXT-BOX 
Code:
Copy      Help
str dd=
;BEGIN DIALOG
;0 "" 0x90C80AC8 0x0 0 0 224 136 "Dialog"
;3 Edit 0x54231044 0x200 16 8 188 96 ""
;4 Button 0x54032000 0x0 108 116 48 14 "TRANSFER"
;2 Button 0x54030000 0x4 168 116 48 14 "Cancel"
;END DIALOG
;DIALOG EDITOR: "" 0x2040700 "*" "" "" ""

str controls = "3"
str e3
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
,ret
,case IDCANCEL

,case 4 ;;TRANSFER
;Now the edit box needs to get focus.

,key Ca          ;; Ctrl+A (selecting all text in the edit box)
,key Cc          ;; Ctrl+C (copy)
,key AT          ;; Alt+Tab (switch to the active application, so far this is the only thing that works).
,1
,key Cv          ;; Ctrl+V (pasting the text)
,
;After performing the above actions the Dialog has to close.

ret 1
#2
Code:
Copy      Help
,case 4 ;;TRANSFER
,str txt.getwintext(id(3 hDlg)) ;;editable text
,;txt.setclip;; this will copy text to clipboard uncomment if needed but more than likely dont need to even use clipboard
,;get window handle and just do this instead example with notepad
,int w=win("Untitled - Notepad" "Notepad")
,int c=id(15 w) ;;editable text 'Text Editor'
,txt.setwintext(c)
;After performing the above actions the Dialog has to close.
,DT_Ok(hDlg)

Depending on the application your trying to put text into will determine which course of action to take let us know
#3
Quote:After that the dialog has to close.

Macro Macro3031
Code:
Copy      Help
str dd=
;BEGIN DIALOG
;0 "" 0x90C80AC8 0x0 0 0 224 136 "Dialog"
;3 Edit 0x54231044 0x200 16 8 188 96 ""
;1 Button 0x54032000 0x0 108 116 48 14 "TRANSFER"
;2 Button 0x54030000 0x4 168 116 48 14 "Cancel"
;END DIALOG
;DIALOG EDITOR: "" 0x2040700 "*" "" "" ""

str controls = "3"
str e3
if(!ShowDialog(dd 0 &controls)) ret
paste e3
#4
Much better!

Kevin, thanks for pointing out the text.getwintext and text.setclip options. I always have a tendency to use Send Keys for this kind of thing but that clearly isn't the best solution. I've changed it to the following (for this, however I had to add Send Keys) so that it works in every active window:

Code:
Copy      Help
case 4 ;;TRANSFER
,str txt.getwintext(id(3 hDlg)) ;;editable text
,txt.setclip
,,,key AT          ;; Alt+Tab
,,,0.2
,,,key Cv          ;; Ctrl+V
,,,
;After performing the above actions the Dialog has to close.
,DT_Ok(hDlg)
,

But now for some reason the Cancel button doesn't respond anymore......


Gintaras, what a clean solution! Unbelievable that all of this can be done with so few lines of code.
This method apparently doesn't use the clipboard? As I noticed that original clipboard contents was maintained. This comes in very handy for a non-clipboard version.

Two additional questions:

I noticed that with some target applications (Chrome for instance) there can be misfiring with the box (target application loses focus). Is there any way of "locking" the box to the last window or control that had focus (without specifying any specific application or window because the box needs to work with any application)?

Also, I would like to assign the following part: 

Code:
Copy      Help
str txt.getwintext(id(3 hDlg)) ;;editable text
,txt.setclip
to the Cancel button as well as to the dialogue itself. So that the users input will always be stored in case of accidental closing or misfiring. But this code gets rejected if I try to attach it to the Cancel button ( or any other new button).
How do I attach it to the dialog itself (I've done it in Visual Studio a couple of times with OnFormClosing).
#5
here ya go cleaner solution

Code:
Copy      Help
str dd=
;BEGIN DIALOG
;0 "" 0x90C80AC8 0x0 0 0 224 136 "Dialog"
;3 Edit 0x54231044 0x200 16 8 188 96 ""
;4 Button 0x54032000 0x0 108 116 48 14 "TRANSFER"
;2 Button 0x54030000 0x4 168 116 48 14 "Cancel"
;END DIALOG
;DIALOG EDITOR: "" 0x2040700 "*" "" "" ""

str controls = "3"
str e3
if(!ShowDialog(dd &sub.DlgProc &controls)) ret
;when a dialog closes using ok button or DT_Ok function it returns control values that can be used for other actions
if(!empty(e3))
,out e3  ;;remove this line just to show you control text
,;;;Method1;;
,e3.setclip
,key AT          ;; Alt+Tab
,0.2
,key Cv          ;; Ctrl+V    
,;;;Method2;;
,;paste e3;; uncomment to use this method and comment lines 17-20

#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
,_s.getwintext(id(3 hDlg))
,sub.OnCancelled(_s)
,case 4 ;;TRANSFER
,DT_Ok hDlg
ret 1
;
#sub OnCancelled
function ~text
if(!empty(text))
,text.setclip
,out text;;remove this line Its just for showing clipboard has been set
#6
Smile 
Thank you Kevin!

Works great. Another true learning experience ;-)


Forum Jump:


Users browsing this thread: 1 Guest(s)