TrackBar
Visual C++ 2005 Express Edition
Windows Server 2003 SP1 Platform SDK
Windowsアプリケーション / 空のプロジェクト
TrackBar.c
// マルチバイト文字セット #include
#include
#include
#define APPNAME "TrackBar" // グローバル変数 static HINSTANCE g_hInstance; static HWND g_hTrack; static HWND g_hLabel; // プロトタイプ宣言 LRESULT CALLBACK WndProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam); void OnHScroll(); void OnCreate(HWND hWnd); void Trace(const char *pcFormat, ...); int WINAPI WinMain( HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow) { char acAppName[] = APPNAME; WNDCLASSEX wcex; HWND hWnd; MSG msg; g_hInstance = hInstance; wcex.cbSize = sizeof(WNDCLASSEX); wcex.style = 0; wcex.lpfnWndProc = WndProc; wcex.cbClsExtra = 0; wcex.cbWndExtra = 0; wcex.hInstance = g_hInstance; wcex.hIcon = LoadIcon(NULL, IDI_APPLICATION); wcex.hCursor = LoadCursor(NULL, IDC_ARROW); wcex.hbrBackground = (HBRUSH)(COLOR_BTNFACE + 1); wcex.lpszMenuName = NULL; wcex.lpszClassName = acAppName; wcex.hIconSm = LoadIcon(NULL, IDI_APPLICATION); RegisterClassEx(&wcex); hWnd = CreateWindow( acAppName, // ClassName acAppName, // WindowName WS_POPUPWINDOW | WS_CAPTION | WS_MINIMIZEBOX, 100, // x 100, // y 320, // Width 120, // Height NULL, // WndParent NULL, // Menu g_hInstance, NULL); // Param if (hWnd == NULL) { return 0; } ShowWindow(hWnd, nCmdShow); while (GetMessage(&msg, NULL, 0, 0)) { TranslateMessage(&msg); DispatchMessage(&msg); } return (int)msg.wParam; } LRESULT CALLBACK WndProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam) { switch (uMsg) { case WM_HSCROLL: OnHScroll(); break; case WM_CREATE: OnCreate(hWnd); break; case WM_DESTROY: PostQuitMessage(0); break; default: return DefWindowProc(hWnd, uMsg, wParam, lParam); } return 0; } void OnHScroll() { int iPos; char acBuf[16]; iPos = (int)SendMessage(g_hTrack, TBM_GETPOS, 0, 0); Trace("OnHScroll(%d)\n", iPos); sprintf_s(acBuf, sizeof(acBuf), "%d", iPos); SetWindowText(g_hLabel, acBuf); } void OnCreate(HWND hWnd) { g_hTrack = CreateWindow(TRACKBAR_CLASS, NULL, WS_CHILD | WS_VISIBLE | TBS_AUTOTICKS, 32, 16, 256, 32, hWnd, (HMENU)0, g_hInstance, NULL); SendMessage(g_hTrack, TBM_SETRANGE, (WPARAM)FALSE, MAKELPARAM(0, 127)); SendMessage(g_hTrack, TBM_SETTICFREQ, (WPARAM)8, 0); g_hLabel = CreateWindow("STATIC", "0", WS_CHILD | WS_VISIBLE, 144, 64, 32, 16, hWnd, (HMENU)1, g_hInstance, NULL); } void Trace(const char *pcFormat, ...) { va_list args; char acBuf[512]; int iRet; va_start(args, pcFormat); iRet = vsprintf_s(acBuf, sizeof(acBuf), pcFormat, args); if (0 < iRet) { OutputDebugString(acBuf); } va_end(args); }