embed window(glfwCreateWindow) as child to C++ MFC parent form - opengl

Please refer this link
Embedding a GLFW window inside windows forms
How can the same achieved by using VC++ to embed glfw window to Parent form?

Try this:
Call glfwWindowHint() to set GLFW_DECORATED and GLFW_VISIBLE to false.
Call glfwCreateWindow().
Call glfwGetWin32Window() to get the native handle of the OpenGL window.
Call SetParent() to set your form as the new parent of the OpenGL window.
Call GetWindowLong() / SetWindowLong() to remove the WS_POPUP and add the WS_CHILDWINDOW style for the OpenGL window.
Call ShowWindow() to finally make the OpenGL window visible.
I got this from github.com/Chronial/foo_chronflow :: EngineWindow.cpp.
You might also call SetWindowPos() to adjust the position of the OpenGL window within your form.

The link in zett42's post is dead, so here's a more complete snippet
glfwWindowHint(GLFW_DECORATED, GLFW_FALSE);
glfwWindowHint(GLFW_VISIBLE, GLFW_FALSE);
GLFWwindow* pWindow = glfwCreateWindow(width, height, "", NULL, NULL);
HWND hwNative = glfwGetWin32Window(m_pWindow);
SetParent(hwNative, hwParentWindow);
long style = GetWindowLong(hwNative, GWL_STYLE);
style &= ~WS_POPUP; // remove popup style
style |= WS_CHILDWINDOW; // add childwindow style
SetWindowLong(hwNative, GWL_STYLE, style);
... any other initialisation code (e.g enable/disable gl features) ...
ShowWindow(hwNative, SW_SHOW);

Related

Render with OpenGL to part of Win32 Window

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.

MFC - Minimize main MDI window only

I have main MDI window and have custom CWnd derived window which I create dynamically run-time. I want to keep that window on the screen even when main MDI window is minimized but I dont want to have top-most window. I have tried use WS_EX_CONTROLPARENT | WS_EX_APPWINDOW styles, set parent to NULL and set owner to GetDesktopWindow() but nothing works.
Any ideas how I should do that?
When window is minimized, it takes down with it all of its child and owned windows.
This code creates a regular (not topmost) window which is not hidden when the main frame is minimized:
HWND hWnd = ::CreateWindow(L"button", L"test", WS_CAPTION|WS_VISIBLE,
100, 100, 200, 200, GetDesktopWindow(), 0, 0, 0);

Qt widget on top of other non qt window

I'm developing a plugin for a commercial program (I can't change it) that I use in Windows operating system. In this plugin I create a Qt Widget and when in the main program a button is clicked, the qt widget appears.
My problem is that the widget appears under the main program window, while I want it on top of it. It can be stay Always on top, if necessary.
Qt::WindowStaysOnTopHint does not seems to work here because I have no Qt parents.
I've found a way to put it on top, following the Qt wiki, and I've created a method that I call after widget constructor:
void RadiationPatternWidget::setWindowTopMost()
{
#ifdef Q_WS_WIN32
HWND hwnd = winId();
DWORD exStyle = ::GetWindowLong(hwnd, GWL_EXSTYLE);
DWORD style = ::GetWindowLong(hwnd, GWL_STYLE);
HWND parent = NULL;
if (parentWidget()) {
parent = parentWidget()->winId();
}
exStyle |= WS_EX_TOPMOST;
HWND newHwnd = ::CreateWindowEx(exStyle, L"#32770", NULL, style,
CW_USEDEFAULT, CW_USEDEFAULT,
CW_USEDEFAULT, CW_USEDEFAULT,
parent, NULL, qWinAppInst(), NULL);
create(newHwnd, true, true);
#endif // Q_WS_WIN32
}
Then I call it after constructor:
m_pxRadiationPatternWidget = new RadiationPatternWidget();
m_pxRadiationPatternWidget->setWindowTopMost();
Now it stays on top, but I've some problem:
Inside the widget I use some QPushButton cannot and if window is raised they are not clickable. clicked() signals are not captured and button image does not change when I click on it with mouse.
Inside the widget I use a derived QGLWidget derived class. When I put it on top this widget is black, while if I don't call the method it works well.
How can I raise on top che QWidget correctly?
Before using your hack, check if widget->window()->raise() wouldn't work.
Using the window class "#32770" is an error. You need to use the same window class that Qt is already using for your window.
You need to retrieve the class used by Qt for the existing window, and only then create a new window with the same class.

Win32: How to hide 3rd party windows in taskbar by hWnd

I have to hide popup windows in third party library.
I have implemented windows hook stuff with SetWindowsHookEx and know all the newely created hWnd(s). I listen to HSHELL_WINDOWCREATED callback and do the following:
long style= GetWindowLong(hWnd, GWL_STYLE);
style &= ~(WS_VISIBLE); // this works - window become invisible
style |= WS_EX_TOOLWINDOW; // flags don't work - windows remains in taskbar
style &= ~(WS_EX_APPWINDOW);
SetWindowLong(hWnd, GWL_STYLE, style);
What I do wrong here to hide newely created windows in task bar?
Before you use SetWindowLong, call ShowWindow(hWnd, SW_HIDE), then call SetWindowLong, then call ShowWindow again like ShowWindow(hWnd, SW_SHOW). So your code will look like this:
long style= GetWindowLong(hWnd, GWL_STYLE);
style &= ~(WS_VISIBLE); // this works - window become invisible
style |= WS_EX_TOOLWINDOW; // flags don't work - windows remains in taskbar
style &= ~(WS_EX_APPWINDOW);
ShowWindow(hWnd, SW_HIDE); // hide the window
SetWindowLong(hWnd, GWL_STYLE, style); // set the style
ShowWindow(hWnd, SW_SHOW); // show the window for the new style to come into effect
ShowWindow(hWnd, SW_HIDE); // hide the window so we can't see it
Here is a relevant quote from Microsoft's Website:
To prevent the window button from being placed on the taskbar, create
the unowned window with the WS_EX_TOOLWINDOW extended style. As an
alternative, you can create a hidden window and make this hidden
window the owner of your visible window.
The Shell will remove a window's button from the taskbar only if the
window's style supports visible taskbar buttons. If you want to
dynamically change a window's style to one that doesn't support
visible taskbar buttons, you must hide the window first (by calling
ShowWindow with SW_HIDE), change the window style, and then show the
window.
You must use GWL_EXSTYLE to get/set the EX flags, GWL_STYLE will not work for EX flags.

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!