SDL adjust window size - c++

I want SDL window size to stay within working area (SPI_GETWORKAREA) of windows which excludes windows taskbar other panels.
The problem is that both SDL_CreateWindow and SDL_SetWindowSize set the client area of window, not the size including window borders. So when I set window size to fit on a small working area, the borders still go out of working area.
SDL_CreateWindow: Use this function to set the size of a window's client area.
Does SDL provide a way to set window size within working area? or how do I get border size of SDL window so that I can do that myself?

You don't even need WinAPI to do that.
The size of window borders can be determined by SDL_GetWindowBordersSize(), and the part of the display not occupied by taskbar should be returned by SDL_GetDisplayUsableBounds().
With these functions, maintaining a proper window position (and maybe size) should be easy.

The only way I know of (SDL 1.2) is to first create a small window (2x2 pixels) and then check the total window size using the Windows API (GetWindowPlacement). Based on this, you can calculate the parameters necessary to get the window size you are looking for, and finally resize the window (MoveWindow).
I hope someone has a better solution, because this is a very ugly workaround.

Related

CDialogEx:: OnNCPaint() increases the size of dialog window

I need to draw custom title bar, using Win10, VS2017, MFC, SDK10.0.16299.0.
When MyDialog::OnNcPaint() does not call CDialogEx::OnNcPaint(), the dialog frame is drawn incorrectly - the top corners are rounded while bottom corners are sharp, and dialog size increases in couple of pixels.
I need to keep the dialog in original size and shape. Any suggestions please ?

GTK3 No resize limits

Currently if I make a window in GTK3
For example 300x300
And I put a button at the bottom, right hand corner, I can not shrink my window
Size because this button is preventing me is there a function in gtk3 that can allow me to ignore all widgets, and resize to anything even 0x0
And this is the user doing this with the window resize, drag and click
And is there a way where I can set this resize limit myself, and not have this dependent on whats in my window
If you initially use set_size_request() to set the window to 300x300, then it won't shrink below that. To allow users to shrink below an initial value, use set_default_size(). I seem to have read that the minimum size of a widget is 1x1, which seems logical, as, at 0x0 you wouldn't be able to resize it anymore. If you want less than 1x1, you can use hide() and just hide the contents.
But if you have any widgets inside the window, then the minimum size is determined by the widgets! (Called the 'natural size')
To allow a window smaller that than the one determined by the widgets, you can maybe use a Gtk.ScrolledWindow.
Also, recall that the outer border is drawn by the window manager, NOT by Gtk. However, you can disable the outer border by using set_decorated(). Not that this may not work - depending if the window manager respects this (not Gtk's fault).

QGLWidget maximum size

I have a Qt application using OpenGL drawing with QGLWidget, on Mac OS.
On my MBP it works well, but when trying on a 30" screen, I noticed that there is a window size limit.
If I increase the window size beyond a certain limit, the QGLWidget's content disappears and only some greyish memory junk is visible.
I changed the code to only put a QGLWidget on the screen. The repaint event is setting the background black in each iteration.
The issue is still visible: when resizing the widget, the black surface disappears and gets replaced by the memory junk, when the size of the widget reaches a certain size.
Interesting facts:
When I decrease the window size, the GL surface comes back to live again
I have several other GL applications (not Qt) running in maximized window, so the issue is not with the OpenGL driver/video card
It seems that the area of the window (nr of pixels) matters, if I make the window very wide, it's height will be limited and vica versa, I if the windoe is maximized in height, the width must be small
I found that while instantiating the QGLWidget using QGLFormat(QGL::NoSampleBuffers) instead of QGLFormat(QGL::SampleBuffers) solves the issue.

Program that displays content on screen but no window

In windows: I would like to know if it is possible (and if so, how) to make a program in C++ that displays images/text on the screen directly, meaning no window; if you are still confused about what I am after some examples are: Rocketdock and Rainmeter.
you can do it certainly without using Qt or any other framework. Just Win32 API helps you do that and internally, every framework calls these API so there is no magic in any of these frameworks
First of all, understand that no image or text can be displayed without a window. Every program uses some kind of window to display text or image. You can verify it using the Spy++ that comes with windows SDK. click the cross-hair sign, click the image or text you think is displayed without any windows. The Spy++ will show you the window it is contained in.
Now how to display such image or text that seems like not contained in any window. Well you have to perform certain steps.
Create a window with no caption bar, resize border, control box, minimize, maximize or close buttons. Use the CreateWindowEx() and see the various windows style WS_EX_XXX, WS_XXX for the desired window style.
Once the window is there you need to cut the window. Much like a cookie cutter. for this you need to define an area. This area is called region and you can define it using many functions like CreateEllipticRgn(), CreatePolygonRgn(), CreateRectRgn(), CreateRoundRectRgn() etc. all these functions return a HRGN which is the handle to the region. Elliptical or rectangle regions are OK as starter.
Now the last part. You have to cut the window like that particular region. Use the SetWindowRgn() function which requires a handle to your window and a handle to that region (HRGN). This function will cut the window into your desired shape.
Now for the image or text. Draw the image or text inside the window. I assume you must have cut the window according to your image, You just need to give window a face. so just draw the image either on WM_ERRASE BACKGROUND or WM_PAINT messages
Use the SetWindowPos() to move the window to the location you wish to on screen. If you have used correct parameters in CreateWindowEx() then this step is not necessary
You can set any further styles of windows using SetWindowLong() function.
Congratulations, you have your image displayed without using any windows ;)

How to make a window that's full screen but still shows the task bar

I'd like to make a captionless window that covers the entire desktop, but still shows the task bar. What is the best way to do this?
I can detect where the taskbar is and just resize my window to exclude it, but then I need to know when the user changes the size / position of the task bar.
Or, is there a combination of window styles or something else that will make sure my window is always behind the task bar?
Set your window placement using the return value from SystemParametersInfo, passing SPI_GETWORKAREA as a parameter.
Retrieves the size of the work area on the primary display monitor.
The work area is the portion of the screen not obscured by the system
taskbar or by application desktop toolbars. The pvParam parameter must
point to a RECT structure that receives the coordinates of the work
area, expressed in virtual screen coordinates.
Maximise a window with no caption/border.