The MASM Forum Archive 2004 to 2012

General Forums => The Campus => Topic started by: NoCforMe on December 10, 2011, 12:32:43 AM

Title: Up-down controls are easy!
Post by: NoCforMe on December 10, 2011, 12:32:43 AM
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 (http://msdn.microsoft.com/en-us/library/hh298353%28v=VS.85%29.aspx) ("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 (http://software.intel.com/sites/products/documentation/hpc/compilerpro/en-us/fortran/win/compiler_f/bldaps_for/win/bldaps_use_spinctl.htm) 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):

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.