News:

MASM32 SDK Description, downloads and other helpful links
MASM32.com New Forum Link
masmforum WebSite

Up-down controls are easy!

Started by NoCforMe, December 10, 2011, 12:32:43 AM

Previous topic - Next topic

NoCforMe

I added another Windows control gizmo to my repertoire, and it wasn't hard at all. I found out how to use up-down controls (aka "spinner" controls). And it's a lot easier than some of what I read online led me to believe.

I started out at MSDN, of course, which has a lot of information about these controls (not all of it accurate, unfortunately!). There I learned how an up-down control uses an adjacent control (like an edit box) as a "buddy" control. But after reading this page ("How to Create Up-Down Controls"), I still had no idea how you "glue" these two controls together to make one operating unit. I thought it would be horribly difficult to actually implement these useful controls.

Not so. For one thing, that page creates the controls "by hand", using CreateWindowEx(), which gives the programmer a lot of low-level stuff to deal with.

This page was the one that finally clued me in to how to make this control work:
QuoteWhen the "Auto buddy" style is set, the Spin control automatically uses the previous control in the dialog box tab order as its buddy window.

Here's the recipe I came up with (see attached .zip file below):


  • Easiest way to create up-down controls is by using a resource editor (I use ResEd, a freebie which I got through this site). Create an edit control, then create an up-down control immediately adjacent to the edit box (left or right).
  • Important: The up-down control must have a tab index 1 greater than the edit control. In other words, it must be one control behind the edit box in tab order. (This is easily done with any resource editor.)
  • Be sure to set the following two flags for the up-down control:
    • UDS_AUTOBUDDY
    • UDS_SETBUDDYINT
That's pretty much it. After this, you can use the up-down control as you would any other edit control, using GetDlgItemInt() to read it and SetDlgItemInt() to set its contents. (This example is for a simple numeric control; while you can use up-down controls in other settings, like with listboxes, I don't know how to do that yet.)

To set the upper and lower limit of the up-down control's range, send the UDM_SETRANGE message to the control.

Attached example creates a dialog box with a single up-down control in it.

Have fun.