Complex (for me) problem involving MFC

Posted on 2012-08-19
Last Modified: 2012-08-20
The situation is that I have a project comprised of multiple document (in a tabbed interface) with different views.  The underlying document is update dynamically via propertypage input.

I've implemented HTML Help that is accessed by a typical menu that is attached to the frame.

When the basic document view is activated, I post a int variable and a message string in the application control logic that can be referenced in the frame logic that initiates the help display via HtmlHelp(xx, text); statement.

When the user activates the propertypage(s), via a frame button, each page as it is activated posts its own int variable and message string in the application control logic, again, to make the information available to the frame logic so the user can click on the frame menu to activate the help call.  --> I'm doing a variation of context help, ergo the int variable (represents a link within the HTML Help file) and the text is text that I add to the menu so that the user sees the equivalent of, "click for help on xxxxxxxx".

Since the propertytpage implementation is modeless, the HTML Help viewer flashes, then disappears.

If I then click on the title bar of the propertypage dialog, the HTML Help viewer will appear under the propertypage dialog; that is great because then the user can drag it off to the side so he / she can read the help text that is specific to the displayed page.

So since that is what I want to achieve I need some way of simulating the click on the tiotle bar of the propertypage dialog or an equivalent.

This is really deep in the weeds for me and I haven't been able to arrive at a solution .

Any ideas or help would be appreciated.

Question by:Onager
    LVL 12

    Expert Comment

    I think I follow what happening.  Can you explain the bit more about 'the HTML help viewer flashes than disappears'?  Is the HTML help in a separate window, a modeless child window or something else?  When you say it disappears do you mean it drops behind the main window or is removed from the screen entirely?

    HTML help doesn't normally disappear, it lives in its own window, somewhere in the window stack.  The behaviour you're describing is like a tooltip or a menu.  To make it disappear the program would have to explicitly hide or close it.

    Author Comment

    The Help viewer is the viewer that is invoked by, for example,

    HtmlHelp(20, HH_HELP_CONTEXT);

    When any of those are executed it is executed in the main frame (CMainFrame) in response to a click on a dropdown menu item.  There is a document open in a view and a modeless propertysheet/page that is accepting input (this is a maintenance procedure) and that propertysheet/page logic is updating the underlying ocument, which in turn is updating the view of that document as a data item is entered and validated.

    The problem only ocurs when the modeless propertysheet/page is up, the help viewer operates as I would have expected if I'm only dealing with a view.

    Again, when I click on the menu item to activate Help, the Help viewer flashes then disappears immediately.  Your comment was on target, it actually disappears, hides would be a better description, behind the main window and will appear if I click on either the main window (anywhere) or on the active propertypage.  When it appears it shows up behind the propertysheet/page but in front of the main window.  Then a user can drag it off to the side and read the help information.  However, if instead of dragging the Help window off to the side the user clicks on anything on the help viewer window, it will hide behind the main window again.

    I don't see anything that I am doing that would explicitly hide it, I think it is an anomoly when there's a modeless dialog involved.

    I did try adding: this->Invalidate(); in the frame logic after HtmlHelp(xx, ccccc) to force repainting but that had no effect.  I thought that there might be a message I could post (WM_xxxxx) that might force the behavior I'm trying to get but I don't see anything that looks like it would work.

    I appreciate your reply, hope you can get me closer to a solution.
    LVL 12

    Accepted Solution

    It sounds like the HTML help window might not owned by your frame window, so it won't stay on top.  The property page is owned by the frame window and will stay on top.  It probably has the WS_EX_TOPMOST or WS_EX_TOOLWINDOW style.

    The problem appears to be that when you show the property page it gets the input focus, or is activated.  It causes the frame window to move up the z-order, which puts the HTML Help Window behind it.

    The solution is to change the relationship between the HTML Help and the frame or the property page and the frame.  If you can make the HTML Help a child window, that would solve it.  If you can make the property window not change the z-order of the frame window that would help too.

    The document of HtmlHelp() in MSDN allows you to specify an owning window.  You're examples don't have as many parameters.  Is there some other way to set the owner window in MFC?

    If you have a handle to the HTML Help window, another possibility is giving it the WS_EX_TOPMOST style.  That will mean it won't fall behind the frame window.  Unfortunately I use the Windows API directly, which gives control over everything.  I don't know MFC well enough to be able to tell you exactly how to do this.

    Author Comment


    The information you gave me led me to the solution.  It was the comments regarding z-order.

    "all" it took was adding:

          this->SetWindowPos(&CWnd::wndBottom, 0, 0, 0, 0,

    To the CMainFrame logic immediately prior to the statement:
                        HtmlHelp(20, HH_HELP_CONTEXT);

    I've not thoroughly tested all circumstances but the behavior so far is exactly what I was trying to achieve, the Help Viewer now shows up on top of the propertysheet/page and gives the user the ability to drag it off to the side.  Even more important, it stays on top of the main window, behind the propertysheet/page, while the user continues their maintenance task, making the help information as useful as I had intended (assuming they find the actual help text useful)

    Thank you again!

    Author Closing Comment

    Nudged me in teh right direction, comments were spot on.
    LVL 12

    Expert Comment

    I'm very glad it helped.  I was pretty sure you could figure out how to make it work, even if I couldn't describe the specifics of MFC.  Like you, I can't say whether the solution you describe is the best way to do it or that it will work in all cases.  Still, I can't see any problem with your method and it appears to work.  If you find a case where I doesn't work you will have some idea have to solve it now.

    Thanks for the points and the answer.  It makes EE worth the effort when people let you know that you helped.

    Featured Post

    How to run any project with ease

    Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
    - Combine task lists, docs, spreadsheets, and chat in one
    - View and edit from mobile/offline
    - Cut down on emails

    Join & Write a Comment

    Suggested Solutions

    Introduction This article is the first in a series of articles about the C/C++ Visual Studio Express debugger.  It provides a quick start guide in using the debugger. Part 2 focuses on additional topics in breakpoints.  Lastly, Part 3 focuses on th…
    Basic understanding on "OO- Object Orientation" is needed for designing a logical solution to solve a problem. Basic OOAD is a prerequisite for a coder to ensure that they follow the basic design of OO. This would help developers to understand the b…
    The goal of the video will be to teach the user the concept of local variables and scope. An example of a locally defined variable will be given as well as an explanation of what scope is in C++. The local variable and concept of scope will be relat…
    The viewer will learn how to use the return statement in functions in C++. The video will also teach the user how to pass data to a function and have the function return data back for further processing.

    733 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    18 Experts available now in Live!

    Get 1:1 Help Now