Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <windows.h>
- #include <commctrl.h>
- const char g_szClassName[] = "myWindowClass";
- int trackbar_num = 0;
- HWND hwndTrack;
- HWND leftLabel;
- HWND rightLabel;
- HWND posLabel;
- HINSTANCE hInst;
- void updateLabel()
- {
- trackbar_num = SendMessage(hwndTrack, TBM_GETPOS, 0, 0);
- wchar_t buf[4];
- wsprintfW(buf, L"%ld", trackbar_num);
- SetWindowTextW(posLabel, buf);
- }
- // Step 4: the Window Procedure
- LRESULT CALLBACK WndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
- {
- HDC hDC, memDCExercising;
- PAINTSTRUCT ps;
- HBITMAP bmp;
- switch (msg)
- {
- case WM_CREATE:
- leftLabel = CreateWindowW(L"STATIC", L"0",
- WS_CHILD | WS_VISIBLE, 0, 0, 10, 30, hwnd, (HMENU)1, NULL, NULL);
- rightLabel = CreateWindowW(L"STATIC", L"255",
- WS_CHILD | WS_VISIBLE, 0, 0, 30, 30, hwnd, (HMENU)2, NULL, NULL);
- hwndTrack = CreateWindowW(L"msctls_trackbar32", L"Trackbar Control",
- WS_CHILD | WS_VISIBLE | TBS_AUTOTICKS,
- 20, 20, 1000, 30, hwnd, (HMENU)"trackbar", NULL, NULL);
- posLabel = CreateWindowW(L"STATIC", L"0",
- WS_CHILD | WS_VISIBLE, 50, 50, 100, 100, hwnd, (HMENU)1, NULL, NULL);
- SendMessage(hwndTrack, TBM_SETRANGE, (WPARAM)TRUE, (LPARAM)MAKELONG(0, 255));
- SendMessage(hwndTrack, TBM_SETBUDDY, TRUE, (LPARAM)leftLabel);
- SendMessage(hwndTrack, TBM_SETBUDDY, FALSE, (LPARAM)rightLabel);
- break;
- case WM_PAINT:
- hDC = BeginPaint(hwnd, &ps);
- bmp = LoadBitmap(hInst, L"C:\\example.bmp");
- memDCExercising = CreateCompatibleDC(hDC);
- SelectObject(memDCExercising, bmp);
- BitBlt(hDC, 100, 100, 500, 500, memDCExercising, 0, 0, SRCCOPY);
- DeleteDC(memDCExercising);
- DeleteObject(bmp);
- EndPaint(hwnd, &ps);
- break;
- case WM_CLOSE:
- DestroyWindow(hwnd);
- break;
- case WM_HSCROLL:
- updateLabel();
- 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)
- {
- WNDCLASSEX wc;
- HWND hwnd;
- HWND track;
- MSG Msg;
- hInst = hInstance;
- //Step 1: Registering the Window Class
- wc.cbSize = sizeof(WNDCLASSEX);
- wc.style = 0;
- wc.lpfnWndProc = WndProc;
- wc.cbClsExtra = 0;
- wc.cbWndExtra = 0;
- wc.hInstance = hInstance;
- wc.hIcon = LoadIcon(NULL, IDI_APPLICATION);
- wc.hCursor = LoadCursor(NULL, IDC_ARROW);
- wc.hbrBackground = (HBRUSH)(COLOR_WINDOW);
- wc.lpszMenuName = NULL;
- wc.lpszClassName = L"ClassName";
- wc.hIconSm = LoadIcon(NULL, IDI_APPLICATION);
- if (!RegisterClassEx(&wc))
- {
- MessageBox(NULL, L"Window Registration Failed!", L"Error!",
- MB_ICONEXCLAMATION | MB_OK);
- return 0;
- }
- // Step 2: Creating the Window
- hwnd = CreateWindowEx(
- WS_EX_CLIENTEDGE,
- L"ClassName",
- L"Image Analysis",
- WS_OVERLAPPEDWINDOW,
- CW_USEDEFAULT, CW_USEDEFAULT, 1100, 150,
- NULL, NULL, hInstance, NULL);
- if (hwnd == NULL)
- {
- MessageBox(NULL, L"Window Creation Failed!", L"Error!",
- MB_ICONEXCLAMATION | MB_OK);
- return 0;
- }
- ShowWindow(hwnd, nCmdShow);
- UpdateWindow(hwnd);
- // Step 3: The Message Loop
- while (GetMessage(&Msg, NULL, 0, 0) > 0)
- {
- TranslateMessage(&Msg);
- DispatchMessage(&Msg);
- }
- return Msg.wParam;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement