Code:
#include <windows.h>
#include <commctrl.h> //the common controls header file
#pragma comment(lib,"comctl32.lib") //here's that comctl32.lib file
LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam);
int APIENTRY WinMain(HINSTANCE hInstance,HINSTANCE hPrev,LPSTR lpCmdLine,int nCmdShow)
{
WNDCLASSEX wc;
wc.lpfnWndProc = WndProc;
wc.hInstance = hInstance;
wc.lpszClassName = "da class";
wc.cbSize = sizeof (WNDCLASSEX);
wc.hCursor = ::LoadCursor (0, IDC_ARROW);
wc.hbrBackground = reinterpret_cast<HBRUSH> (COLOR_BTNFACE + 1);
wc.style = 0;
wc.cbClsExtra = 0;
wc.cbWndExtra = 0;
wc.hIcon = 0;
wc.hIconSm = 0;
wc.lpszMenuName = 0;
::RegisterClassEx(&wc);
HWND hWnd = ::CreateWindowEx(0,"da class","A window",WS_OVERLAPPED,
200,200,200,200,NULL,NULL,hInstance,NULL);
::ShowWindow(hWnd,nCmdShow);
MSG msg;
while (GetMessage(&msg, NULL, 0, 0))
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
return msg.wParam;
}
LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
{
switch (message)
{
case WM_CREATE:
{
INITCOMMONCONTROLSEX icex;
icex.dwSize = sizeof(INITCOMMONCONTROLSEX);
icex.dwICC = ICC_PROGRESS_CLASS;
InitCommonControlsEx(&icex);
//123 is the id (just like IDC_PROGRESS1)
::CreateWindowEx(0,PROGRESS_CLASS,"Progress bar",WS_CHILD|WS_VISIBLE,25,50,150,50,
hWnd,reinterpret_cast<HMENU>(123),(HINSTANCE)::GetWindowLong(hWnd,GWL_HINSTANCE),NULL);
}
break;
case WM_LBUTTONDOWN:
{
//you clicked the left button...change the progress to 25
SendMessage(GetDlgItem(hWnd,123),PBM_SETPOS,25,0);
}
break;
case WM_RBUTTONDOWN:
{
//you clicked the right button...change the progress to 75
SendMessage(GetDlgItem(hWnd,123),PBM_SETPOS,75,0);
}
break;
case WM_DESTROY:
//bye bye
::PostQuitMessage(0);
return 0;
}
return DefWindowProc(hWnd, message, wParam, lParam);
}