Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Can't keep button centered on window size change
#1
When I maximize the screen in my dialog the buttons don't stay centered. I'm using" DT_AutoSizeControls" to move them, but they are offset to the right of the dialog window instead of centered when the window is full screen. If you restore the dialog, they move back to center. Am I using the wrong command?


Code:
Copy      Help
DT_AutoSizeControls hDlg message "20mh 21mh 22mh 23mhh"
#2
DT_AutoSizeControls does not make controls centered.

Function dlg_control_centered
Code:
Copy      Help
\Dialog_Editor
function# hDlg message wParam lParam
if(hDlg) goto messages

if(!ShowDialog("dlg_control_centered" &dlg_control_centered 0)) ret

;BEGIN DIALOG
;0 "" 0x90CF0AC8 0x0 0 0 217 129 "Dialog"
;3 Button 0x54032000 0x0 82 54 50 16 "Button"
;END DIALOG
;DIALOG EDITOR: "" 0x2030300 "*" "" ""

ret
;messages
sel message
,case WM_INITDIALOG
,SendMessage hDlg WM_SIZE 0 0
,
,case WM_SIZE
,int c=id(3 hDlg)
,RECT rd rc
,GetClientRect hDlg &rd
,GetClientRect c &rc
,mov rd.right/2-(rc.right/2) rd.bottom/2-(rc.bottom/2) c
,
,case WM_COMMAND goto messages2
ret
;messages2
sel wParam
,case IDOK
,case IDCANCEL
ret 1
#3
Thank you!
#4
Code:
Copy      Help
,case WM_INITDIALOG
,SendMessage hDlg WM_SIZE 0 0
,
,case WM_SIZE
,int c=id(3 hDlg)
,RECT rd rc
,GetClientRect hDlg &rd
,GetClientRect c &rc
,mov rd.right/2-(rc.right/2) rd.bottom/2-(rc.bottom/2) c
I've been trying to use this code you gave me to move other buttons around in my dialog, I'm having the same problem as before with my other buttons. I have 8 large buttons, 4 on top and 4 on bottom. If I play with the code I can get some of the buttons where I want them but on others (especially the right side of the screen), no matter what I do I cannot figure out how to move them to the right locations. Can you maybe break down this code and explain how I might be able to change it to move buttons around in my dialog? Or is there another code I should be using.

Thanks
#5
Function DT_AutoZoomControls
Code:
Copy      Help
;/
function hDlg message $controls

;Proportionally moves and resizes dialog controls when you resize the dialog.
;Call this function from dialog procedure, before sel message.

;hDlg, message - hDlg, message.
;controls - space-separated list of controls.
;;;Syntax for a control: IdActionDirection
;;;;;Id - control id.
;;;;;Action - m (move) or s (resize) or none (move and resize).
;;;;;Direction - h (horizontally) or v (vertically) or none (horizontally and vertically).

;EXAMPLE
;;...
;;messages
;DT_AutoZoomControls hDlg message "3mv 4 5h 6m"
;sel message
,;case WM_INITDIALOG
,;;...


type AZC_CONTROL hwnd !action !direction ^x ^y ^cx ^cy
AZC_CONTROL* p
int i j k x y cx cy
RECT r rc

sel message
,case WM_INITDIALOG
,GetClientRect hDlg &rc
,
,ARRAY(lpstr) a
,tok controls a
,p._new(a.len)
,SetProp hDlg "azc_controls" p
,
,for i 0 a.len
,,AZC_CONTROL& c=p[i]
,,lpstr s=a[i]
,,j=val(s 0 k); s+k
,,c.hwnd=id(j hDlg); if(!c.hwnd) out "Warning: control %i not found." j; continue
,,sel(s[0]) case ['m','s'] c.action=s[0]; s+1
,,c.direction=s[0]
,,
,,GetWindowRect c.hwnd &r; MapWindowPoints 0 hDlg +&r 2
,,c.x=1.0*r.left/rc.right
,,c.y=1.0*r.top/rc.bottom
,,c.cx=1.0*r.right-r.left/rc.right
,,c.cy=1.0*r.bottom-r.top/rc.bottom
,
,case WM_SIZE
,GetClientRect hDlg &rc
,
,p=+GetProp(hDlg "azc_controls")
,
,for i 0 p._len
,,&c=p[i]
,,j=0; sel(c.direction) case 'h' j|2; case 'v' j|1
,,x=c.x*rc.right
,,y=c.y*rc.bottom
,,cx=c.cx*rc.right
,,cy=c.cy*rc.bottom
,,if(c.action!'s') mov x y c.hwnd j; err
,,if(c.action!'m') siz cx cy c.hwnd j; err
,
,case WM_DESTROY
,p=+RemoveProp(hDlg "azc_controls")
,p._delete
#6
I'm sorry to keep coming back to this.. I have read the help file, looked at examples, read through the forum and tried everything I can think of. I just can't quite seem to grasp this for some reason.. I'm still VERY new to all this but can usually figure stuff out. For whatever reason, moving buttons so they remain where they should regardless of window size is the hardest thing for me to do... I tried the last example you gave me and about a hundred other things but a centered button on a smaller windows is always offset on a larger window. Should I be changing something in it when I do put it in my dialog? If I play with this
Code:
Copy      Help
,mov rd.right/2-(rc.right/2) rd.bottom/2-(rc.bottom/2) c
I can get most the buttons perfect, just not the ones on the right side of the screen for some reason. Is there something I can do with that? I've played with the numbers, renamed right to left, tried negatives, but nothing seems to work for me.. Is there an example of a dialog with say 2 or more buttons that re-adjust properly on windows size change that I can look at? I'm sure I'm driving you nuts with my inability to understand this.. It's just the only thing I can't seem to get and it's driving me crazy.. :oops:

Thanks & Sorry
#7
Better yet! Can you fix this code to center properly for me so I can see exactly what needs to be done?
Code:
Copy      Help
\Dialog_Editor
function# hDlg message wParam lParam
if(hDlg) goto messages

str controls = "1 2"
str b1Ok b3Can
if(!ShowDialog("Move_Button" &Move_Button &controls)) ret
...

BEGIN DIALOG
0 "" 0x90C90AC8 0x0 0 0 265 163 "Dialog"
1 Button 0x54030001 0x4 76 6 48 14 "OK"
2 Button 0x54030000 0x4 132 6 48 14 "Cancel"
END DIALOG
DIALOG EDITOR: "" 0x2030208 "" "2" ""

ret
messages
DT_AutoSizeControls hDlg message "1mh 2mh"
sel message
    case WM_INITDIALOG
    case WM_DESTROY
    case WM_COMMAND goto messages2
ret
messages2
sel wParam
    case IDOK
    case IDCANCEL
    case LBN_SELCHANGE<<16|3
     selectpage
    _i=LB_SelectedItem(id(3 hDlg))
    DT_Page hDlg _i
ret 1
#8
....I figured it out.... So simple. Thank you!!
#9
OK, so I finally have everything centering and re-adjusting just the way I want. :oops: But... Whenever I maximize a screen now there is this half inch or so gray box, border, frame, something on the bottom of the page. If I restore the window it goes away but as soon as I maximize again it comes back. What would that be?
#10
show your code
#11
I'm just using the "DT_AutoZoomControl" function you provided me with "DT_AutoSizeControls hDlg message "1101s""
#12
Using DT_AutoSizeControls and DT_AutoZoomControl withh same control? I did not test, maybe they cannot be used together.
#13
Code:
Copy      Help
/
function hDlg message $controls

Proportionally moves and resizes dialog controls when you resize the dialog.
Call this function from dialog procedure, before sel message.

hDlg, message - hDlg, message.
controls - space-separated list of controls.
   Syntax for a control: IdActionDirection
     Id - control id.
     Action - m (move) or s (resize) or none (move and resize).
     Direction - h (horizontally) or v (vertically) or none (horizontally and vertically).

EXAMPLE
  ...
  messages
DT_AutoZoomControls hDlg message "3mv 4 5h 6m"
sel message
     case WM_INITDIALOG
      ...


type AZC_CONTROL hwnd !action !direction ^x ^y ^cx ^cy
AZC_CONTROL* p
int i j k x y cx cy
RECT r rc

sel message
    case WM_INITDIALOG
    GetClientRect hDlg &rc
    
    ARRAY(lpstr) a
    tok controls a
    p._new(a.len)
    SetProp hDlg "azc_controls" p
    
    for i 0 a.len
        AZC_CONTROL& c=p[i]
        lpstr s=a[i]
        j=val(s 0 k); s+k
        c.hwnd=id(j hDlg); if(!c.hwnd) out "Warning: control %i not found." j; continue
        sel(s[0]) case ['m','s'] c.action=s[0]; s+1
        c.direction=s[0]
        
        GetWindowRect c.hwnd &r; MapWindowPoints 0 hDlg +&r 2
        c.x=1.0*r.left/rc.right
        c.y=1.0*r.top/rc.bottom
        c.cx=1.0*r.right-r.left/rc.right
        c.cy=1.0*r.bottom-r.top/rc.bottom
    
    case WM_SIZE
    GetClientRect hDlg &rc
    
    p=+GetProp(hDlg "azc_controls")
    
    for i 0 p._len
        &c=p[i]
        j=0; sel(c.direction) case 'h' j|2; case 'v' j|1
        x=c.x*rc.right
        y=c.y*rc.bottom
        cx=c.cx*rc.right
        cy=c.cy*rc.bottom
        if(c.action!'s') mov x y c.hwnd j; err
        if(c.action!'m') siz cx cy c.hwnd j; err
    
    case WM_DESTROY
    p=+RemoveProp(hDlg "azc_controls")
    p._delete

Is this right? If I play with the 1.0 in "c.cy=1.0*r.bottom-r.top/rc.bottom" I can move that box up or down. But can't seem to get it just right.


Forum Jump:


Users browsing this thread: 1 Guest(s)