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

Dialog Editor version 6.X
plus
plus

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

Center Dialog for Any Screen Resolution


Question:

I would like to ceter a custom dialog no matter what the screen resolution is. Can this be done using WinMetrics and or WinPlace, I guess this would have to be done with two scripts not sure if this can then be compiled into one exe?

Can this be done? Has any of you Winbatch experts done this possibly in a UDF or something?

Answer:

If you want the dialog to *always* come up centered set MyDialogX and MyDialogY to 9999

If you want the dialog to start out centered, then if the user moves it and the dialog is later redisplayed, to use the location it was moved to, then set MyDialogX and MyDialogY to -1

;Alternately, here's some code I posted a while ago to make a splash 
;screen centered at a constant size regardless of resolution.  Basically,
;you get your screen size in dialog units by taking dimensions in pixels
;(WinMetrics 0 & 1, and dividing by pixels per dialog unit (WinMetrics -6
;& -5).

ScreenWidth =WinMetrics(0)/WinMetrics(-6)                  ;Determine screen width in dialog units
ScreenHeight=WinMetrics(1)/WinMetrics(-5)                  ;Determine screen height in dialog units
DlgWidth =ScreenWidth*0.663                                ;Make splash screen 2/3 width of screen
DlgHeight=ScreenHeight*0.5                                 ;Make splash screen 1/2 height of screen
DlgX=(ScreenWidth-DlgWidth)  /2                            ;Determine X co-ordinate for splash screen to be centered
DlgY=(ScreenHeight-DlgHeight)/2                            ;Determine Y co-ordinate for splash screen to be centered

TextWidth=162                                             
TextHeight=30
TextX=(DlgWidth-TextWidth)  /2                             ;Determine X co-ordinate for label to be centered
TextY=(DlgHeight-TextHeight)/2                             ;Determine Y co-ordinate for label to be centered

DlgCaption="Splash Test"                                   ;Get name of dialog window for later reference
DlgCount=5                                                ;Set length of display in seconds

;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~;
;FixBox : Sets window style.                                                      ;
;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~;
;Win   : window name                                                              ;
;flags : Use '&' to combine flags                                                 ;
;        ~262144    unresizable                                                   ;
;        ~65536     remove maximize                                               ;
;        ~131072    remove minimize                                               ;
;        ~12582912  remove caption                                                ;
;        ~524288    remove system menu                                            ;
;        2147483648 pop up mode                                                   ;
;        8388608    pop up mode with border                                       ;
;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~;
#DefineFunction FixBox(Win,Flags)                          ;Originally by Guido, with some liberties taken by Marc Worrel
hwnd=DllHwnd (Win)                                         ;Get window handle
User32 = StrCat(DirWindows(1),"USER32.DLL")
OldStyle=DllCall(User32, long:"GetWindowLongA",long:hwnd,long:-16)
NewStyle=OldStyle & Flags
Result = DllCall(User32,long:"SetWindowLongA",long:hwnd,long:-16,long:NewStyle)
;Display can glitch until window is refreshed, so convince it has moved by moving it to its own current position
CurPos = Arrayize(WinPosition(Win),",")                      
WinPlace (CurPos[0],CurPos[1],CurPos[2],CurPos[3],Win)
IntControl (54,Win,1,0,0)
Return (Result)
#EndFunction

#DefineSubRoutine   DlgCallback (DlgName,DlgEvent,DlgCtrlNo,param4,param5)
InitDialog = 0
TimerTick  = 1
   Switch DlgEvent
      Case InitDialog
         Count=DlgCount                                    ;Set initial count
         FixBox (DlgCaption,8388608)                       ;Get rid of window caption and create frame
         DialogProcOptions (DlgName,TimerTick,1000)        ;Set 1 second timer event
         Return (-2)
      Case TimerTick
         Count=Count-1
         If Count==0 Then Return (1)
         Return (-2)
   EndSwitch 
   Return (-2) 
#EndSubRoutine

frmSplashFormat=`WWWDLGED,6.1`
frmSplashCaption=DlgCaption
frmSplashX=DlgX
frmSplashY=DlgY
frmSplashWidth=DlgWidth
frmSplashHeight=DlgHeight
frmSplashNumControls=002
frmSplashProcedure=`DlgCallback`
frmSplashFont=`DEFAULT`
frmSplashTextColor=`DEFAULT`
frmSplashBackground=`DEFAULT,DEFAULT`
frmSplashConfig=123
frmSplash001=`201,155,034,014,PUSHBUTTON,DEFAULT,"OK",1,1,1,DEFAULT,DEFAULT,DEFAULT`
frmSplash002=`%TextX%,%TextY%,%TextWidth%,%TextHeight%,STATICTEXT,DEFAULT,"Insert text here",DEFAULT,2,DEFAULT,"Microsoft Sans Serif|24576|40|34","0|0|128",DEFAULT`
frmSplashButtonPushed=Dialog("frmSplash",1)

Article ID:   W15903
File Created: 2004:03:30:15:41:40
Last Updated: 2004:03:30:15:41:40