WinBatch Tech Support Home

Database Search

If you can't find the information using the categories below, post a question over in our WinBatch Tech Support Forum.

TechHome

Windows UDFs

Can't find the information you are looking for here? Then leave a message over on our WinBatch Tech Support Forum.

Keywords: 

Question:

I'm aware of the trick of forcing dialogs to the center by entering huge or invalid values for the X and Y coordinates of a dialog created with the dialog editor, but is there any way to know if a user moved the dialog, what the coordinates were when he pressed a button and closed the dialog (so i can make it display in the same place next time...) Certainly this is a frequently desired behaviour, no?

Answer:

If you have WinBatch 2001, and you set DialogX and DialogY to -1, then it will exhibit the behavior you are looking for.

Question (cont'd):

yes, that works nice, but is there a possibility to retrieve those new coordinates and use them in a next session ?

Answer:

Yes. Ummm IntControl 75.

Here are some UDFs.

In the following examples, you can choose: inifile or registry.

When the parameter savelocation is numeric: registry otherwise it is an inifile

#definefunction SaveWinPosXY(thisdlg, savelocation)
; usage: ButtonPushed = Dialog('MyDialog')
; SaveWinPosXY('MyDialog', savelocation)
; !! do not use buttonvalue 0 for &Cancel....
; !! use another value and do the handling yourself
%thisdlg%X = IntControl(75, 1, 0, 0, 0)
%thisdlg%Y = IntControl(75, 2, 0, 0, 0)
if isnumber(savelocation) ;---- savelocation is a registry key
   key = RegCreateKey(savelocation,'position')
   rtv = RegSetValue(key,'[%thisdlg%X]', %thisdlg%X)
   rtv = RegSetValue(key,'[%thisdlg%Y]', %thisdlg%Y)
else ;---- savelocation is an inifile
   IniWritePvt('position','%thisdlg%X' ,%thisdlg%X,savelocation) 
   IniWritePvt('position','%thisdlg%Y' ,%thisdlg%Y,savelocation) 
endif
#endfunction

#definefunction GetWinPosX(thisdlg, savelocation)
; usage: MyDialogX = GetWinPosX('MyDialog',savelocation)
; default value: -1 (centered)
;

if isnumber(savelocation) ;---- savelocation is a registry key
   key = RegCreateKey(savelocation,'position')
   if RegExistValue(key,'[%thisdlg%X]')
      retvalue = RegQueryValue(key, '[%thisdlg%X]')
   else
      retvalue = -1
   endif
else ;---- savelocation is an inifile
   retvalue = IniReadPvt('position','%thisdlg%X',-1,savelocation) 
endif
return retvalue
#endfunction


#definefunction GetWinPosY(thisdlg, savelocation)
; usage: MyDialogY = GetWinPosY('MyDialog',savelocation)
; default value: -1 (centered)
;

if isnumber(savelocation) ;---- savelocation is a registry key

key = RegCreateKey(savelocation,'position')
   if RegExistValue(key,'[%thisdlg%Y]')
      retvalue = RegQueryValue(key, '[%thisdlg%Y]')
   else
      retvalue = -1
   endif
else ;---- savelocation is an inifile
   retvalue = IniReadPvt('position','%thisdlg%Y',-1,savelocation) 
endif
return retvalue
#endfunction


#definefunction ExeIniFile()
; returns an inifile with the path and root of the exefile
;
exepath = IntControl(1004,0,0,0,0)
return strCat(FilePath(exepath),FileRoot(exepath),'.ini')
#endfunction


;savelocation = ExeIniFile() ;-- savelocation is an inifile
savelocation = RegCreateKey(@REGCURRENT,'Software\WinBatch\winpos_udf') ;-- savelocation is a registry key


;--- testing.......
MyDialogFormat=`WWWDLGED,5.0`

MyDialogCaption=`WIL Dialog`
MyDialogWidth=178
MyDialogHeight=78
MyDialogNumControls=6

MyDialog01=`82,52,64,DEFAULT,PUSHBUTTON,DEFAULT,"&Cancel",99`
MyDialog02=`48,12,64,DEFAULT,VARYTEXT,MyDialogX,""`
MyDialog03=`10,12,36,DEFAULT,STATICTEXT,DEFAULT,"MyDialogX ="`
MyDialog04=`10,26,36,DEFAULT,STATICTEXT,DEFAULT,"MyDialogY = "`
MyDialog05=`48,26,64,DEFAULT,VARYTEXT,MyDialogY,""`
MyDialog06=`8,52,64,DEFAULT,PUSHBUTTON,DEFAULT,"&Try again",1`

while 1
MyDialogX= GetWinPosX('MyDialog',savelocation)
MyDialogY= GetWinPosY('MyDialog',savelocation)

ButtonPushed=Dialog("MyDialog")
SaveWinPosXY('MyDialog', savelocation)
if buttonpushed==99 then exit
endwhile

exit 


Article ID:   W14991
File Created: 2001:11:08:12:41:18
Last Updated: 2001:11:08:12:41:18