Taskbar Dimensions - SMcNeill - 12-26-2023
Quote:Code: (Select All)
DH = _DesktopHeight: DW = _DesktopWidth
TBH = TaskbarHeight: TBW = TaskbarWidth
TH = TitleBarHeight: BW = BorderWidth
If TBH = DH Then TBH = 0 'Users taskbar is configured vertical, not hortizonal.
If TBW = DW Then TBW = 0
Screen _NewImage(DW, DH, 32)
Print "This screen is the size of your desktop, but it has some inherent issues."; _Width, _Height
Print
Print "Hit the <SPACE BAR> and watch as we position it in different manners:"
Sleep
_ScreenMove 0, 0
Print
Print "To start with, this is a _SCREENMOVE 0,0 call. It places the TITLEBAR's top left corner at position 0,0."
Print "If you notice, the bottom of the screen is now hidden as the titlebar has shifted us down below the max resolution our screen will display."
Sleep
ScreenMove 0, 0
Print
Print "Now, this is a Steve Approved(tm) ScreenMove method to move the screen itself to position 0,0."
Print "Now, as you can tell (if your taskbar is set to hide itself), the program window now covers the screen perfectly."
Print "The only problem with this method is that we are now hiding the title bar over the top of the screen!"
Sleep
Screen _NewImage(DW - TBW, DH - TBH, 32)
If taskbar_bottom = TBH Then ScreenY = TBH Else ScreenY = 0
If taskbar_right = TBW Then ScreenX = TBW Else ScreenX = 0
ScreenMove ScreenX, ScreenY
Print
Print "To fix these issues, we use the functions here to figure out EXACTLY what size our screen needs to be."
Print
Print "Title Bar Height = "; TH
Print "Screen Border ="; BW; "on each side."
Print "Task Bar Height ="; TBH
Print "Task Bar Width ="; TBW
Print "Task Bar Top = "; taskbar_top
Print "Task Bar Left = "; taskbar_left
Print "Task Bar Bottom = "; taskbar_bottom
Print "Task Bar Right = "; taskbar_right
Print
Print "This is a screen perfectly sized to fit on your screen."; _Width, _Height
Print "See how it fits your visible screen perfectly?"
Print
Print "Note: If you have transparent borders, or if your theme has them set to opaque, it may appear to be a gap around your screen. That transparent gap IS the screen border. Set it a solid color and you can see it."
Print
Print "At this point, you should have your title bar up top. You screen shouldn't cover, or be covered, by the task bar."
Print "Everything should be visible and accessable for you."
Print
Print "To my way of thinking, THIS is the maximum resolution that your screen should run in with a program. "
Sleep
Screen _NewImage(DW - TBW - BW * 2, DH - TBH - TH - BW * 2, 32)
If taskbar_bottom = TBH Then ScreenY = TBH Else ScreenY = 0
If taskbar_right = TBW Then ScreenX = TBW Else ScreenX = 0
_ScreenMove ScreenX, ScreenY
Print "Or THIS height, if one wants to include the titlebar and boarder and use the whole screen, without covering the taskbar.)"
Print
Print "This is a screen perfectly sized to fit on your screen. (with Titlebar and Borders)"; _Width, _Height
Print "See how it fits your visible screen perfectly?"
Sub ScreenMove (x, y)
Do Until _Width <> 0 And _ScreenExists <> 0: Loop
_ScreenMove x - BorderWidth, y - BorderWidth - TitleBarHeight
End Sub
Sub ScreenMove_Middle
Do Until _Width <> 0 And _ScreenExists <> 0: Loop
_ScreenMove (_DesktopWidth - _Width - BorderWidth) / 2 + 1, (_DesktopHeight - _Height - BorderWidth) / 2 - TitleBarHeight + 1
End Sub
Function TaskbarHeight
$If WIN Then
Do Until _Width <> 0 And _ScreenExists <> 0: Loop
$If TASKBARDEC = UNDEFINED Then
$Let TASKBARDEC = TRUE
Declare Library "taskbar"
Function taskbar_height& ()
Function taskbar_width& ()
Function taskbar_top& ()
Function taskbar_left& ()
Function taskbar_bottom& ()
Function taskbar_right& ()
End Declare
$End If
TaskbarHeight = taskbar_height&
$Else
TaskbarHeight = 0 'no function to get the value for Linux/Mac, so return 0 instead of an error
$End If
End Function
Function TaskbarWidth
$If WIN Then
Do Until _Width <> 0 And _ScreenExists <> 0: Loop
$If TASKBARDEC = UNDEFINED Then
$Let TASKBARDEC = TRUE
Declare Library "taskbar"
Function taskbar_height& ()
Function taskbar_width& ()
Function taskbar_top& ()
Function taskbar_left& ()
Function taskbar_bottom& ()
Function taskbar_right& ()
End Declare
$End If
TaskbarWidth = taskbar_width&
$Else
TaskbarWidth = 0 'no function to get the value for Linux/Mac, so return 0 instead of an error
$End If
End Function
Function TitleBarHeight
Do Until _Width <> 0 And _ScreenExists <> 0: Loop
$If BORDERDEC = UNDEFINED Then
$Let BORDERDEC = TRUE
Declare Library
Function glutGet& (ByVal what&)
End Declare
$End If
TitleBarHeight = glutGet(507)
End Function
Function BorderWidth
Do Until _Width <> 0 And _ScreenExists <> 0: Loop
$If BORDERDEC = UNDEFINED Then
$Let BORDERDEC = TRUE
Declare Library
Function glutGet& (ByVal what&)
End Declare
$End If
BorderWidth = glutGet(506)
End Function
taskbar.h (Size: 1.11 KB / Downloads: 59)
<-- Required C-header file which needs to go in your QB64 folder for this to work properly.
RE: Taskbar Dimensions - bplus - 12-26-2023
Thanks I needed this for 2nd laptop. Now to re-configure graphics programs to handle various screen sizes and positions people may use.
Already running into issues with my programs on screens < max 1380 X 780
RE: Taskbar Dimensions - PhilOfPerth - 12-26-2023
Pardon my ignorance (again) but how do I get the HTML file into my Qb64pe folder (as a working library)?
I copied it and saved it (as HTML) into the folder, but obviously that's not the format required.
RE: Taskbar Dimensions - bplus - 12-27-2023
Hi @PhilOfPerth
An .h file is not an HTML file, it is C or C++ code that can be used as supplementary sub or function. It should be stored in the same folder as your QB64pe.exe file. Call it a "header" file.
RE: Taskbar Dimensions - SMcNeill - 12-27-2023
Aye. As bplus said, .h isn't a html file. It's a c header file. Both are basically just text, but the IDE is expecting to find "taskbar.h" in the proper place. It's not checking for "taskbar.html".
Chances are, all you need to do is rename the extension and it'll work for you.
RE: Taskbar Dimensions - PhilOfPerth - 12-27-2023
So how do I download the attachment? I'm not given the Download option on it, and
when I copy/ paste it into a Word page I just get a series of red, squiggly lines!
RE: Taskbar Dimensions - TerryRitchie - 12-27-2023
(12-27-2023, 11:15 PM)PhilOfPerth Wrote: So how do I download the attachment? I'm not given the Download option on it, and
when I copy/ paste it into a Word page I just get a series of red, squiggly lines!
Right click on it and then "Save link as"
RE: Taskbar Dimensions - SMcNeill - 12-27-2023
taskbar.h (in text forrm):
Code: (Select All) int32 taskbar_height() {
RECT rect;
HWND taskBar = FindWindow("Shell_traywnd", NULL);
if(taskBar && GetWindowRect(taskBar, &rect)) {
return rect.bottom - rect.top;
}
}
int32 taskbar_width() {
RECT rect;
HWND taskBar = FindWindow("Shell_traywnd", NULL);
if (taskBar && GetWindowRect(taskBar, &rect)) {
return rect.right - rect.left;
}
}
int32 taskbar_top() {
RECT rect;
HWND taskBar = FindWindow("Shell_traywnd", NULL);
if (taskBar && GetWindowRect(taskBar, &rect)) {
return rect.top;
}
}
int32 taskbar_left() {
RECT rect;
HWND taskBar = FindWindow("Shell_traywnd", NULL);
if (taskBar && GetWindowRect(taskBar, &rect)) {
return rect.left;
}
}
int32 taskbar_bottom() {
RECT rect;
HWND taskBar = FindWindow("Shell_traywnd", NULL);
if (taskBar && GetWindowRect(taskBar, &rect)) {
return rect.bottom;
}
}
int32 taskbar_right() {
RECT rect;
HWND taskBar = FindWindow("Shell_traywnd", NULL);
if (taskBar && GetWindowRect(taskBar, &rect)) {
return rect.right;
}
}
If worst comes to worst, you can always copy the text above and paste it into a plain text file called "taskbar.h" and put it in your qb64pe folder.
RE: Taskbar Dimensions - PhilOfPerth - 12-27-2023
Ok, got it. Thanks
Now it's playtime...
RE: Taskbar Dimensions - bplus - 12-28-2023
With the embedded stuff now, is it possible to create one sub that can set the exact screen width and height and move it so the title and task bar both show but you have the rest of the screen for your app?
I think I would use a sub like that allot for scaling the drawing, buttons and such so it fits anyones system.
|