Jump to content
  • Advertisement
Sign in to follow this  
Dookie

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.

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

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 this post


Link to post
Share on other sites
Advertisement
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!

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!