Context Sensitive Help for a Dialog

General Macro Scheduler discussion

Moderators: JRL, Dorian (MJT support)

Post Reply
User avatar
JRL
Automation Wizard
Posts: 3529
Joined: Mon Jan 10, 2005 6:22 pm
Location: Iowa

Context Sensitive Help for a Dialog

Post by JRL » Wed May 17, 2006 7:15 pm

Here is a concept script for context sensitive help messages. The messages are invoked by right clicking an object or by pressing F1 while the mouse cursor is over an object. In this case the object is a field or a button. The messages will be closed when 5 seconds has elapsed or when ESC is pressed or when a second right click takes place. I'm certain that a script Marcus wrote long ago could be used to create a mouseover situation to invoke the help but I didn't shoot for that capability here.

http://www.mjtnet.com/forum/viewtopic.php?t=1515

[code]//Script relies on the OnEvent function which is only
//available with version 8.0 or later.

//VK2 is right mouse click
OnEvent>KEY_DOWN,VK2,0,Help
//VK112 is the F1 key
OnEvent>KEY_DOWN,VK112,0,Help
//VK27 is the ESC key
OnEvent>KEY_DOWN,VK27,0,CloseHelp
Let>k=1
Let>msg=~n~o~n~e~

////////////////////////////////////////////////////////
//Dialog example taken from the MS dialog help file
//Two modifications made to the original script as noted.
//Mod. 1- Added "Close=0" in dialog to remove title bar options
Dialog>Dialog1
Caption=Help Test
Top=113
Width=264
Left=16
Height=113
Close=0
Button=Update,16,8,75,25,5
Button=Exit,16,48,75,25,6
Edit=msEdit1,104,8,121,
ComboBox=msComboBox1,104,32,121,1%CRLF%2
Edit=msEdit2,104,56,121,
EndDialog>Dialog1

Show>Dialog1

Label>ActionLoop
GetDialogAction>Dialog1,r
if>r=5,Update
if>r=6,Close
if>r=2,exit
//Mod. 2- Added wait to thwart tight loop
Wait>0.01
Goto>ActionLoop
Label>exit

SRT>Update
Let>Dialog1.msEdit2=%Dialog1.msEdit1% %Dialog1.msComboBox1%
ResetDialogAction>Dialog1
END>Update

SRT>Close
CloseDialog>Dialog1
Let>r=2
END>Close
////////////////////////////////////////////////////////

SRT>Help
IfWindowOpen>Dialogtooltag%k%
CloseWindow>Dialogtooltag%k%
EndIF

GWP>Help Test,hx,hy
GCP>cx,cy
Let>rx=%cx%-%hx%
Let>ry=%cy%-%hy%
If>{(%rx%>110)and(%rx%35)and(%ry%msg=Type your name here
Gosub>Process
EndIf
If>{(%rx%>110)and(%rx%57)and(%ry%msg=Select a number
Gosub>Process
EndIf
If>{(%rx%>110)and(%rx%83)and(%ry%msg=result box for your name and your number
Gosub>Process
EndIf
If>{(%rx%>20)and(%rx%35)and(%ry%msg=Select here to update result box
Gosub>Process
EndIf
If>{(%rx%>20)and(%rx%73)and(%ry%msg=Select here to cancel dialog
Gosub>Process
EndIf

////MessageModal below was helpful in determining the outer
////bounds of the items to be commented for help.
////to use: unremark the "MDL" line and remark out all
////"Gosub>Process" lines above. Start the script.
////Right clicking will pop up a message with the position
////of the "Help Test" window, the cursor position when you
////right clicked, and the difference between them.
////Right clicking each corner of a field or button will tell
////you its outer boundaries. These boudaries are used in the
////If> statements above.
//MDL>Help Test position %hx%:%hy%%CRLF%Cusor position %cx%:%cy%%CRLF%Difference %rx%:%ry%
END>Help

SRT>Process
Len>%msg%,len
Let>wide={int(%len%*6)}
add>k,1
Let>file1=%TEMP_DIR%~BorderOnlyDialog%k%~.scp
IfFileExists>%file1%
DeleteFile>%file1%
EndIF
WriteLn>%file1%,wresult,Dialog>Dialog%k%
WriteLn>%file1%,wresult, Caption=Dialogtooltag%k%
WriteLn>%file1%,wresult, Width=%wide%
WriteLn>%file1%,wresult, Height=0
WriteLn>%file1%,wresult, Top=%cy%
WriteLn>%file1%,wresult, Left=%cx%
WriteLn>%file1%,wresult, Close=0
WriteLn>%file1%,wresult, Resize=0
WriteLn>%file1%,wresult, Title=0
WriteLn>%file1%,wresult, Label=%msg%,5,1
WriteLn>%file1%,wresult,EndDialog>Dialog%k%
WriteLn>%file1%,wresult,show>dialog%k%
WriteLn>%file1%,wresult,WIN>2,Dialogtooltag%k%
WriteLn>%file1%,wresult,wait>0.01
WriteLn>%file1%,wresult,CloseDialog>Dialog%k%
WriteLn>%file1%,wresult,wait>0.0.01
WriteLn>%file1%,wresult,LibFunc>user32,FindWindowA,dhwnd,TForm,Dialogtooltag%k%
WriteLn>%file1%,wresult,LibFunc>user32,SetWindowLongA,sres,dhwnd,-16,1073741824
WriteLn>%file1%,wresult,show>dialog%k%
WriteLn>%file1%,wresult,set>Dialogtooltag%k%
WriteLn>%file1%,wresult,wait>5

//I tried three different methods to call the dialogs which are the
//help text. All provide slightly different visual appeal.
////The following line works but is visually unappealing
////Also, will not function in an exe on non MS licensed computers
////but is the one that is most universal for this post.
Run>%COMMAND_LINE% %file1%

////The following line works but does not allow pressing ESC to close
//Macro>%file1%

////The following line works but is visually unappealing
////Also, it requires runmacro.exe to be transported as a second
////executable and placed in the non MS licensed computer's
////temp directory. Of the three it is my favorite.
//Run>%TEMP_DIR%runmacro.exe /mac=%file1%

/////////////////////////////////////////////
//One line contents of runmacro.exe //
//macro>%mac% //
////////////////////////////////////////////

IfFileExists>%file1%
DeleteFile>%file1%
EndIF
END>Process

SRT>CloseHelp
IfWindowOpen>Dialogtooltag%k%
CloseWindow>Dialogtooltag%k%
Set>Help Test
EndIF
END>CloseHelp[/code]

Thank you Marcus for the Tips and Tricks post yesterday to make the title bar disappear from a dialog box.

http://www.mjtnet.com/forum/viewtopic.php?t=1759

Comments, questions or concerns?

Later,
Dick

Post Reply
Sign up to our newsletter for free automation tips, tricks & discounts