#include <windows.h>#include <commctrl.h>#include <stdio.h>#define IDC_SLIDER1 101#define IDC_PROGRESS1 102 #define IDC_BUTTON1 103const char g_szClassName[] = "myWindowClass";LRESULT CALLBACK WndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam);HFONT hfont0;HWND hCtrl0_0, hCtrl0_1, hCtrl0_2;int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow) { //create and register window class WNDCLASSEX wc; ZeroMemory(&wc, sizeof(wc)); wc.cbSize = sizeof(wc); wc.hbrBackground = (HBRUSH)(COLOR_3DFACE + 1); wc.lpszMenuName = NULL; wc.style = CS_HREDRAW|CS_VREDRAW; wc.lpfnWndProc = WndProc; wc.hInstance = hInstance; wc.hIcon = LoadIcon(0, (LPCTSTR)IDI_APPLICATION); wc.hCursor = LoadCursor(NULL, IDC_ARROW); wc.lpszClassName = g_szClassName; if(!RegisterClassEx(&wc)) {MessageBox(NULL, "Window Registration Failed!", "Error!", MB_ICONEXCLAMATION | MB_OK); return 0;} //populate window with controls hfont0 = CreateFont(-11, 0, 0, 0, 400, FALSE, FALSE, FALSE, 0, 400, 2, 1, 1, ("Microsoft Sans Serif")); HWND hwnd = CreateWindowEx(WS_EX_APPWINDOW, g_szClassName, "Controls Test", WS_OVERLAPPEDWINDOW, 200, 200, 306, 123, 0, 0, hInstance, 0); hCtrl0_0 = CreateWindowEx(0, TRACKBAR_CLASS, 0, WS_VISIBLE | WS_CHILD | WS_TABSTOP | TBS_BOTH | TBS_NOTICKS, 3, 36, 294, 26, hwnd, (HMENU)IDC_SLIDER1, hInstance, 0); SendMessage(hCtrl0_0, WM_SETFONT, (WPARAM)hfont0, FALSE); SendMessage(hCtrl0_0, TBM_SETRANGE, FALSE, MAKELONG(1, 100)); SendMessage(hCtrl0_0, TBM_SETPOS, FALSE, 1); hCtrl0_1 = CreateWindowEx(0, PROGRESS_CLASS, 0, WS_VISIBLE | WS_CHILD, 3, 5, 294, 20, hwnd, (HMENU)IDC_PROGRESS1, hInstance, 0); SendMessage(hCtrl0_1, WM_SETFONT, (WPARAM)hfont0, FALSE); SendMessage(hCtrl0_0, PBM_SETRANGE, FALSE, MAKELONG(1, 100)); hCtrl0_2 = CreateWindowEx(0, WC_BUTTON, ("OK"), WS_VISIBLE | WS_CHILD | WS_TABSTOP | 0x00000001, 105, 68, 90, 23, hwnd, (HMENU)IDC_BUTTON1, hInstance, 0); SendMessage(hCtrl0_2, WM_SETFONT, (WPARAM)hfont0, FALSE); //start 'er up and run the control loop ShowWindow(hwnd, nCmdShow); UpdateWindow(hwnd); MSG Msg; while(GetMessage(&Msg, NULL, 0, 0) > 0) { TranslateMessage(&Msg); DispatchMessage(&Msg); } return Msg.wParam;}LRESULT CALLBACK WndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam) { unsigned int pos; switch(msg) { case BN_CLICKED: break; //this never gets triggered for some reason case TB_ENDTRACK: //this isn't working correctly pos = SendMessage(hCtrl0_0, TBM_GETPOS, NULL, NULL); SendMessage(hCtrl0_1, PBM_SETPOS, pos, NULL); break; case WM_CLOSE: DestroyWindow(hwnd); break; case WM_DESTROY: PostQuitMessage(0); break; default: return DefWindowProc(hwnd, msg, wParam, lParam); } return 0;}
I'm running into some problems. What I want it to do is set the progress bar according to the value of the slider and quit the app when the OK button is pressed. I've tried using TB_THUMBTRACK rather than TB_ENDTRACK but that doesn't seem to work either. The progress bar only seems to set itself when I first touch the slider and then stops responding. The BN_CLICKED message never gets recieved by the proc.
When I looked over the definitions for the messages I saw that a lot of controls could potentially send the same message, so I'm pretty sure I'm missing something here. Can anyone tell me why this isn't working and what I'm missing here???
Thanks in advance for any advice. :)