Free MD2 Model Viewer
Click here to go to the MD2View program





Source code for

Progress Bars

Listing of resource.h

#define IDI_ICON 101 #define IDB_TEST 1001 #define IDT_TIMER 1002 #define IDT_PROGRESS_TIMER 1003 #define IDPB_PROGRESS_BAR 1004

Listing of resource.rc

#include "resource.h" IDI_ICON ICON "icon.ico"

Listing of main.cpp

// Win32 Tutorial (Progress Bars) // Alan Baylis 2004 #include <windows.h> #include <commctrl.h> #include "resource.h" const char ClassName[] = "MainWindowClass"; HWND hWndButton; HWND hWndProgressBar; LRESULT CALLBACK WndProc( HWND hWnd, UINT Msg, WPARAM wParam, LPARAM lParam ) { switch (Msg) { case WM_CREATE: { hWndButton = CreateWindowEx( 0, "BUTTON", "Set Timer", WS_VISIBLE | WS_CHILD | BS_DEFPUSHBUTTON, 10, 10, 100, 20, hWnd, (HMENU)IDB_TEST, (HINSTANCE)GetWindowLong(hWnd, GWL_HINSTANCE), NULL); hWndProgressBar = CreateWindowEx( 0, PROGRESS_CLASS, (LPSTR)NULL, WS_VISIBLE | WS_CHILD, 10, 50, 200, 20, hWnd, (HMENU)IDPB_PROGRESS_BAR, (HINSTANCE)GetWindowLong(hWnd, GWL_HINSTANCE), NULL); if (!hWndProgressBar) MessageBox(NULL, "Progress Bar Failed.", "Error", MB_OK | MB_ICONERROR); SendMessage(hWndProgressBar, PBM_SETRANGE, 0, MAKELPARAM(0, 9)); SendMessage(hWndProgressBar, PBM_SETSTEP, (WPARAM)1, 0); } break; case WM_TIMER: { switch ((UINT)wParam) { case IDT_TIMER: { KillTimer(hWnd, IDT_TIMER); KillTimer(hWnd, IDT_PROGRESS_TIMER); MessageBox(NULL, "Timer Activated", "Success", MB_OK | MB_ICONINFORMATION); } break; case IDT_PROGRESS_TIMER: SendMessage(hWndProgressBar, PBM_STEPIT, 0, 0); break; } } break; case WM_COMMAND: { switch(LOWORD(wParam)) { case IDB_TEST: { switch(HIWORD(wParam)) { case BN_CLICKED: { if (SetTimer(hWnd, IDT_TIMER, 5000, (TIMERPROC)NULL)) { SetTimer(hWnd, IDT_PROGRESS_TIMER, 500, (TIMERPROC)NULL); MessageBox(NULL, "Timer set for 5 seconds", "Success", MB_OK | MB_ICONINFORMATION); } else MessageBox(NULL, "Timer failed", "Error", MB_OK | MB_ICONERROR); } break; } } break; } return 0; } break; case WM_CLOSE: DestroyWindow(hWnd); break; case WM_DESTROY: PostQuitMessage(0); break; default: return (DefWindowProc(hWnd, Msg, wParam, lParam)); } return 0; } INT WINAPI WinMain( HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, INT nCmdShow ) { InitCommonControls(); WNDCLASSEX wc; wc.cbSize = sizeof(WNDCLASSEX); wc.style = 0; wc.lpfnWndProc = (WNDPROC)WndProc; wc.cbClsExtra = 0; wc.cbWndExtra = 0; wc.hInstance = hInstance; wc.hIcon = LoadIcon(hInstance, MAKEINTRESOURCE(IDI_ICON)); wc.hIconSm = LoadIcon(hInstance, MAKEINTRESOURCE(IDI_ICON)); wc.hCursor = LoadCursor(NULL, IDC_ARROW); wc.hbrBackground = (HBRUSH)(COLOR_WINDOW + 1); wc.lpszMenuName = NULL; wc.lpszClassName = ClassName; if (!RegisterClassEx(&wc)) { MessageBox(NULL, "Failed To Register The Window Class.", "Error", MB_OK | MB_ICONERROR); return 0; } HWND hWnd; hWnd = CreateWindowEx( WS_EX_CLIENTEDGE, ClassName, "Progress Bars", WS_OVERLAPPEDWINDOW, CW_USEDEFAULT, CW_USEDEFAULT, 240, 120, NULL, NULL, hInstance, NULL); if (!hWnd) { MessageBox(NULL, "Window Creation Failed.", "Error", MB_OK | MB_ICONERROR); return 0; } ShowWindow(hWnd, SW_SHOW); UpdateWindow(hWnd); MSG Msg; while (GetMessage(&Msg, NULL, 0, 0)) { TranslateMessage(&Msg); DispatchMessage(&Msg); } return Msg.wParam; }


Copyright © 1998 - 2010 Alan Baylis, All Rights Reserved