Can overlapped buttons both receive notification?
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 11 of 11

Thread: Can overlapped buttons both receive notification?

  1. #1
    Join Date
    Aug 2006
    Posts
    508

    Can overlapped buttons both receive notification?

    The apparent answer for this is seemingly 'No' but I am wondering if there is a way or trick.

    I have multiple bitmap buttons of non-square shape. Because of their odd shape I can overlap them and they will still look good on screen, which is what I want - that certain layout.

    The problem is that because underlying button in reality is square (which I am subclassing), the bitmap of one button may overlay with the non-bitmap area of the other button (in the underlying square). This means that 2nd bitmap button will not receive notification because the press is registered with top level window only.

    Is there a way that both windows can receive the notification and check if they are in the hot spot, they will respond? I know this is against windows design and rather look silly to ask but I am wondering if there is some kind of way.

  2. #2
    GCDEF is offline Elite Member Power Poster
    Join Date
    Nov 2003
    Posts
    12,068

    Re: Can overlapped buttons both receive notification?

    I don't know of a conventional way. I suppose you could handle mouse click events in the parent window using PreTranslateMessage, see where the mouse is, enumerate the child windows, see which ones are under the mouse and dispatch the message or call a method yourself. There may be an easier way that I'm not aware of.

  3. #3
    Join Date
    Nov 2000
    Location
    Voronezh, Russia
    Posts
    5,960

    Re: Can overlapped buttons both receive notification?

    Quote Originally Posted by zspirit View Post
    The problem is that because underlying button in reality is square
    This is where your real problem is. You have to learn button creation based on region rather than square bitmap.
    Best regards,
    Igor

  4. #4
    Join Date
    Aug 2006
    Posts
    508

    Re: Can overlapped buttons both receive notification?

    @Igor, yes thats what seem to be the ase but based on something along what GCDEF said, when a button receives click event and it determines its not in the hot spot, could it pass it to any other control which maybe overlapping in its area?

  5. #5
    GCDEF is offline Elite Member Power Poster
    Join Date
    Nov 2003
    Posts
    12,068

    Re: Can overlapped buttons both receive notification?

    Quote Originally Posted by zspirit View Post
    @Igor, yes thats what seem to be the ase but based on something along what GCDEF said, when a button receives click event and it determines its not in the hot spot, could it pass it to any other control which maybe overlapping in its area?
    If it's not in the hot spot, it won't receive the click event, which is why I suggested handling it in the parent window and seeing which window is under the mouse when the button is clicked.

  6. #6
    Join Date
    Aug 2006
    Posts
    508

    Re: Can overlapped buttons both receive notification?

    Quote Originally Posted by GCDEF View Post
    If it's not in the hot spot, it won't receive the click event, which is why I suggested handling it in the parent window and seeing which window is under the mouse when the button is clicked.
    I have implemented the hot spot myself in the button subclass where I am capturing all clicks in PreTranslateMessage() so I do decide there I am not going to care about this mouse click in my control. The question is, is there a way to pass it on to someone else from there!?

  7. #7
    GCDEF is offline Elite Member Power Poster
    Join Date
    Nov 2003
    Posts
    12,068

    Re: Can overlapped buttons both receive notification?

    Quote Originally Posted by zspirit View Post
    I have implemented the hot spot myself in the button subclass where I am capturing all clicks in PreTranslateMessage() so I do decide there I am not going to care about this mouse click in my control. The question is, is there a way to pass it on to someone else from there!?
    There's a hwnd member of the MSG struct that gets passed to PreTranslateMessage. I don't know what happens if you change that to another window, but it's possible that you could put the handle of whatever window you want to get the message, it will route the message appropriately. Certainly worth a try. Otherwise, you could send a message yourself I suppose.

  8. #8
    Join Date
    Dec 2012
    Location
    England
    Posts
    2,328

    Re: Can overlapped buttons both receive notification?

    Once you have received a message in a window handler, you can re-post the message to another window for which you know the window handle.
    All advice is offered in good faith only. You are ultimately responsible for effects of your programs and the integrity of the machines they run on.

  9. #9
    Join Date
    Apr 2000
    Location
    Belgium (Europe)
    Posts
    3,845

    Re: Can overlapped buttons both receive notification?

    It depends on the complexity of what you're doing but the gist of it..

    ALL windows on Windows are inherently rectangular. While it's possible with regionclipping and alpha transparency to give the impression that a window has a non-rectangular shape. This doesn't change that underlying fact.

    If you have a limited number of these overlapping buttons. Then having a simple redirection handler is probably the easiest way (this is being suggested above).

    More complex is making the window conform to a region.

    If you have bitmaps as buttons, then a partial alpha transparent window might be more appropriate with a custom hit-test.

    If you have LOTS of "overlapping buttons" (suppose you wanted to represent a screen full of clickable hexagones), then just having the parent window, WITHOUT child windows, and having the parent figure out which hexagon got clicked with custom drawing for the "clicking" effect is probably the advisable direction. Expect that this will take some work...

  10. #10
    Join Date
    Aug 2006
    Posts
    508

    Re: Can overlapped buttons both receive notification?

    [QUOTE=OReubens;2132901If you have bitmaps as buttons, then a partial alpha transparent window might be more appropriate with a custom hit-test.
    [/QUOTE]
    I am not sure what you mean by partial alpha transparent window..does it mean partially transparent? I guess I am using a different techinque, a mask bitmap.

    I only have 6 buttons and any one can overlap with maximum of 2 buttons. Should I just store reference to those overlapping buttons and passed them the message when applicable? Otherwise I expect a complex logic to determine the handle of windows overlapping.

  11. #11
    Join Date
    Apr 2000
    Location
    Belgium (Europe)
    Posts
    3,845

    Re: Can overlapped buttons both receive notification?

    With partial alpha transparency, I mean that the bitmap has a per-pixel alpha value, where 0 means transparent, 255 means opaque, and any value in between means partially transparent.
    Newer versions of windows have support for that kind of behaviour, although it'll take a bit of work on your end to properly set things up so windows knows what you're trying to do.

    if you have a masked image, then this doesn't count any any way. IN that case, the easiest (assuming limited amount of overlapped buttons) is a custom redirection as mentioned above.
    the click arrivés in the top button, if that button figures out it's outside it's masked area, it redirects the click to either a redirection handler, or to the appropriate button directly.

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  


Azure Activities Information Page

Windows Mobile Development Center


Click Here to Expand Forum to Full Width

This is a CodeGuru survey question.


Featured


HTML5 Development Center