Thread: Concept help

  1. #1

    Concept help

    I've got a conceptual problem ... I'm creating a visual gui designer program, much like design view in vb except that it exports the code for the gui.

    Now, I have an MDI for it. When a new window is made a child window is made inside it, the form. Now the fom can't be moved or resized like a normal window, you need to click it to activate the resize bounding box and then drag a handle in the direction you want to resize it (this will be the same for all controls on the form).

    So anyway, I have the form window. I have made a handle control. But What my problem is, what's the best way to 'attach' the handle control to the form (and subsequent child widnows such as buttons) ??

    I was thinking, that I'd just create the handle control right over the top of it so that if you click it you would really be clicking the handle control because it's over the top of it. But I'm not really sure if this is the best way.

    I'd like some suggestions on how to go about this .. I hope I explained it enough.

  2. #2
    Registered User Codeplug's Avatar
    Join Date
    Mar 2003
    Posts
    4,981
    >> I was thinking, that I'd just create the handle control right over the top of it so that if you click it you would really be clicking the handle control because it's over the top of it. But I'm not really sure if this is the best way.

    Sounds like a reasonable approach to me. The "handle" control can sit right on top of the window it's resizing, sending it appropriate messages to resize itself as the user drags the mouse.

    gg

  3. #3
    Ok, so I've tried this ... but it doesn't work .. well it does but there is an added problem.
    For some reason when you click the handle control the window behind comes to the front.

  4. #4
    erstwhile
    Join Date
    Jan 2002
    Posts
    2,227
    A possible option is to intercept and re-route mouse messages to your 'sizing' control, eg. (test):
    Code:
    MSG Msg;
    while (GetMessage(&Msg,NULL,0,0)>0)
      {
      switch (Msg.message)
        {
        case WM_MOUSEMOVE:
        case WM_LBUTTONDOWN:
        case WM_LBUTTONUP:
        case WM_RBUTTONDOWN:
        case WM_RBUTTONUP:
          if (Msg.hwnd==hAttached)
            {
            Msg.hwnd=hSizingCntrl;
            }
        }
        TranslateMessage(&Msg);
        DispatchMessage(&Msg);
      }
    where hAttached is the control your 'sizing' control is attached to and hSizingCntrl is the 'sizing' control itself. A WH_GETMESSAGE hook might be a better way to go with this approach (see also Hooks).
    CProgramming FAQ
    Caution: this person may be a carrier of the misinformation virus.

  5. #5
    Oh, cool ...

    I think I get what I have to do now, I'll try it and see.

  6. #6
    Actually, I don't think I will ... There has to be a simpler way.

    I use the WM_NOTIFYPARENT message to attach a handle and it's there, my only problem is keeping it on top ... I've tried SendWindowToTop() at various times and SetWindowPos using HWND_TOPMOST but that didn't stop it from moving behind the window it's attached to..

  7. #7
    erstwhile
    Join Date
    Jan 2002
    Posts
    2,227
    By re-routing mouse messages you shouldn't have to worry about the z-order. If you make the 'sizing' window a little bigger than the 'attached' control and give the 'sizing' window a NULL or HOLLOW_BRUSH background to make it transparent, you need only draw some sort of custom border for it and the 'attached' control will be visible within the 'sizing' window's borders.

    Still, that approach may not fit with your design. Good luck anyway.
    CProgramming FAQ
    Caution: this person may be a carrier of the misinformation virus.

  8. #8
    Well it is a little bigger, and it has a border but it also has little handles which I've made using InvertRect() around the window it's attached to. A little bit of the sizing handles actually fall behind the window. I could live with it but I was just trying to find a way to fix it.

    I could implement what your suggestion, it'd require some restructuring though..

  9. #9
    Registered User Codeplug's Avatar
    Join Date
    Mar 2003
    Posts
    4,981
    How does your control work?
    Is it a single window that covers the entire window which it is resizing?
    Or is it just a tiny little window which is as big as the resizing graphic?

    Here's how I imagined it - the green window is the control window and the red window is the window that's being resized. The green window is alway ontop of the red window (oppisite of what's shown).
    Since the green window completely overlaps the red window, it receives all the mouse events. And since the green window doesn't paint himself where the red window is, the red window essentially "shows through" (you might have to ask the red window to redraw himself before rendering the green window).

    gg

  10. #10
    Here's a screenie of what I'm talking about --- (1 is before clicking anywhere on the control, 2 is after)

  11. #11
    I guess I could make the handles completely outside of the window being resized, probably easier (ie this is no problem then) ..

  12. #12
    Ok, I've made it so that or windows are a child of a handle window ... I have a new problem though ..

    I'm catching the WM_PARENTNOTIFY message when a user clicks an a child window (say a button for instance) ... so when the user clicks the button it sends the WM+PARENTNOTIFY message which I then check for WM_LBUTTON down and if it's there I either show or hide the drag handles.

    My problem is that the WM_PARENTNOTIFY message is sent so many times so quickly! I get a few dozen messages with just a single mouse click and as such the handles are shown and hiden so many times so quickly it becomes garbled and generally ends up in the wrong state anyway.

    Is there a better way?

  13. #13
    lol I guess you deleted your post --

    Use a boolean - if (handle_is_set==false) then show_handle would seem t
    o be the simplest.
    Yeah I do, but I get the message so fast that it goes on an off a few dozen times..

  14. #14
    erstwhile
    Join Date
    Jan 2002
    Posts
    2,227
    >>lol I guess you deleted your post <<

    You were quick to catch that one - I deleted it within a few seconds because it occurred to me that you would have already tried something like that..

    Perhaps, since only one control or window will ever be 'attached' to your 'handle' window, you could use the 'attached' control's handle or identifier, only changing the draw state if a change of 'attached' control is indicated?
    CProgramming FAQ
    Caution: this person may be a carrier of the misinformation virus.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Question about concept of class
    By Roy01 in forum C++ Programming
    Replies: 6
    Last Post: 11-23-2006, 01:15 AM
  2. MUD Concept Question
    By mrpickle in forum Game Programming
    Replies: 3
    Last Post: 12-01-2003, 12:45 PM
  3. help !!concept of class templates
    By sanju in forum C++ Programming
    Replies: 1
    Last Post: 03-20-2003, 09:12 AM
  4. linkedlist concept please!
    By SAMSAM in forum C Programming
    Replies: 3
    Last Post: 03-15-2003, 01:50 PM
  5. basic doubt in pointer concept
    By sanju in forum C Programming
    Replies: 1
    Last Post: 10-24-2002, 11:35 PM