Sign in to follow this  

A windows Api question

This topic is 3593 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Ok this questions probaly not going to be as simple as it sounds but here it goes. Im writing a MySql Database manager, for retreaving results i want to know how alot of programs have controls that your can scroll down too... hmm how to put it ok heres an example. You got a window with a scroll bar and if you scroll down there is a button and a bunch of other controls im woundering how to set that up -.^ im still not sure if my question is clear but if someone knows what im getting at please let me know what needs to be done. Regards Jouei

Share this post


Link to post
Share on other sites
You can create a Window with scroll bars by specifying the WS_VSCROLL|WS_HSCROLL (V for vertical, H for horizontal) styles when creating your Window with CreateWindow or CreateWindowEx. The scroll bar controls will then send WM_HSCROLL and WM_VSCROLL messages to your window when the user interacts with them, which you can process to determine how much the scroll bar has moved. You can also use GetScrollInfo and SetScrollInfo to retrieve or set the scroll bar's position.

As for the other controls, they're all documented here. They're generally created by calling CreateWindow and specifying the control's pre-made window class, and also specifying your window as the parent class. If you're using controls in a dialog, you can simply use Visual Studio's dialog editor to drag controls onto your dialog template. The controls are the automatically created when your create the dialog from the template.

I should warn you...handling controls in straight Win32 can get tedious very quickly. You may want to consider using a C++ library like WTL to make your life easier. A .NET language with Windows Forms will also probably give you less of a headache than anything using native C++.

Share this post


Link to post
Share on other sites
Thanks for your reply its not compltly what i meant unfortunitly.

Basicly i know how to create any control needed its like when your own a web site and controls are offscreen and then you move the scroll bar controls are then on screen the question is does win32 api keep track of where the controls are for you and reacts with the scroll bar accordingly if so how can one set that up and if not does that mean id have to get the scroll bars postion and check it manualy for movment and show and hide controls and move controls based on its movement.

Regards Jouei.

Share this post


Link to post
Share on other sites
Quote:
Original post by Jouei
Thanks for your reply its not compltly what i meant unfortunitly.

Basicly i know how to create any control needed its like when your own a web site and controls are offscreen and then you move the scroll bar controls are then on screen the question is does win32 api keep track of where the controls are for you and reacts with the scroll bar accordingly if so how can one set that up and if not does that mean id have to get the scroll bars postion and check it manualy for movment and show and hide controls and move controls based on its movement.

Regards Jouei.


Win32 doesn't handle any of that for you. Win32 is basically the lowest-level approach you can take to programming Windows, it expects you to explicitly tell it what to do in almost every case. Like I said in my post above, the scroll bar controls will only tell you how much the user has moved them. It's up to your application to respond accordingly, which in your case would probably involve moving the controls with SetWindowPos. Each control will keep track of its own position (since they're all a window and every window has a position), but you'll be responsible for setting that position.

Once again you may want to take a high-level approach to your UI if you're looking for things to just happen automagically for you. Windows Forms can significantly ease the burden, however you'd have to find a way to make your managed code interact with any un-managed code you've already written. There are also 3rd-party libraries for handling GUI elements, however I'm not really familiar with any of them so I can't recommend one.

Share this post


Link to post
Share on other sites
Hmm well i though that was the case witch is not so bad.. Windows Forms sounds intresting but i know nothing about them.. As for the magjority of my code Compents like amangaing MySql and an error manager is imported Via 2 Differnt Run time Dll's.

I guess i kinda of just got myself stuck to Win Api since it something im used to as for my Programing prefrence it is C++.

Thanks for your replys ill tak ea look into windows form but im not sure ill use them i may i may not im just not all to sure how to go about useing them for the most part.

Regards Jouei.

Share this post


Link to post
Share on other sites
If you're using visual studio it should do all the scrolling of the window for you with the default message pump actions (someone please correct me if I'm wrong). Also if you are using something like Visual C++ 6.0 or lower to make unmanaged code you could consider using a much easier way called MFC. MFC is the Microsoft Foundation Classes that wraps a lot of the Win32 API functionality under classes. If you are using something like Dev C++ then you probably are looking into hand coding your form for scrolling.

To explain a bit about how scrolling works (hopefully this helps). If you have a window with too many controls to see on the window at once it will not automatically set up a scroll window feature for you, this is why some people like Win API, you can design everything by hand. You instead will have to use MJP's advice, when you use that advice you will enable your window to scroll Vertically (Up and Down) or Horizontally (Left and Right) and you do not need to worry about hiding and displaying the controls they are clipped when out of view. Also if you have to hand code the scrolling mechanism then you still will not have to worry about hiding and showing controls, that will still happen automatically with clipping.

Now from my personal experience if you have so many controls on your window that you need to scroll them you have a different problem. A problem of organization, try increasing the window size or grouping controls under different windows or a tab control or menus or simlar ways of logical control seperation. I know scrollable windows are pretty much against Microsoft's new policy for good user interfaces.

Share this post


Link to post
Share on other sites

This topic is 3593 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this