Results 1 to 11 of 11

Thread: WS_CHILD follow scrollable parent window ?

  1. #1

    Thread Starter
    Fanatic Member
    Join Date
    Nov 2013
    Posts
    658

    WS_CHILD follow scrollable parent window ?

    Hi all,

    i am creating a small BUTTON window using CreateWindowEx api and setting its parent to the form window.

    The newly created child button is added successfully to the form's client area as expected but when I scroll the parent window, the child button remains in its initial position and doesn't follow the scrolling.

    Is there a window style bit that I should set in the parent or in the child window so parent and child become synchronized when scrolling the parent form?

    Thanks.

  2. #2
    PowerPoster Elroy's Avatar
    Join Date
    Jun 2014
    Location
    Near Nashville TN
    Posts
    9,853

    Re: WS_CHILD follow scrollable parent window ?

    This is a tricky thing to do. I'll put together a little sample project where I'm doing this. Give me a few.
    Any software I post in these forums written by me is provided "AS IS" without warranty of any kind, expressed or implied, and permission is hereby granted, free of charge and without restriction, to any person obtaining a copy. To all, peace and happiness.

  3. #3
    PowerPoster Elroy's Avatar
    Join Date
    Jun 2014
    Location
    Near Nashville TN
    Posts
    9,853

    Re: WS_CHILD follow scrollable parent window ?

    Ok, here's a little demo project that shows how I do it. It does use subclassing so be careful. Ideally, you'd always shut down your program by closing all its forms, as that'd protect the IDE.

    EDIT: You know? Maybe I missed the point. When I initially read your post, I was thinking the non-client area. For the client area, why not just create the controls with the IDE tools you have?
    Attached Files Attached Files
    Any software I post in these forums written by me is provided "AS IS" without warranty of any kind, expressed or implied, and permission is hereby granted, free of charge and without restriction, to any person obtaining a copy. To all, peace and happiness.

  4. #4

    Thread Starter
    Fanatic Member
    Join Date
    Nov 2013
    Posts
    658

    Re: WS_CHILD follow scrollable parent window ?

    Quote Originally Posted by Elroy View Post
    Ok, here's a little demo project that shows how I do it. It does use subclassing so be careful. Ideally, you'd always shut down your program by closing all its forms, as that'd protect the IDE.

    EDIT: You know? Maybe I missed the point. When I initially read your post, I was thinking the non-client area. For the client area, why not just create the controls with the IDE tools you have?
    Thanks.

    Using native vb form controls will defeat the purpose of what I am trying to do which is to make this work with a child win32 control created from scratch in order to learn if & how this can be done.

    I can subclass the parent window and intercept the scrolling message and reposition the child button accordingly but I thought there might be a window Style or Extended Style that I could set to make child and parent synchronized.

    I wonder how vb does this behind the scenes with the forms controls.
    Last edited by JAAFAR; Nov 23rd, 2021 at 12:04 PM.

  5. #5
    The Idiot
    Join Date
    Dec 2014
    Posts
    2,721

    Re: WS_CHILD follow scrollable parent window ?

    if u want to create custom buttons, why not just skip the hassle with child-forms and other outdated component and instead create your own using any of the graphic engine we have such as gdi/cairo/d2d/directx etc.
    that will give u more freedom and also stability.

  6. #6

    Thread Starter
    Fanatic Member
    Join Date
    Nov 2013
    Posts
    658

    Re: WS_CHILD follow scrollable parent window ?

    Quote Originally Posted by baka View Post
    if u want to create custom buttons, why not just skip the hassle with child-forms and other outdated component and instead create your own using any of the graphic engine we have such as gdi/cairo/d2d/directx etc.
    that will give u more freedom and also stability.
    As I said, I am just wanting this for the sake of learning and to see if\how this can be done.

    Thanks anyway for you suggestion.

  7. #7
    PowerPoster Elroy's Avatar
    Join Date
    Jun 2014
    Location
    Near Nashville TN
    Posts
    9,853

    Re: WS_CHILD follow scrollable parent window ?

    Basically, it sounds like you're trying to do what Krool has already done for us.

    Krool has put in a tremendous amount of work giving us a complete set of controls that are created from scratch. See the CodeBank for his work, or you can look at my onesie-twosie examples of his work where I've peeled it apart into individual controls.

    It will take some work on your part to just follow through the code on one of his controls, but it does seem like that's what you're wanting.
    Any software I post in these forums written by me is provided "AS IS" without warranty of any kind, expressed or implied, and permission is hereby granted, free of charge and without restriction, to any person obtaining a copy. To all, peace and happiness.

  8. #8

    Thread Starter
    Fanatic Member
    Join Date
    Nov 2013
    Posts
    658

    Re: WS_CHILD follow scrollable parent window ?

    Quote Originally Posted by Elroy View Post
    Basically, it sounds like you're trying to do what Krool has already done for us.

    Krool has put in a tremendous amount of work giving us a complete set of controls that are created from scratch. See the CodeBank for his work, or you can look at my onesie-twosie examples of his work where I've peeled it apart into individual controls.

    It will take some work on your part to just follow through the code on one of his controls, but it does seem like that's what you're wanting.
    Thanks for the info. I will take a look at Krool's work.

  9. #9
    PowerPoster wqweto's Avatar
    Join Date
    May 2011
    Location
    Sofia, Bulgaria
    Posts
    5,120

    Re: WS_CHILD follow scrollable parent window ?

    Quote Originally Posted by JAAFAR View Post
    . . . but when I scroll the parent window, the child button . . .
    Which API do you use to scroll tha parent window?

    Sending WM_MOUSEWHEEL messages to a hWnd does not scroll anything per se. It's each window's custom drawing routines responsability to adjust virtual viewport or top index or whatever method they use internally to implement visual scrolling.

    Do you offset parent window's client area somehow and expect child windows to recognize something has changed in the parent drawing settings?

    The easiest 100% working, no lagging method to implement child controls scrolling is to place a *second* container inside your parent window which will server as a virtual canvas (the whole area to be explored) so you can reposition it on scroll notifications into negative coords and emulate scrolling of the parent window "viewport".

    cheers,
    </wqw>

  10. #10

    Thread Starter
    Fanatic Member
    Join Date
    Nov 2013
    Posts
    658

    Re: WS_CHILD follow scrollable parent window ?

    Quote Originally Posted by wqweto View Post
    The easiest 100% working, no lagging method to implement child controls scrolling is to place a *second* container inside your parent window which will server as a virtual canvas (the whole area to be explored) so you can reposition it on scroll notifications into negative coords and emulate scrolling of the parent window "viewport".
    </wqw>
    That sounds like a good idea to avoid lagging. Never done anything like that before but I will try to give it a shot and see.

    Thanks

  11. #11
    Hyperactive Member
    Join Date
    Jun 2016
    Location
    EspaƱa
    Posts
    506

    Re: WS_CHILD follow scrollable parent window ?


Posting Permissions

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



Click Here to Expand Forum to Full Width