Render with OpenGL to part of Win32 Window - c++

I have a regular Win32 window, I want to render using OpenGL only to part of that window, I found this question:
Using OpenGL in a regular window (Win32)
But I don't really know how they created a panel inside a window and got the DC for it..
Basically I want a window that will draw buttons, lists and more using win32 and on the same window, in some specified section, render opengl stuff.
I tried using glScissor and clearing the buffers but that just fills the whole screen with black and the part I specified in the clear color..
I also tried using glViewport but that didn't do anything.

I ended up creating a new widget like so:
HWND OpenglHWND = CreateWindowW(L"Static", L"",
WS_CHILD | WS_VISIBLE | WS_BORDER,
200, 10, 300, 300, ParentWindowHandle, 0, 0, NULL);
After that, you got the HWND of the panel you created, from here just initialize OpenGL like you always do, BUT, when creating the context, use the DC of the HWND we got before! (basically use GetDC(OpenGLHWND) for the OpenGL context)

You'd need to create a WinForms Panel control (assuming you are using WinForms?) then call GetDC(panel.Handle) passing the Handle property of the panel as a parameter. This will give you the DC to create the OpenGL context.

Related

Maximized WS_POPUP window goes in front of the taskbar

I'm creating a window in C++ with that code:
HWnd = CreateWindow(wc.lpszClassName,
"myapp",
WS_POPUP |WS_VISIBLE,
10, 10, 1000, 800, 0, 0, hInst, NULL);
It appears as I want but when I maximize it with like this:
ShowWindow(hwnd, SW_SHOWMAXIMIZED);
then it's like a fullscreen window so that the taskbar is hidden.
I think it's because it is a POPUP window but this is like I want it to appear.
Do I need to create my own maximize function or is there a parameter to avoid that ?
Thanks
You can add WS_CAPTION | WS_SYSMENU | WS_MAXIMIZEBOX style.
If you want your window to be without caption then you will need to adjust window size manually to fit into desktop work area that you can query using SystemParametersInfo specifying SPI_GETWORKAREA flag.
This is a feature where the Taskbar will get out of your full-screen application:
If you want to create a fullscreen window that covers the taskbar, just create a fullscreen window and the taskbar will automatically get out of the way.
I’ve seen people hunt for the taskbar window and then do a ShowWindow(hwndTaskbar, SW_HIDE) on it. This is nuts for many reasons.
Don’t do any of this messing with the taskbar. Just create your fullscreen window and let the taskbar do its thing automatically.
Since this is Stackoverflow, a combination of Wikipedia and Reddit, i want this relevant information saved for the next guy asking this question.

Transparent hwnd window

Is it possible to create a "transparent" hwnd window ? What I mean by that is that there is no background or borders of that window but that only text is visible...like if I have a main window background and I have something written on the background ( or if I just want to add text on some area via window ) and I want to make it a clickable option, to create that kind of window that will be invisible but still clickable.
On Windows 2000 and later, you can create a top-level window with the WS_EX_LAYERED style (on Windows 8 and later, child windows can now use the WS_EX_LAYERED style as well), and then use SetLayeredWindowAttributes() or UpdateLayeredWindow() to make the window transparent.
Create a solid background color, and then set that color as the window's transparent color. Anything on the window that is not using that color will not be transparent. The OS will handle the rest for you.
Refer to MSDN for more details:
Layered Windows
Using Layered Windows
SetLayeredWindowAttributes()
UpdateLayeredWindow()
From your tag of hwnd, I'm assuming that you are working with C++ or at least have access to the Win32 API, there are plenty of resources to help you get started. The concept is called Window Compositing.
Transparent win32 window and text
Quick and Dirty Window Transparency
If you use WPF instead of C++, here's a link:
Transparent Windows in WPF
First set the styles to enable the layers:
SetWindowLong(itsec->first, GWL_EXSTYLE, GetWindowLong(itsec->first, GWL_EXSTYLE) & WS_EX_LAYERED);
Then indicate if you want the transparency to be alpha or not:
SetLayeredWindowAttributes(itsec->first, RGB(154,255,214), 200, LWA_ALPHA);

How to make Win32 EDIT window on desktop outside of dialog take up all space

I need to create an EDIT control directly on the desktop without being inside of a dialog box. I need the text box to take up all the available space in the window.
Currently I am trying to just do something like:
CreateWindow(L"EDIT", nullptr, WS_VISIBLE, 0, 0, 300, 50, nullptr, nullptr, nullptr, nullptr);
But that results in a textbar that's almost as wide as my window, but not nearly as tall, surrounded by a transparent background.
I'm relatively new to win32 programming so any pointers in the right direction would be helpful.
Looks like I just needed to add WS_POPUP in addition to WS_VISIBLE

partially click through on layered windows win32

In using layered windows in win32 or atl/wtl c++ if I set the main window's alpha to 0 and paint on the child, fake window so that it is viewable and click the window, the entire window is a click through.
I want to be able to make only regions of the window click through, not the entire window, let's say if I want to paint a rounded corner window, I make the bottom/main window to be click through but I don't want the upper "fake" window to be click through, i want to be able to click on it. How do I do that?
Where I am so far:
In the OnInitDialog function of the main window :
::SetWindowLong( m_hWnd, GWL_EXSTYLE, ::GetWindowLong(m_hWnd, GWL_EXSTYLE) | WS_EX_LAYERED);
BYTE bTran = 0;
::SetLayeredWindowAttributes( m_hWnd, 0, bTran, LWA_ALPHA);
and when I create the fake window:
m_hFakeWnd = ::CreateWindowEx( WS_EX_LAYERED | WS_EX_TRANSPARENT | WS_EX_NOACTIVATE | WS_EX_LEFT
, m_strWndClassName
, NULL
, WS_VISIBLE | WS_OVERLAPPED
, rc.left
, rc.top
, rc.Width()
, rc.Height()
, GetSafeHwnd()
, NULL
, ::GetModuleHandle(NULL)
, NULL
);
IF, I set eliminate the WS_EX_TRANSPARENT flag the fake window is click-able while the main is click through, but! it doesn't respond to anything! click/drag. none.
It sounds like you are covering another window solely for the purpose of intercepting clicks?
Anyway, you need to handle window's WM_NCHITTEST message in order to be able to let system know that particular position is transparent, in which case you return HTTRANSPARENT:
In a window currently covered by another window in the same thread (the message will be sent to underlying windows in the same thread until one of them returns a code that is not HTTRANSPARENT).
Use alpha 1 instead of 0 in the regions you want to accept clicks. The window will still be completely invisible but the areas of alpha 1 will register clicks and mouse movements as normal.
Note that to get per-pixel alpha you'll need to use UpdateLayeredWindow rather than SetLayeredWindowAttributes.
Make two windows, one with click-through properties and another with normal ones.

Float GLUT window on top without titlebar on OSX

I'm creating a simple commandline applicatiation that starts a GLUT window.
I need that GLUT window to be always on top and remove the titlebar.
Basically GLUT does not provide anything for this so i'm looking into other options. On Windows i would do something like:
glutCreateWindow( "dpd" ); //create window with glut
HWND hwnd = FindWindow( "GLUT", "dpd" );
SetWindowPos( hwnd, HWND_TOPMOST, NULL, NULL, NULL, NULL, SWP_NOREPOSITION | SWP_NOSIZE ); //set the window always-on-top
But how can i do such a thing on OSX? (C++)
I already use some Carbon code to remove the menubar, but the titlebar is still visible:
SetSystemUIMode(kUIModeAllHidden,KWindowNoTitleBarAttribute);
i'm new to OSX development and out of ideas..
thanks
Ok, i found out that there is now way to make changes / ajustments to a glut window. So i finaly created a workaround: i start glut on one thread, on an other thread i created a fullscreen window with a transparent background and created a dynamic backgroundimage (png) with a viewport with just the size of the GLUT window without the titlebar. Sound kind a ugly but hey, it works, the client does get the result they want within budget :)
If you think there is a better solution for this without creating a manual openGL implementation please let me know!