Tooltip is displayed for dialog box but not for child window - winapi

I'm working on an MFC project (old technology, I know).
In my dialog-box class (derived from CDialog) I have:
CToolTipCtrl m_cToolTipCtrl;
CWnd m_cImageWindow;
In the class OnInitDialog function I do:
m_cToolTipCtrl.Create(this);
m_cImageWindow.CreateEx(...);
m_cToolTipCtrl.AddTool(this,_T("Parent"));
m_cToolTipCtrl.AddTool(&m_cImageWindow,_T("Child"));
In the class PreTranslateMessage function I do:
m_cToolTipCtrl.RelayEvent(pMsg);
When I run the project, the "Parent" tooltip is displayed whenever I hover within the parent window, but the "Child" tooltip is not displayed whenever I hover within the child window.
I have originally tried this without the "Parent" tooltip and it didn't work, so it is obviously not a matter of the "Parent" tooltip masking the "Child" tooltip.
I think that events are relayed only to the parent window, but I'm not really sure how to tackle this problem.
Putting a breakpoint in the PreTranslateMessage function is useless, since it stops eminently on every event that the application receives. How can I investigate this problem?

Found the answer:
Simply add the SS_NOTIFY flag to the child window style when creating it.
For example:
m_cImageWindow.CreateEx(0,WC_STATIC,NULL,WS_CHILD|SS_NOTIFY,{0,0,0,0},this,0);

Related

mfc OnVScroll not getting called in MDI main frame class

I have a c++ MFC MDI based project using visual studio 2013 community.
Mainframe class is derived as
class CMainFrame : public CMDIFrameWndEx
In mainframe class in pre-create, the scroll bar is set as below.
cs.style |= WS_VSCROLL | WS_HSCROLL;
An OnVScroll call back function has been added to receive a call back whenever the main frame scroll bar is moved. ON_WM_VSCROLL() has been added to the message map in the mainframe. We find that OnVScroll never gets called.
How do we enable callbacks on OnVScroll whenever the user moves the scrollbar. Any help will be very appreciated.
Thanks & Regards,
Rakesh
Please be aware that a scrollbar for CMDIFrameWndEx makes no sense.
The CMDIFrameWndEx has a child window of type CMDIClientAreaWnd,this window covers the complete client area that is left after toolbars and ribbon are created.
So when you create the main frame with the styles WS_VSCROLL | WS_HSCROLL this styles are removed from the main frame window and transferred to the inner class (the MDI client window).
So the outer frame window will never receive the scroll messages.
You have the MFC source code, just look into the source code of the function CMDIFrameWnd::CreateClient! You find the behavior there.
After this is done the CMDIClientAreaWnd gets control via a subclass of the handle m_hWndMDIClient to the class CMDIClientAreaWnd.
This class is responsible for the MDI-Tab View style.
So if you want the scrollbar messages you may use classic subclassing to the inner MDI Client window.
Spy++ may help you to understand the window structure.

How make button in NSWindow clickable while a sheet's on top of it

I have created a custom (themed) NSWindow, by creating a borderless window and then recreating all elements of the window border/background inside the content view. I've created the window widgets (close box, zoom box, minimize box) on top of my own fake title bar using -standardWindowButton:forStyleMask:.
Trouble is, when a sheet is presented on top of my custom window (e.g. "save changes...", those buttons do not receive the clicks.
Does anybody know how I can tell NSWindow not to intercept the clicks in my minimize box? It works with a standard NSWindow. When a sheet is up, I can still send both of them to the dock, or zoom the window out.
I thought maybe there's special code in the content view that ignores clicks in subviews while a sheet is up. But it seems as if -hitTest: is called on the content view and returns the minimize widget, but the widget's action never gets triggered.
I guess I could just replace the content view and perform the action in the content view's hitTest if it is the minimize widget ... but that seems a bit ugly.

Why do my buttons stay highlighted simultaneously?

You usually only have one button that looks like a "default button".
However, I made a child window and placed two buttons in it (with the child window as their parent). Then I put the child window inside a dialog and displayed it.
Suddenly, the buttons stay highlighted even when I click other buttons!
Why?
Your child window needs the WS_EX_CONTROLPARENT style, to allow the dialog to handle the notifications from its children.

Child Windows Not Being Added Properly

I'm trying to add a secondary window to bottom of my main window in an OS X application, with the hopes of eventually making it so it animates out from underneath the window when a toggle button is pressed. As far as I can tell, the best way to do this with the SDK is to add a window as a child window using - [NSWindow addChildWindow:ordered:]. However, when I call that function, although the secondary window is displayed, it isn't added as a child window. Here's the function called when I press the button:
- (IBAction)childToggleButtonPressed:(id)sender {
[self.window addChildWindow:_secondaryWindowController.window ordered:NSWindowBelow];
NSLog(#"Child Windows: %#", [[self.window childWindows] count]);
}
(I haven't added the code to dismiss it yet because I'm making sure it shows up in the first place first.)
And here's the output to the console:
2011-08-31 12:37:25.312 Playground[1712:707] Child Windows: (null)
Does anyone know why the window isn't being added as a child and what I can do to fix this?
Some additional context that might help is that I'm drawing a custom window using an image as the background for both the window itself and the title bar. The code I'm modifying can be found at http://cocoawithlove.com/2008/12/drawing-custom-window-on-mac-os-x.html.
Thank you!
EDIT: I tried overriding the - [NSWindow addChildWindow:ordered:] function and logging any information I could find, and it turns out the window itself isn't passed to the function. Hopefully this will help someone find out the problem!
I ended up solving this problem by making it so that the child windows did not have NSWindowControllers. Apparently you can't assign the window of an NSWindowController to be a child window. As soon as I turned them into NSWindow subclasses, I could add them as child windows using the code I showed above (replacing _secondaryWindowController.window with the window, of course).
In short, don't use an NSWindowController's window as a child window, use just an NSWindow.

combobox dropdown window can show beyond the combobox window,how?

in windows, how can make a 'child' window beyond the parent window, and the parent window always in active status (GetActiveWindow() return parent), just like the combobox dropdown window.
I think these are the main points when trying to do this:
The pop-up is a top-level window which has the same parent as the control. (i.e. The pop-up is not a child of the control. It's not a child-window at all; it's a top-level window, but one without a thick window border etc. so it doesn't look like a normal top-level window.) That's why it can extend outside of the control's boundaries.
When the pop-up is created it is shown using ShowWindow(hWndPopup, SW_SHOWNA) so that it does not take the input focus. This prevents the parent window from going inactive.
When the pop-up is created you capture the mouse using SetCapture. You then track where the mouse is and highlight items within the pop-up when the mouse overlaps them. When the mouse button is clicked you act on whatever is under the mouse (or cancel the pop-up if the mouse isn't over it at all). Remember to respond to WM_CAPTURECHANGED, in case something else captures the mouse. And remember to ReleaseCapture when you are done.
The popup should handle WM_MOUSEACTIVATE by returning MA_NOACTIVATEANDEAT.

Resources