I would like to write some code in my System/Mod/Config file that sets the main window to a specified (constant) size. Can anyone help me with some suggestions or examples?
Thanks.
Setting the main window size
- Ivan Denisov
- Posts: 362
- Joined: Tue Sep 17, 2013 12:21 am
- Location: Krasnoyarsk, Russia
Re: Setting the main window size
There is one module, which I wrote for internal windows.
Use HostWindows.main instead of win(HostWindows.Window).wnd and you do not need GetWindow for such a case.
Code: Select all
MODULE CpcWindows;
IMPORT HostWindows, Views, WinApi, Windows;
PROCEDURE GetWindow (name: ARRAY OF CHAR): Windows.Window;
VAR win, winTmp: Windows.Window; title: Views.Title;
BEGIN
win := Windows.dir.First();
winTmp := NIL;
WHILE (win # NIL) & (winTmp = NIL) DO
win.GetTitle(title);
IF title$ = name$ THEN
winTmp := win
END;
win := Windows.dir.Next(win)
END;
RETURN winTmp
END GetWindow;
PROCEDURE SetWindow* (name: ARRAY OF CHAR; x, y: INTEGER);
VAR win: Windows.Window; ret: WinApi.BOOL;
BEGIN
win := GetWindow(name);
IF win # NIL THEN
ret := WinApi.SetWindowPos(win(HostWindows.Window).wnd, 0, x, y, 0, 0,
WinApi.SWP_NOSIZE + WinApi.SWP_NOZORDER + WinApi.SWP_NOACTIVATE)
END
END SetWindow;
PROCEDURE ResizeWindow* (name: ARRAY OF CHAR; w, h: INTEGER);
VAR win: Windows.Window; ret: WinApi.BOOL;
BEGIN
win := GetWindow(name);
IF win # NIL THEN
ret := WinApi.SetWindowPos(win(HostWindows.Window).wnd, 0, 0, 0, w, h,
WinApi.SWP_NOMOVE + WinApi.SWP_NOZORDER + WinApi.SWP_NOACTIVATE)
END
END ResizeWindow;
PROCEDURE Close* (name: ARRAY OF CHAR);
VAR win: Windows.Window;
BEGIN
ASSERT(name$ # "", 20);
win := GetWindow(name);
IF win # NIL THEN
Windows.dir.Select(win, FALSE);
Windows.dir.Close(win)
END
END Close;
END CpcWindows.
- Ivan Denisov
- Posts: 362
- Joined: Tue Sep 17, 2013 12:21 am
- Location: Krasnoyarsk, Russia
Re: Setting the main window size
Also this peace of code as an example, how to control window resize behavior and decoration.
Code: Select all
PROCEDURE TrackWindow* (wnd: Windows.Window);
VAR res: WinApi.BOOL; hnd: WinApi.HANDLE; style: SET;
BEGIN
hnd := wnd(HostWindows.Window).wnd;
style := BITS(WinApi.GetWindowLongA(hnd, WinApi.GWL_STYLE));
style := style - WinApi.WS_THICKFRAME - WinApi.WS_CAPTION;
res := WinApi.SetWindowLongA(hnd, WinApi.GWL_STYLE, ORD(style));
style := BITS(WinApi.GetWindowLongA(hnd, WinApi.GWL_EXSTYLE));
style := style - WinApi.WS_EX_DLGMODALFRAME - WinApi.WS_EX_CLIENTEDGE - WinApi.WS_EX_STATICEDGE;
res := WinApi.SetWindowLongA(hnd, WinApi.GWL_EXSTYLE, ORD(style))
END TrackWindow;
PROCEDURE UntrackWindow* (wnd: Windows.Window);
VAR res: WinApi.BOOL; hnd: WinApi.HANDLE; style: SET; wp: WinApi.WINDOWPLACEMENT;
BEGIN
hnd := wnd(HostWindows.Window).wnd;
style := BITS(WinApi.GetWindowLongA(hnd, WinApi.GWL_STYLE));
style := style + WinApi.WS_THICKFRAME + WinApi.WS_CAPTION;
res := WinApi.SetWindowLongA(hnd, WinApi.GWL_STYLE, ORD(style));
style := BITS(WinApi.GetWindowLongA(hnd, WinApi.GWL_EXSTYLE));
style := style + WinApi.WS_EX_DLGMODALFRAME + WinApi.WS_EX_CLIENTEDGE + WinApi.WS_EX_STATICEDGE;
res := WinApi.SetWindowLongA(hnd, WinApi.GWL_EXSTYLE, ORD(style));
res := WinApi.GetWindowPlacement(hnd, wp);
DEC(wp.rcNormalPosition.right, wp.rcNormalPosition.left); DEC(wp.rcNormalPosition.bottom, wp.rcNormalPosition.top);
res := WinApi.SetWindowPos(hnd, 0, 0, 0, wp.rcNormalPosition.right, wp.rcNormalPosition.bottom, WinApi.SWP_NOZORDER + WinApi.SWP_FRAMECHANGED + WinApi.SWP_NOACTIVATE)
END UntrackWindow;
Re: Setting the main window size
Thanks Ivan.
I already knew how to write your GetWindow procedure, but it does not help here as I wanted the main window. But the suggestion to use HostWindows.main was precisely the information I needed.
My code isThe position and size parameters were obtained by trial and error. I'm sure there is a more sophisticated solution, but this is adequate for my immediate needs. (It is odd that I need an x-position of -8 pixels to align the window with the left of my (dual) screen!)
Thanks.
I already knew how to write your GetWindow procedure, but it does not help here as I wanted the main window. But the suggestion to use HostWindows.main was precisely the information I needed.
My code is
Code: Select all
res := WinApi.MoveWindow (HostWindows.main, -8, 0, 2638, 1086, 1)
Thanks.