Ayse
Ayse

Reputation: 2754

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.

Upvotes: 0

Views: 94

Answers (2)

Jack
Jack

Reputation: 761

you will have to handle WM_VSCROLLand WM_HSCROLL messages.

Upvotes: 1

Devolus
Devolus

Reputation: 22094

You must handle the button messages of your scrollbar. You enabled the scrollbar by using WS_VSCROLL | WS_HSCROLL adn you already noted that you can see them. However using 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..

Upvotes: 0

Related Questions