Solved

z-order across parent windows

Posted on 2004-10-22
1,040 Views
Last Modified: 2007-12-19
I am implementing something called GlassPanel in Java, except I am using C#.

The purpose of a GlassPanel is usually to draw lines that link the controls laid out on the main panel below the GlassPanel.

I have done everything fine until the last step, where I draw lines on the top level glass panel (a transparent panel) and have the lines show up above the controls behind it. the lines do show up on top of controls that are peers to the transparent panel (same containing parent window). but when the peer control has its own child controls, these child controls cover up the lines.

This must be because the z-order of the transparent panel is not preserved by these child controls. Each parent window maintain their own z-order stack.

How do I set the relative z-order for windows who do not share the same parent window.

I have already tried the SetWindowPos call from User32.dll. so that is not the answer.

Thanks

Bruce
0
Question by:bhomass
    15 Comments
     

    Author Comment

    by:bhomass
    come on guys. you mean this is the very first question I ever posted on the site, and I am getting a No hitter? how hard is this question? is it impossible or the points are not worth anybody's time?
    0
     
    LVL 49

    Expert Comment

    by:DanRollins
    I don't know C#, but this sounds like it could be a generic Windows programming question.

    I have to think that the controls are being draw after the lines are drawn (as opposed to the lines being clipped as they are drawn).

    I have to know if you are drawing things in the "Windows Way" by doing so in the WM_PAINT handler.  One way to ascertain that is to use the mouse to drag another application window across the window that has the lines.    A similar test is to move the window partially off screen and then back on screen.

    What happns when you try those tests?

    If the code is written correctly, then the lines should be redrawn immediately after either action (without needing to be manually triggered in your program).

    -- Dan
    0
     

    Author Comment

    by:bhomass
    Hi Dan

    Thanks for working with me. This is indeed a generic windows/graphics question.

    The drawline() action is done after the controls, and they do repaint after eclipsed by another application window. These are not the problems. Let me clarify the situation with some concrete examples.

    what I have is like this:
    1. there is a form
    2. which contains a panel
    3. the panel contains several instances of a custom user control
    4. the user control contains numerous labels
    5. the lines are draw on the panel connecting the custom user controls, and often the lines cross over some custom user controls

    therefore, the lines and the custom control share the same parent, which is the panel.

    however, the labels on the custom control have a different parent than the lines and apparently follow a different z-order.

    So, when the lines are drawn, they cover most of the custom control, excep where the labels appear, in which case the lines are covered by the labels.

    is this description clear? do you think there is a solution for this? is 500 point the right amount of award for this problem?

    Thanks

    Bruce
    0
     
    LVL 49

    Accepted Solution

    by:
    To be honest, I've never worked with such a scenario.  
    I think that the custom controls are ActiveX controls and I think that the GDI drawing logic can be somewhat unintuitive with ActiveX controls (at least I think I've read other questions where z-order seemed "strangely" ignored in such cases).

    My furst (best) suggestion is to use Spy++ to see if there is something about the Window Style bits and child/parent relationships of the windows that seems out of whack.

    Here is another idea that I'd explore if I were tasked with solving this:  
    I assume that the connection lines are some sort of visual aid to illustrate (for the user) logical connections between buttons or controls.   If so, perhaps the controls themselves do not need to be functional at such time as the lines are displayed.  If so... then perhaps I could draw everything and take a snapshot of the resulting image into a bitmap (or metafile).  Then I'd draw the lines on to the bitmap and display the combined image.  If I needed to allow user interaction with controls, then I'd detect mouse clicks and know that I'd need to re-substitute the original ("real") screen back into place.   This is not all that farfetched... For instance, in Ms Word, a "text box" is only a text box after it is selected, made active, etc.  Until then it just *looks* like one.

    Before going that route, I'd look carefully at all of the window styles used by all of the relevant windows.  Also, I have no idea if you are using SetWindowPos correctly, etc. or if your parent/child relationships are set meaningfully.

    -- Dan
    0
     
    LVL 85

    Expert Comment

    by:Mike Tomlinson
    I can't think of any way to directly solve the z-order problem...

    But along the same lines as DanRollins suggestion, you could possibly draw your lines directly on the DesktopDC using API's.

    Another possiblity is to use ControlPaint.DrawReversibleLine().

    ~IM
    0
     

    Author Comment

    by:bhomass
    Thanks for the comments. It sounds like this z-order business gets hard to manage using winform or ActiveX.

    I believe what you are suggesting involves defining a lot of regions and using hittest to find out which child control is clicked. I have to say this workaround can be a quite major undertaking once the number of controls go up.

    I wish someone could suggests a means of controlling the z-order using the necessary GDI+ api.

    Bruce
    0
     
    LVL 49

    Expert Comment

    by:DanRollins
    Have you used Spy++ (an utility program that comes with Visual Studios) to examine the style bit settings and the parent/child relationships of all of the relevant windows?
    0
     

    Author Comment

    by:bhomass
    Dan

    I don't have spy++ in my VS .Net. I have to install the old version to try it. it may take some times to get to that. I intend to test it out though.

    In the meantime, can we look at a more common scenario to see if you or anyone had similar experience.

    1. a custom user control
    2. contains a label aligned to the top of the control (same Location.Y)
    3. the control OnPaint() method draws a red line around its border

    the control appears with the red line around the border everywhere except where the upper border is covered by the label. this happens even if I call SendToBack() on the label.

    this is actually the same sympton as the previous more complex case. it is due to the fact that the label is a child control and follows its own z-order. there does not seem to be any easy way to alter that. does this sound familiar to anyone? any solutions for this?

    Bruce
    0
     
    LVL 49

    Expert Comment

    by:DanRollins
    It might be possible to re-parent the labels.  As long as they are being drawn last, they will overlap and cover up whatever they are above.

    I think it is a common problem, and it is normally solved by being very precise in setting up child/parent relationships.  Sometimes when the order of drawing is outside of your control, you need to force some screen elements to redraw themselves, even if that uses extra processing and causes screen flicker.
    0
     

    Author Comment

    by:bhomass
    Dan

    I tried the redraw approach already. excuse my ignorance, but I couldn't find a suitable event to trigger the refresh() (which redraws the border lines). The right time to redraw lines would be after the child label controls have been painted. which event of the Parent or child control would that be?

    Thanks

    Bruce
    0
     
    LVL 49

    Expert Comment

    by:DanRollins
    I don't know the answer to that, but there is a very easy way to find out...

    Use Spy++  to record the sequence of messages sent to your window, and find one that would be a good signal on which to key your redraw operation.

    -- Dan
    0
     

    Author Comment

    by:bhomass
    I really have not gotten my questions answered. However, one expert helped pointing something things out. His comments may or may not lead to an answer. I won't know until spending a lot more time researching. is it possible to award partial points to him, and drop this question?
    0
     
    LVL 49

    Expert Comment

    by:DanRollins
    Yes, you can handl that yourself.  Click the [Accept] button next to any comment or click the "split points" link.
    0
     

    Author Comment

    by:bhomass
    split points has the requirements that the total must add up to the original total of 500 points. is there a way to say hand out 250 points for one contribution, and drop the remaining 300?
    0
     

    Author Comment

    by:bhomass
    Yes, please.

    Sorry for the elaborate procedures. I just thought to be fair to the point system, I will reduce the point to indicate that the original intend of the question was not fully satisfied. But it does not diminish my appreciation for your helpful hints.

    Thanks

    0

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Lean Six Sigma Project Manager Certification

    There are many schools of thought around successful project management, but few as highly regarded as the Six Sigma and Lean methods. With 37 hours of learning, this training will explain concrete processes for increasing efficiency and limiting wasted time and effort.

    Article by: Ivo
    C# And Nullable Types Since 2.0 C# has Nullable(T) Generic Structure. The idea behind is to allow value type objects to have null values just like reference types have. This concerns scenarios where not all data sources have values (like a databa…
    Entity Framework is a powerful tool to help you interact with the DataBase but still doesn't help much when we have a Stored Procedure that returns more than one resultset. The solution takes some of out-of-the-box thinking; read on!
    With the advent of Windows 10, Microsoft is pushing a Get Windows 10 icon into the notification area (system tray) of qualifying computers. There are many reasons for wanting to remove this icon. This two-part Experts Exchange video Micro Tutorial s…
    Migrating to Microsoft Office 365 is becoming increasingly popular for organizations both large and small. If you have made the leap to Microsoft’s cloud platform, you know that you will need to create a corporate email signature for your Office 365…

    884 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

    21 Experts available now in Live!

    Get 1:1 Help Now