# Easy slider control question...

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

## Recommended Posts

Hey guys, here's another easy one for ya! I'm working on a little Windows program that is nothing but a single 'DialogBox()'. I have all of the controls working on it except for the slider control... Every time I 'draw' a slider control on my dialog box from within my VisualC IDE, then the dialog box won't appear when I compile and run it. What I mean by that is, I click 'Debug'->'Start' and the program spits stuff into the debug window that looks the same as if I'd clicked the 'Exit' button in my dialogbox (although in this instance, the dialogbox never appeared). But if I delete the slider control, the dialog box appears and functions just fine. However, I really need that slider control to finish my project! In my program, I have this (but it doesn't make any difference; the dialog box still won't appear if I have a slider control in it):
VOID OnInitDialog( HWND hDlg )
{
HWND hFreqSlider    = GetDlgItem( hDlg, IDC_VOLSLIDER );
PostMessage( hFreqSlider, TBM_SETRANGEMAX, TRUE, 100 );
PostMessage( hFreqSlider, TBM_SETRANGEMIN, TRUE, 0 );
}
Would any of you guys help me get a slider control into my dialog box? I don't know much about Windows programming, so don't be suprised if it's a silly simple solution that gets me on my way. Let me know if you need to see any more of my code to come up with a solution. Thanks in advance for the help!

##### Share on other sites
No ideas, huh? Probably because I didn't post enough info... Here's something to try:

1) Create a new VisualC empty project in Visual Studio.

2) Add a new item under 'Source Files' (.cpp file) and copy this code into it:

#include	<windows.h>#include	<commdlg.h>#include	"resource.h"#include	"commctrl.h"INT_PTR CALLBACK MainDlgProc( HWND hDlg, UINT msg, WPARAM wParam, LPARAM lParam );INT APIENTRY WinMain( HINSTANCE hInst, HINSTANCE hPrevInst, LPSTR pCmdLine, INT nCmdShow ){	// Display the main dialog box.	DialogBox( hInst, MAKEINTRESOURCE(IDD_DIALOG1), NULL, MainDlgProc );	return TRUE;}INT_PTR CALLBACK MainDlgProc( HWND hDlg, UINT msg, WPARAM wParam, LPARAM lParam ){	// HRESULT hr;	HWND	hwndTrack;	switch( msg ) 	{		case WM_INITDIALOG:			hwndTrack = GetDlgItem( hDlg, IDC_SLIDER1 );			SendMessage(hwndTrack,				TBM_SETRANGE, 				TRUE,					// redraw flag 				MAKELONG(0, 1000));		// min. & max. positions			break;		case WM_COMMAND:			switch( LOWORD(wParam) )			{				case IDOK:					EndDialog( hDlg, IDCANCEL );					break;				case IDCANCEL:					EndDialog( hDlg, IDCANCEL );					break;				default:					return FALSE;	// Didn't handle message			}			break;		default:			return FALSE;			// Didn't handle message	}	return TRUE;					// Handled message}

3) Under 'Resource Files' in your Solution Explorer, add a simple dialog box. Make sure it has an OK (ID = 'IDOK') and CANCEL (ID = 'IDCANCEL') button in it.

4) Compile (build) your project, and then run it under 'Debug'. You will see a dialog box with an OK and Cancel button on it. Press OK or CANCEL to close the dialog box and return to Visual Studio.

5) Now, look at your dialog box in Visual Studio and choose 'Slider Control' in the Dialog Editor. Draw a slider control onto your dialog box. After you do so, give it the ID of 'IDC_SLIDER1'.

6) Compile (build) your project, and then run it under 'Debug'. No dialog box! It runs without displaying anything, then immediately returns to Visual Studio.

---

Now that y'all know exactly what I'm doing, can anybody show me what I'm doing wrong? I've been banging my head against the monitor for the past couple of days over this, and I don't think my monitor (or my head) can take much more. Thanks!

1. 1
Rutin
36
2. 2
3. 3
4. 4
5. 5

• 12
• 14
• 9
• 9
• 14
• ### Forum Statistics

• Total Topics
633344
• Total Posts
3011438
• ### Who's Online (See full list)

There are no registered users currently online

×