tags:

views:

526

answers:

3

just want to know how to add an spin control ( in another name, up/down control ) in the dialog box using C program (win32 / code::block / mingw compiler)

A: 

Take a look at the example here

Naveen
but how to add it to dialog box ?
TuxGeek
A: 

It depends. There are two ways to create a dialog. Programmatically, or via a dialog resource. In the first case, you call CreateDialogIndirect, in the second case CreateDialog. I assume you call CreateDialogIndirect since you mention "in C". In the dialog box template you use, simply add the spin control. You will need to identify it by name in DLGTEMPLATEEX.windowClass.

MSalters
+1  A: 

Simplest way is by using a resource editor to design your dialog. Code::Blocks doesn't come with one, but ResEdit is one I've used.

If you are editing an .rc file by hand, you'd add a line similar to the following within the dialog definition section:

CONTROL         "", IDC_SPIN1, UPDOWN_CLASS, UDS_ARROWKEYS, 7, 22, 11, 14

If you want to add it programatically, you can do so through the CreateWindow API function, e.g.

HWND hwndUpDown = CreateWindow(UPDOWN_CLASS, NULL, 
                        WS_CHILD | WS_VISIBLE | UDS_ARROWKEYS,
                        7, 22, 11, 14, 
                        hwndDlg, NULL, hInst, NULL);

where the hwndDlg parameter is the HWND of your dialog window. A good place to call this is when you handle the WM_INITDIALOG message for the dialog.

Steve Beedie
ResEdit is very useful
TuxGeek