简体   繁体   中英

How to show more than 50 push buttons on a window?

I have created a Window and then, created 50 buttons on this Window but I can only see 10 buttons on my window. Rest are out of view since I am not able to scroll the window down.

I have added auto scroll to window by adding

WS_VSCROLL | WS_HSCROLL | ES_AUTOVSCROLL | ES_AUTOHSCROLL

to Window Style parameter of CreateWindowEx function. By doing this, I can see a scroll on the window but this scroll is not movable.

What is the possible and simple solution to add a auto scroll to window in order to see all the 50 buttons in such a situation.

您将必须处理WM_VSCROLL和WM_HSCROLL消息。

You must handle the button messages of your scrollbar. You enabled the scrollbar by using WS_VSCROLL | WS_HSCROLL WS_VSCROLL | WS_HSCROLL adn you already noted that you can see them. However using ES_AUTOVSCROLL | ES_AUTOHSCROLL ES_AUTOVSCROLL | ES_AUTOHSCROLL doesn't magically mean that the window will scroll. These flags are for edit boxes, so they automatically scroll when characters are added. Your window doesn't recognize these.

So what you must do is to write some code in your message handler when the user clicks the buttons on the scrollbar, to move the window around on your own.

Since using WinAPI directly is not exactly easy, I would recommend to use a GUI library like wxWidgets or QT, which will reduce errors and make your life easier, as there are already a lot features implemented which you might use.

If you insist on WinAPI for whatever reason, you must probably write a lot of code on your own..

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM