Hello Macro colleagues,
I want to perform these 3 tasks at runtime.
1. Change the Dialog title
2. Change the content in an Editbox
3. Have the above text values perserved (not change) when call to "ResetDialogAction>MyDialog"
/* Set the text in the Editbox at runtime works */
SetControlText>Change Window title,TEdit,1,%strTemp%
/* This doesn't work. I can't change the Dialog title */
SetControlText>Change Window title,TForm,1,%strTemp%
/* Windows API: Set the text in the Editbox at runtime works */
LibFunc>user32,SetWindowTextA,lfres,MyDialog.msEdit1.HANDLE,strTemp
/* Windows API: Set the Dialog title at runtime works */
LibFunc>user32,SetWindowTextA,lfres,MyDialog.HANDLE,strTemp
/* Reset the Dialog response. However it also reset the Editbox and Dialog title changes. */
ResetDialogAction>MyDialog
/* My code */
Dialog>MyDialog
Caption=Change Window title
Width=300
Height=185
Top=CENTER
Left=CENTER
Max=0
Min=0
Close=0
Resize=0
Button=Write,12,104,69,25,1
Button=Cancel,104,104,81,25,2
Edit=msEdit1,79,38,121,msEdit1
Button=Read,206,105,75,25,3
EndDialog>MyDialog
Show>MyDialog
Label>Loop
Wait>0.1
GetDialogAction>MyDialog,res1
If>res1=2
CloseDialog>MyDialog
Exit>0
EndIF
If>res1=1
Let>strTemp=Write Hello World
SetControlText>Change Window title,TEdit,1,%strTemp%
/*
SetControlText>Change Window title,TForm,1,%strTemp%
*/
/*
LibFunc>user32,SetWindowTextA,lfres,MyDialog.msEdit1.HANDLE,strTemp
LibFunc>user32,SetWindowTextA,lfres,MyDialog.HANDLE,strTemp
*/
MessageModal>Write msEdit1=%MyDialog.msEdit1%
ResetDialogAction>MyDialog
EndIf
If>res1=3
MessageModal>Read msEdit1=%MyDialog.msEdit1%
ResetDialogAction>MyDialog
EndIf
Goto>Loop
Thanks
Kiet
How to set Dialog title and Editbox at runtime
Moderators: JRL, Dorian (MJT support)
Don't use setcontroltext on your own dialog, its not needed. Set the editbox using Let>MyDialog.msedit1=What Ever then ResetDialogAction>Mydialog
The GetDialogAction> function is reverting the dialog title after you change it so avoid using GetDialogAction> by instead using Dialog_Event OnEvents.
Here's your script cobbled a bit but working, I think as you want it.
Here's your script cleaned up:
The GetDialogAction> function is reverting the dialog title after you change it so avoid using GetDialogAction> by instead using Dialog_Event OnEvents.
Here's your script cobbled a bit but working, I think as you want it.
Code: Select all
OnEvent>Dialog_Event,MyDialog,1,UpDate
OnEvent>Dialog_Event,MyDialog,2,Close
OnEvent>Dialog_Event,MyDialog,3,Read
SRT>UpDate
Let>strTemp=Write Hello World
//SetControlText>Change Window title,TEdit,1,%strTemp%
Let>MyDialog.msedit1=strTemp
/*
SetControlText>Change Window title,TForm,1,%strTemp%
*/
//LibFunc>user32,SetWindowTextA,lfres,MyDialog.msEdit1.HANDLE,strTemp
LibFunc>user32,SetWindowTextA,lfres,MyDialog.HANDLE,strTemp
ResetDialogAction>MyDialog
MessageModal>Write msEdit1=%MyDialog.msEdit1%
END>UpDate
SRT>Close
Exit>0
END>Close
SRT>Read
MessageModal>Read msEdit1=%MyDialog.msEdit1%
ResetDialogAction>MyDialog
END>Read
Dialog>MyDialog
Caption=Change Window title
Width=300
Height=185
Top=0
Left=CENTER
Max=0
Min=0
Close=0
Resize=0
Button=Write,12,104,69,25,1
Button=Cancel,104,104,81,25,2
Edit=msEdit1,79,38,121,msEdit1
Button=Read,206,105,75,25,3
EndDialog>MyDialog
Show>MyDialog
Label>Loop
Wait>0.1
//GetDialogAction>MyDialog,res1
/*
If>res1=2
CloseDialog>MyDialog
Exit>0
EndIF
*/
/*
If>res1=1
Let>strTemp=Write Hello World
//SetControlText>Change Window title,TEdit,1,%strTemp%
Let>MyDialog.msedit1=strTemp
/*
SetControlText>Change Window title,TForm,1,%strTemp%
*/
/*
LibFunc>user32,SetWindowTextA,lfres,MyDialog.msEdit1.HANDLE,strTemp
LibFunc>user32,SetWindowTextA,lfres,MyDialog.HANDLE,strTemp
MessageModal>Write msEdit1=%MyDialog.msEdit1%
ResetDialogAction>MyDialog
EndIf
*/
/*
If>res1=3
MessageModal>Read msEdit1=%MyDialog.msEdit1%
ResetDialogAction>MyDialog
EndIf
*/
Goto>Loop
Code: Select all
OnEvent>Dialog_Event,MyDialog,1,UpDate
OnEvent>Dialog_Event,MyDialog,2,Close
OnEvent>Dialog_Event,MyDialog,3,Read
SRT>UpDate
Let>strTemp=Write Hello World
Let>MyDialog.msedit1=strTemp
LibFunc>user32,SetWindowTextA,lfres,MyDialog.HANDLE,strTemp
ResetDialogAction>MyDialog
MessageModal>Write msEdit1=%MyDialog.msEdit1%
END>UpDate
SRT>Close
Exit>0
END>Close
SRT>Read
MessageModal>Read msEdit1=%MyDialog.msEdit1%
ResetDialogAction>MyDialog
END>Read
Dialog>MyDialog
Caption=Change Window title
Width=300
Height=185
Top=0
Left=CENTER
Max=0
Min=0
Close=0
Resize=0
Button=Write,12,104,69,25,1
Button=Cancel,104,104,81,25,2
Edit=msEdit1,79,38,121,msEdit1
Button=Read,206,105,75,25,3
EndDialog>MyDialog
Show>MyDialog
Label>Loop
Wait>0.01
Goto>Loop
A big Thank You JRL for your help.
Just one last question. For some reason I can't read the Editbox value by referencing MyDialog.msEdit1. I had to use the Windows API GetWindowTextA(). Is this the proper solution in Macro Scripting?
LibFunc>user32,GetWindowTextLengthA,wtlen,MyDialog.msEdit1.HANDLE
Let>buffer_SIZE=wtlen
Let>wtlen=wtlen+1
LibFunc>user32,GetWindowTextA,lfres,MyDialog.msEdit1.HANDLE,buffer,wtlen
MessageModal>Read msEdit1=%MyDialog.msEdit1% %CRLF% lfres_2=%lfres_2%
Just one last question. For some reason I can't read the Editbox value by referencing MyDialog.msEdit1. I had to use the Windows API GetWindowTextA(). Is this the proper solution in Macro Scripting?
LibFunc>user32,GetWindowTextLengthA,wtlen,MyDialog.msEdit1.HANDLE
Let>buffer_SIZE=wtlen
Let>wtlen=wtlen+1
LibFunc>user32,GetWindowTextA,lfres,MyDialog.msEdit1.HANDLE,buffer,wtlen
MessageModal>Read msEdit1=%MyDialog.msEdit1% %CRLF% lfres_2=%lfres_2%
Code: Select all
OnEvent>Dialog_Event,MyDialog,1,UpDate
OnEvent>Dialog_Event,MyDialog,2,Close
OnEvent>Dialog_Event,MyDialog,3,Read
SRT>UpDate
Let>strTemp=Write Hello World
Let>MyDialog.msedit1=strTemp
LibFunc>user32,SetWindowTextA,lfres,MyDialog.HANDLE,strTemp
ResetDialogAction>MyDialog
MessageModal>Write msEdit1=%MyDialog.msEdit1%
END>UpDate
SRT>Close
Exit>0
END>Close
SRT>Read
LibFunc>user32,GetWindowTextLengthA,wtlen,MyDialog.msEdit1.HANDLE
Let>buffer_SIZE=wtlen
Let>wtlen=wtlen+1
LibFunc>user32,GetWindowTextA,lfres,MyDialog.msEdit1.HANDLE,buffer,wtlen
MessageModal>Read msEdit1=%MyDialog.msEdit1% %CRLF% lfres_2=%lfres_2%
ResetDialogAction>MyDialog
END>Read
Dialog>MyDialog
Caption=Change Window title
Width=300
Height=185
Top=CENTER
Left=CENTER
Max=0
Min=0
Close=0
Resize=0
Button=Write,12,104,69,25,1
Button=Cancel,104,104,81,25,2
Edit=msEdit1,79,38,121,msEdit1
Button=Read,206,105,75,25,3
EndDialog>MyDialog
Show>MyDialog
Label>Loop
Wait>0.01
Goto>Loop
-
- Pro Scripter
- Posts: 70
- Joined: Sun May 03, 2009 11:49 pm
- Location: AU
An interesting thing i noticed when running Kiet's code is that
Length>%lfres_2%,length
makes length=255
regardless of what you type in the edit box. Can anyone please explain?
After fiddling around with this for a while i have another question/thought. How would one go about getting data from a combo box. I have tried adding a combo box with options Yes and No, when i check up the initial value of the box, it is always Yes%CRLF%No
I have to physically choose Yes or No, before it changes.
Length>%lfres_2%,length
makes length=255
regardless of what you type in the edit box. Can anyone please explain?
After fiddling around with this for a while i have another question/thought. How would one go about getting data from a combo box. I have tried adding a combo box with options Yes and No, when i check up the initial value of the box, it is always Yes%CRLF%No
I have to physically choose Yes or No, before it changes.
Loving MS's Capabilities!!!
Oops. that's because in order to keep the dialog title change we turned off GetDialogAction>. As its name implies, that is the function that reassigns all of the dialog variables to the value they've been changed to. If you put GetDialogAction> back in the idle Loop, the variable would contain the test from the edit box. Very clever how you acquired the text via a win API.Kiet wrote:Just one last question. For some reason I can't read the Editbox value by referencing MyDialog.msEdit1
I don't get that result. The "Write Hello World" text reports to be 17 characters. Which I believe is correct.zabros2020 wrote:An interesting thing i noticed when running Kiet's code is that
Length>%lfres_2%,length
makes length=255
regardless of what you type in the edit box. Can anyone please explain?
I haven't tried it but I suspect its the GetDailgoAction> function having been removed that creating your problem. Add the line back into the loop and see if it makes a difference.zabros2020 wrote:How would one go about getting data from a combo box.
-
- Pro Scripter
- Posts: 70
- Joined: Sun May 03, 2009 11:49 pm
- Location: AU
Thanks JRL great work.
I don't quite grasp how ms deals with these things, but i finally have my code working thanks to you
On another note. If you use Kiet's code but omit the lines:
Max=0
Min=0
Close=0
Resize=0
And allow the user to click X, then it never enters the subroutine for close.
Is there a reason for this? I thought macro scheduler allows for X to default to 2 as a modal value
I don't quite grasp how ms deals with these things, but i finally have my code working thanks to you
On another note. If you use Kiet's code but omit the lines:
Max=0
Min=0
Close=0
Resize=0
And allow the user to click X, then it never enters the subroutine for close.
Is there a reason for this? I thought macro scheduler allows for X to default to 2 as a modal value
Loving MS's Capabilities!!!
I discovered the same thing a couple of days ago. See THIS THREAD.
-
- Pro Scripter
- Posts: 70
- Joined: Sun May 03, 2009 11:49 pm
- Location: AU