Author Topic: Record position of a Dialog box  (Read 4414 times)


  • Newbie
  • *
  • Posts: 42
Record position of a Dialog box
« on: February 24, 2014, 09:34:44 am »
Hi folks, quick question.

I've got an application that uses a simple dialog (not currently a Dynamic Dialog). It appears at a set point on the display when you run it. Is there any way to record if a user moves it to another part of the screen so that when the dialog is called again it can go back to the place the user moved it to rather than the original location?



  • Wilson WindowWare Tech Support
  • Pundit
  • *****
  • Posts: 1183
  • WinBatch® can do it.
    • WinBatch Tech Support Database
Re: Record position of a Dialog box
« Reply #1 on: February 24, 2014, 09:46:52 am »
Not sure if you are aware but the x and y coordinates of the dialog can contain values with special meaning. i.e. 9999 or -1.

Specify 9999 to always force the dialog to center, or specify -1 to center but remember user placement for re-display.

Does that fit your needs?
Deana F.
Technical Support
Wilson WindowWare Inc.


  • Sr. Member
  • ****
  • Posts: 511
Re: Record position of a Dialog box
« Reply #2 on: February 24, 2014, 12:02:00 pm »
I've used this scheme before (in pseudo code)
Code: Winbatch
L = position from ini file
set box position L

master timer loop
                P = current box position
                if P != L
                        L = P
                        store L position in ini file
end master timer loop

the idea is, the program repeatedly queries it's own position,  and if it detects change, write the new position to an ini file.  On startup, it retrieves and uses the position from the ini file.
The mind is everything; What you think, you become.


  • Tech Support
  • *****
  • Posts: 4386
    • WinBatch
Re: Record position of a Dialog box
« Reply #3 on: February 24, 2014, 07:49:20 pm »
A crude example showing one simple way to save and restore a WIL Dialog's size and location.
Code: Winbatch
;; Ini file with dialog position info.
strLocIni = DirScript():"LocateMe.ini"

;;; Save current dialog location to ini file.
#DefineFunction PlacementSave(strCaption, strLocIni)
   strRect = WinPlaceGet(@Normal, strCaption)
   IniWritePvt("Position", "rect",  strRect, strLocIni)
   return 1

;;; Position dialog based on saved position in ini file.
#DefineFunction PlacementRestore(strCaption, strLocIni)
   strRect = IniREadPvt("Position", "rect",  "-1", strLocIni)
   if strRect != "-1" then WinPlaceSet(@Normal, strCaption, strRect)
   then return 1
   else return 0

;; Rough example of UDF that can both save
;; and restore a dialogs location .
#DefineSubroutine LocateCallback(LocateMe_Handle,LocateMe_Message,LocateMe_Name,LocateMe_EventInfo,LocateMe_ChangeInfo)
   switch LocateMe_Message                                  
      case 0   ;; Initialize.
         PlacementRestore(LocateMeCaption, strLocIni)                                
         DialogProcOptions(LocateMe_Handle,2,@TRUE)  ; Button clicks.
         ;;DialogProcOptions(LocateMe_Handle,11,@TRUE) ; System menu Close.
      case 2   ;; Button pressed
      ;;case 11  ;; System menu close. (Uncomment for close system menu.)
            PlacementSave(LocateMeCaption, strLocIni)


LocateMeCaption=`Locate Me`


"No one who sees a peregrine falcon fly can ever forget the beauty and thrill of that flight."
  - Dr. Tom Cade