zpq
New Member
Posts: 18
|
Post by zpq on Sept 27, 2021 11:56:48 GMT -5
Hi Is there a way to position the mainwindow anywhere on the screen? Also a graphics window.?
Thanks
|
|
|
Post by Walt Decker on Sept 27, 2021 12:21:13 GMT -5
Do you mean at startup or after the window is created?
AT STARTUP:
UpperLeftX = someposition > 0 UpperLeftY = someposition > 0
AFTER STARTUP:
OPEN "User32.dll FOR DLL AS #USER WinHndl = HWND(#YOURHANDL)
CALLDLL #USER, "MoveWindow", WinHndl AS ULONG, YourPosX AS LONG, _ YourPosY AS LONG, WinSizeX AS LONG, WinSizeY AS LONG, 1 AS LONG, _ RetVal AS VOID
The 1(one) near the end tells windows you want the screen updated now.
EDIT: If WinSizeX and/or WinSizeY are different from the original the window will be resized.
|
|
zpq
New Member
Posts: 18
|
Post by zpq on Sept 27, 2021 13:00:20 GMT -5
UpperLeftX = 1 UpperLeftY = 1
tried many numbers, can't come close to center screen
|
|
|
Post by Walt Decker on Sept 27, 2021 13:35:02 GMT -5
UpperLeftX = DisplayWidth / 2 UpperLeftY = DisplayHeight / 2
There is also a way to get it using API
EDIT: That places the upper left corner of the window at the center of the monitor. If you want the window centered:
UpperLeftX = (DisplayWidth / 2) - (WindowWidth / 2) UpperLeftY = (DisplayHeight / 2) - (WindowHeight / 2)
|
|
|
Post by Brandon Parker on Sept 27, 2021 14:28:33 GMT -5
Just a heads up...
You do not have to "Open" or "Close" the user32.dll with Liberty BASIC. This DLL is already opened by Liberty BASIC itself and is available for immediate use when you run a Liberty BASIC program; LB will also automatically close user32.dll when the program shuts down.
The handle used by Liberty BASIC is "#user32" ...
{:0)
Brandon Parker
|
|
zpq
New Member
Posts: 18
|
Post by zpq on Sept 28, 2021 7:41:00 GMT -5
I can't get the window out of the upper left quadrant. Tried everything suggested.
I have Win10 Pro display is 1920x1200
|
|
|
Post by Brandon Parker on Sept 28, 2021 8:01:55 GMT -5
Can you provide some example code? If your window would be positioned off the screen at all, Windows likes to force it to be completely visible. If this is the case, you may have to move the window after it has been opened. I normally do this by opening the window in the hidden state, moving it where I want it, and then showing it.
Example code from you will help everyone immensely that is trying to provide support for you.
{:0)
Brandon Parker
|
|
|
Post by tsh73 on Sept 28, 2021 8:21:18 GMT -5
This code does put windows at all four corners and center too. Try it.
print DisplayWidth print DisplayHeight '1920 '1080
DATA "Center window" DATA "Top Left" DATA "Bottom Left" DATA "Top Right" DATA "Bottom right"
winSize=200 'center UpperLeftX = (DisplayWidth / 2) - (winSize / 2) UpperLeftY = (DisplayHeight / 2) - (winSize / 2) handle$ = "#win";4 read ttl$ open "ttl$" for text as #handle$ '#handle$ "trapclose subClose" 'doesn't work for text window #handle$ ttl$ 'wait
for i = 0 to 1 for j = 0 to 1 x= (DisplayWidth-winSize)*i+1 ' as I know, 0 doesn't work!!! y= (DisplayHeight-winSize)*j+1 UpperLeftX = x UpperLeftY = y handle$ = "#win";4 read ttl$ print ttl$, x, y open "ttl$" for text as #handle$ '#handle$ "trapclose subClose" #handle$ ttl$ next next
wait
sub subClose handle$ close #handle$ end sub
|
|
|
Post by Rod on Sept 28, 2021 9:06:43 GMT -5
Are we discussing the IDE, the window that opens to allow you to edit basic code?
|
|
zpq
New Member
Posts: 18
|
Post by zpq on Sept 28, 2021 9:17:32 GMT -5
from the error log.
Runtime error: No DLL for #USER32
I do have user32.dll
CALLDLL #USER32, "MoveWindow", WinHndl AS ULONG, YourPosX AS LONG, _ YourPosY AS LONG, WinSizeX AS LONG, WinSizeY AS LONG, 1 AS LONG, _ RetVal AS VOID
|
|
zpq
New Member
Posts: 18
|
Post by zpq on Sept 28, 2021 9:19:19 GMT -5
the window that opens when you RUN the code
|
|
|
Post by Brandon Parker on Sept 28, 2021 9:22:15 GMT -5
Anatoly, The method used to generate the window #handle for each window is not really an approved method. That being said, it will work, but you can not choose what the #handle$ name is based on providing the handle$ variable a string (handle$ does have to be set to something though). It seems that LB has some form of counting (in some awkward way and not really correct all the time) the occurrences of #handle$ being used to generate a new window handle. The string values always start at the top of the count.
I guess that is one way to have LB automatically generate handle names, BUT doing so does not guarantee uniqueness if the programmer is also using the same naming convention - #handleX - where X is a number. In testing, LB always starts at that top count value even if the programmer has used it. For instance, let's say that LB has its count at 7 and the user has designated a hard-coded window handle as #handle7, LB will still start off its auto-generation at #handle7 as well. This leads to some issues with control of the hard-coded window that the user set up because #handle7 now points to the new window, and the initial window is orphaned.
Before we get too off-topic with that, we should start a new thread for discussing it if you want. I just wanted to point out what was going on with how the handles are actually being generated.
Also, you can make the TrapClose work by using the Text window version for the statement.
#handle$ "!TrapClose subClose"
{:0)
Brandon Parker
|
|
zpq
New Member
Posts: 18
|
Post by zpq on Sept 28, 2021 9:22:30 GMT -5
This code does put windows at all four corners and center too.
that works OK
It is the mainwindow that I can't get where I want.
|
|
|
Post by Brandon Parker on Sept 28, 2021 9:23:17 GMT -5
from the error log. Runtime error: No DLL for #USER32 I do have user32.dll CALLDLL #USER32, "MoveWindow", WinHndl AS ULONG, YourPosX AS LONG, _ YourPosY AS LONG, WinSizeX AS LONG, WinSizeY AS LONG, 1 AS LONG, _ RetVal AS VOID The handle is case-sensitive. Unless you "Open user32.dll For #USER32" then #USER32 is not going to be available. Walt issued "Open user32.dll For #USER" and therefore #USER was available. I was stating earlier that doing that is not necessary since LB automatically opens the user32.dll for its own use and thus makes it available for the programmer, but it does so under the handle #user32. Try using #user32 instead...all lower-case. {:0) Brandon Parker
|
|
zpq
New Member
Posts: 18
|
Post by zpq on Sept 28, 2021 9:59:21 GMT -5
OK the error is gone. Can you give me code that works on your computer?
Thanks
|
|