Dock window in win32 c++ - c++

Can you dock a child window control in C++ win32 API (like are there WS_* styles or something), or do you always have to listen for the WM_SIZE message on the parent window and manually re-layout/fill all the children?

There is nothing directly available in the WinAPI that will automate this, it's generally implemented by framework wrappers (like MFC...). However, there are a few libraries (such as this one) that you could use as an alternative to implementing it from scratch.

Related

Win32 api different classes per window?

ive recently started to work with the win32 api and im trying to do a couple of things.
I have a project that is gonna use about 4-5 windows. I want to seperate each of these into a different cpp file where each has its own message Loop. How do i pass information from window to window?(is there some sort of entry point?) at the moment im creating all windows during case WM_CREATE: and I am showing them as required.
I am trying to have a nice OOP design but having trouble with that, my main issue is the communication between windows. I have a fair amount of experience in C# and C++ and other than this the win32 api is not being a problem.
Thanks for your help!
I don't think you want a per-window message loop, unless you want each window in its own thread. You probably need a window procedure instead.
Each window class has its own window procedure, which you register by setting lpfnWndProc field of WNDCLASS structure before passing it to the RegisterClass. Once you've done that, you can use that class when creating a new window with CreateWindow.
In your case, you'll probably want to implement the window procedure so it accepts custom messages (WM_APP + x), and then pass custom messages between windows using PostMessage (for asynchronous communication) or SendMessage (for synchronous communication). If necessary, you can create separate window classes and window procedures for your different windows. A single message loop is capable of pumping messages to all these procedures.
The classic way of inter-window communication is sending / posting messages:
SendMessage
PostMessage

Why does GetSafeHwnd() return zero in an ActiveX control?

I have developed a MFC Activex control which is windowless and invisible in runtime, while i assumed that basically an activex is a control that would manipulate a windows handle, i have used GetSafeHwnd() to get windows handle, but unfortunately this method returns zero when it runs. maybe i had set wrong option when creating my activex. how i can create a windowless activex which could manipulate windows hanlde?
By definition, windowless ActiveX control doesn't have a window, and rendered as part of its parent. If you want to work with Windows messages in the control, you can create worker thread with a message loop, and handle any messages there. To have message loop, you don't need a window, just thread. This solution can be implemented in windowless control or in any COM component.
Alternatively, you can use windowed ActiveX control by changing its properties.

IWebBrowser2 and move hosting window

I use IWebBrowser2 to implement a GUI for my application. I have a custom frameless window which hosts IWebBrowser2. Javascript and window.external I use to communicate with the application.
My question is how to implement moving my host window (with IWebBrowser2 of course)?
I draw a pseudo-Header in html and I need to detect mouse-down event (this is possible)
inside and detect mouse-move event after... and I don't know how can I do it?
Thanks
Don't use IWebBrowser2 directly for this. Instead, use the Win32 API. You can get a HWND with IWebBrowser2::get_HWND. With that, it's easy to subclass its windowproc (via SetWindowLong(GWL_WNDPROC)) and intercept WM_MOUSEMOVE.

How to enumerate MFC controls if I only have a h_wnd?

Long time reader, first time poster.
I'm a big noob when it comes to win32 gui apps so here's my question.
Let's say you have a handle to a window:
HWND h_wnd;
That window ultimately has a bunch of controls, list, buttons and whatnot.
Now I believe all controls inherit from CWnd (maybe that's not the right technical term in MFC...not sure). So would I be able to drill down to the controls using something like:
EnumChildWindows();
Again, I only have access to the top window handle.
Thanks !
MFC controls are normal windows so you can use EnumChildWindows.
EnumChildWindows recursively enumerates all child windows of a parent window.

Controls on main window using Visual C++ designer?

Is is possible to draw controls using Visual C++ designer on the main window, in the same way you can design dialogs? I'd preferably like to be able to design the main window controls this way without using MFC, rather than creating them on WM_CREATE.
EDIT: I don't want a dialog-based app, just to be able to design the main window graphically similar to what can be done using Windows Forms Designer in .NET?
Your options are:
Use MFC and create a main window that has a dialog view (based on the CFormView class).
Use WinForms/.NET
Use Qt.
If you're starting a new project and you want to stick with C++, then I highly recommend Qt. Not only is it an excellent framework, but it's cross-platform so your app could be built on Linux and the Mac.
http://www.qtsoftware.com/products/
A Visual C++ plugin is available and you can design your main window visually using a tool called Qt Designer.
I'm not sure if I understand what you want your app to look like. If you want your application to be a dialog, then make it a dialog app.
Just create a new MFC Application, and set it to "Dialog based". Now your application will start at that dialog.
If you want to use a native win32 app, just create the dialog in your InitInstance, using CreateDialog (instead of CreateWindow).
In both cases, you use the resource editor to create the dialog.