Eddie,
I have recently had a battle with the positioning of window controls and so I've modified Paul's code a little to show positioning of %ib controls using
GET_WINDOW_LOCATION@ & MOVE_WINDOW@.
A couple of problems to overcome first. The get_window_location@ actually returns the position of a control relative to the top left corner of the window, but the move_window@ is relative to the first pixel under the caption bar and to the right of the LH border. These of course vary with text size and windows style (standard or XP for example). It there is a %mn then it is the first pixel below the menu.
What I did, and there is probably a better way was to construct a dummy window on startup, which places a caption and a menu, followed by an %rd control. Using a %sc callback, which returns 0, closing the dummy window, I position the %rd to 0,0 and get its position. Add 1 to the x & y positions and use this as the offset from the top of the overall window. Subsequently the get_real_control_location routine simply subtracts these from the get_window_location@ positions to get a location relative to the first usable space. This can then be used to set the %ib or any other control to a new location. After a window resize, the overall window size could be adjusted to account for any dramatic repositioning of controls that you have carried out.
I know it is a bit long winded, but it might help.
Paul,
Is there any way to get the locations relative to the same point that move_window@ uses?
Regards
Ian
WINAPP
include <windows.ins>
INTEGER i,iresize,iget_offsets,imove_ib2
external iresize,iget_offsets,imove_ib2
common/window_things/ihandle_window,ihandle_ib1,ihandle_ib2,ihandle_tt
common/window_offset/ixoffset,iyoffset
!dummy window
i=winio@('%ca[dummy]&')
i=winio@('%mn[File[Exit]]&','EXIT') !include this line only if real window is to contain a menu
i=winio@('%rd%lc%sc',i,ihandle_window,iget_offsets)
! real window
i=winio@('%ca[Image bar]%ww%bg[btnface]%hw&',ihandle_window)
i=winio@('%bd&',0.0D0,0.0D0,0.5D0,1.0D0)
i=winio@('%mn[File[Exit]]&','EXIT')
i=winio@('%3ib[flat]&','cut/Cut',4,'CONTINUE','copy/Copy',4,'CONTINUE','paste/Paste',4,'CONTINUE')
i=winio@('%lc&',ihandle_ib1)
i=winio@('%se&',0.0D0)
i=winio@('%3ib[flat]&','cut/Cut',4,'CONTINUE','copy/Copy',4,'CONTINUE', 'paste/Paste',4,'CONTINUE')
i=winio@('%lc&',ihandle_ib2)
i=winio@('%ff%^tt[Move IB2]&',imove_ib2)
i=winio@('%lc&',ihandle_tt)
i=winio@('%ff%pv%^gr[black,user_resize]',300,200,iresize)
END
integer*4 function iresize()
include <windows.ins>
common/window_things/ihandle_window,ihandle_ib1,ihandle_ib2,ihandle_tt
! get new position & size of overall window
call get_real_control_location(ihandle_window,ix,iy,iw,ih)
print *,'window',ix,iy,iw,ih
! get new position & size of first ib block
call get_real_control_location(ihandle_ib1,ix,iy,iw,ih)
print *,'ib 1 ',ix,iy,iw,ih
! get new position & size of second ib block
call get_real_control_location(ihandle_ib2,ix,iy,iw,ih)
print *,'ib 2 ',ix,iy,iw,ih
! get new position & size of text button
call get_real_control_location(ihandle_tt,ix,iy,iw,ih)
print *,'tt ',ix,iy,iw,ih
iresize = 1
end
! get initial offsets using dummy window
integer*4 function iget_offsets()
include <windows.ins>
common/window_things/ihandle_window,ihandle_ib1,ihandle_ib2,ihandle_tt
common/window_offset/ixoffset,iyoffset
! set the %rd pixel location to zero,zero
call MOVE_WINDOW@( ihandle_window, 0,0)
call GET_WINDOW_LOCATION@( ihandle_window, ixoffset, iyoffset, iw, ih)
ixoffset = ixoffset + 1
iyoffset = iyoffset + 1
print *,ixoffset, iyoffset
iget_offsets = 0
end
! move the second %ib block
integer*4 function imove_ib2()
include <windows.ins>
common/window_things/ihandle_window,ihandle_ib1,ihandle_ib2,ihandle_tt
common/window_offset/ixoffset,iyoffset
call get_real_control_location(ihandle_ib2, ix, iy, iw, iw)
ix = ix + 2
call MOVE_WINDOW@( ihandle_ib2, ix, iy)
imove_ib2 = 1
end
!fix returned locations
subroutine get_real_control_location(ihandle,ix,iy,iw,ih)
include <windows.ins>
common/window_offset/ixoffset,iyoffset
call GET_WINDOW_LOCATION@( ihandle, ix, iy, iw,ih)
ix = ix - ixoffset
iy = iy - iyoffset
end
RESOURCES
cut BITMAP cut.bmp
copy BITMAP copy.bmp
paste BITMAP paste.bmp