trackbar

Hello everybody.
So I have this program, which should show me a hello world statement and a trackbar somewhere. For some reason trackbar doesn't show. What's wrong here ? Also, I was wondering how treat this type of errors, when program compiles, but something just doesn't show in the window.

Code:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
#include <windows.h>
#include <CommCtrl.h>
#include <iostream>

#pragma comment(lib, "comctl32.lib")

#define ID_TRACKBAR 41231

LRESULT CALLBACK WndProc( HWND hwnd, UINT message, WPARAM wparam, LPARAM lparam );
int WINAPI WinMain( HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR szCmdLine, int iCmdShow );
HWND WINAPI CreateTrackbar( HWND hwndDlg, UINT iMin, UINT iMax, UINT iSelMin, UINT iSelMax );

int WINAPI WinMain( HINSTANCE hInstance,
                    HINSTANCE hPrevInstance,
                    LPSTR szCmdLine,
                    int iCmdShow )
{
    
    #pragma region part 1

    WNDCLASS wc;
    wc.cbClsExtra = 0;
    wc.cbWndExtra = 0;
    wc.hbrBackground = (HBRUSH)GetStockObject( WHITE_BRUSH );  
    wc.hCursor = LoadCursor( NULL, IDC_ARROW ); 
    wc.hIcon = LoadIcon( NULL, IDI_APPLICATION );    
    wc.hInstance = hInstance;      
    wc.lpfnWndProc = WndProc;  
    wc.lpszClassName = TEXT("Philip");  
    wc.lpszMenuName = 0;
    wc.style = CS_HREDRAW | CS_VREDRAW; 
    RegisterClass( &wc );

	HWND hwnd = CreateWindow(TEXT("Philip"), TEXT("m0ving BOX"), WS_BORDER, 100, 100, 500, 500, NULL, NULL, hInstance, NULL);

	ShowWindow(hwnd, SW_SHOW);

    UpdateWindow(hwnd);

    #pragma endregion

    #pragma region part 2

    MSG msg;
    while( GetMessage( &msg, NULL, 0, 0 ) )
    {
        TranslateMessage( &msg );
        DispatchMessage( &msg );
    }

    #pragma endregion

    return msg.wParam;
}

LRESULT CALLBACK WndProc(   HWND hwnd,
                            UINT message,
                            WPARAM wparam,
                            LPARAM lparam )
{

    switch( message )
    {
    case WM_CREATE:

		CreateTrackbar( hwnd, 10, 100, 10, 100 );

        return 0;
        break;

    case WM_PAINT:
        {

            HDC hdc;
            PAINTSTRUCT ps;
            hdc = BeginPaint( hwnd, &ps );

			TCHAR szBuffer[50] = {0};
			int iLength = 0;
			iLength = wsprintf(szBuffer, L"Hello World!");
			TextOut( hdc , 10 , 10 , szBuffer , iLength );
            
            EndPaint( hwnd, &ps );
        }
        return 0;
        break;

    case WM_DESTROY:
        PostQuitMessage( 0 ) ;
        return 0;
        break;

        
    }

    return DefWindowProc( hwnd, message, wparam, lparam );
}

HWND WINAPI CreateTrackbar( 
    HWND hwndDlg,  // handle of dialog box (parent window) 
    UINT iMin,     // minimum value in trackbar range 
    UINT iMax,     // maximum value in trackbar range 
    UINT iSelMin,  // minimum value in trackbar selection 
    UINT iSelMax )  // maximum value in trackbar selection 
{

    HWND hwndTrack = CreateWindowEx( 
        0,                               // no extended styles 
        TRACKBAR_CLASS,                  // class name // HERE was the problem.
        L"Trackbar Control",              // title (caption) 
        WS_CHILD | 
        WS_VISIBLE | 
        TBS_AUTOTICKS | 
        TBS_ENABLESELRANGE,              // style 
        100, 100,                          // position 
        200, 30,                         // size 
        hwndDlg,                         // parent window 
        (HMENU)ID_TRACKBAR,                     // control identifier 
        GetModuleHandle(NULL),                         // instance 
        NULL                             // no WM_CREATE parameter 
        );

    SetFocus(hwndTrack);

    return hwndTrack; 
} 


Also, i was wondering why i have to make every string "long" (put a "L" behind it), to make it work. I'm using MS Visual 2010.

EDIT: At last it worked. Class name should be "TRACKBAR_CLASS". Also for anyone wondering how to get rid of the "L" in front of every string: Press ALT+F7 to open the properties, and navigate to Configuration Properties > General. Switch Character Set to "Use Multi-Byte Character Set". My project used normal Unicode instead if this.
Last edited on
You'd probably get a better response posting this in the Windows forums.

For info, L doesn't denote "long". It means it's a wide string literal. That is, every char in the string is actually a wchar_t.
Topic archived. No new replies allowed.