Advertisement
Guest User

Untitled

a guest
Jun 19th, 2015
393
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 3.18 KB | None | 0 0
  1. #include <windows.h>
  2. #include <commctrl.h>
  3.  
  4. const char g_szClassName[] = "myWindowClass";
  5. int trackbar_num = 0;
  6. HWND hwndTrack;
  7. HWND leftLabel;
  8. HWND rightLabel;
  9. HWND posLabel;
  10. HINSTANCE hInst;
  11.  
  12. void updateLabel()
  13. {
  14.     trackbar_num = SendMessage(hwndTrack, TBM_GETPOS, 0, 0);
  15.     wchar_t buf[4];
  16.     wsprintfW(buf, L"%ld", trackbar_num);
  17.  
  18.     SetWindowTextW(posLabel, buf);
  19. }
  20. // Step 4: the Window Procedure
  21. LRESULT CALLBACK WndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
  22. {
  23.     HDC hDC, memDCExercising;
  24.     PAINTSTRUCT ps;
  25.     HBITMAP bmp;
  26.  
  27.     switch (msg)
  28.     {
  29.     case WM_CREATE:
  30.         leftLabel = CreateWindowW(L"STATIC", L"0",
  31.             WS_CHILD | WS_VISIBLE, 0, 0, 10, 30, hwnd, (HMENU)1, NULL, NULL);
  32.  
  33.         rightLabel = CreateWindowW(L"STATIC", L"255",
  34.             WS_CHILD | WS_VISIBLE, 0, 0, 30, 30, hwnd, (HMENU)2, NULL, NULL);
  35.  
  36.         hwndTrack = CreateWindowW(L"msctls_trackbar32", L"Trackbar Control",
  37.             WS_CHILD | WS_VISIBLE | TBS_AUTOTICKS,
  38.             20, 20, 1000, 30, hwnd, (HMENU)"trackbar", NULL, NULL);
  39.  
  40.         posLabel = CreateWindowW(L"STATIC", L"0",
  41.             WS_CHILD | WS_VISIBLE, 50, 50, 100, 100, hwnd, (HMENU)1, NULL, NULL);
  42.        
  43.         SendMessage(hwndTrack, TBM_SETRANGE, (WPARAM)TRUE, (LPARAM)MAKELONG(0, 255));
  44.         SendMessage(hwndTrack, TBM_SETBUDDY, TRUE, (LPARAM)leftLabel);
  45.         SendMessage(hwndTrack, TBM_SETBUDDY, FALSE, (LPARAM)rightLabel);
  46.         break;
  47.     case WM_PAINT:
  48.         hDC = BeginPaint(hwnd, &ps);
  49.         bmp = LoadBitmap(hInst, L"C:\\example.bmp");
  50.         memDCExercising = CreateCompatibleDC(hDC);
  51.         SelectObject(memDCExercising, bmp);
  52.         BitBlt(hDC, 100, 100, 500, 500, memDCExercising, 0, 0, SRCCOPY);
  53.         DeleteDC(memDCExercising);
  54.         DeleteObject(bmp);
  55.         EndPaint(hwnd, &ps);
  56.         break;
  57.     case WM_CLOSE:
  58.         DestroyWindow(hwnd);
  59.         break;
  60.     case WM_HSCROLL:
  61.         updateLabel();
  62.         break;
  63.     case WM_DESTROY:
  64.         PostQuitMessage(0);
  65.         break;
  66.     default:
  67.         return DefWindowProc(hwnd, msg, wParam, lParam);
  68.     }
  69.     return 0;
  70. }
  71.  
  72. int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance,
  73.     LPSTR lpCmdLine, int nCmdShow)
  74. {
  75.     WNDCLASSEX wc;
  76.     HWND hwnd;
  77.     HWND track;
  78.     MSG Msg;
  79.     hInst = hInstance;
  80.  
  81.     //Step 1: Registering the Window Class
  82.     wc.cbSize = sizeof(WNDCLASSEX);
  83.     wc.style = 0;
  84.     wc.lpfnWndProc = WndProc;
  85.     wc.cbClsExtra = 0;
  86.     wc.cbWndExtra = 0;
  87.     wc.hInstance = hInstance;
  88.     wc.hIcon = LoadIcon(NULL, IDI_APPLICATION);
  89.     wc.hCursor = LoadCursor(NULL, IDC_ARROW);
  90.     wc.hbrBackground = (HBRUSH)(COLOR_WINDOW);
  91.     wc.lpszMenuName = NULL;
  92.     wc.lpszClassName = L"ClassName";
  93.     wc.hIconSm = LoadIcon(NULL, IDI_APPLICATION);
  94.  
  95.     if (!RegisterClassEx(&wc))
  96.     {
  97.         MessageBox(NULL, L"Window Registration Failed!", L"Error!",
  98.             MB_ICONEXCLAMATION | MB_OK);
  99.         return 0;
  100.     }
  101.  
  102.     // Step 2: Creating the Window
  103.     hwnd = CreateWindowEx(
  104.         WS_EX_CLIENTEDGE,
  105.         L"ClassName",
  106.         L"Image Analysis",
  107.         WS_OVERLAPPEDWINDOW,
  108.         CW_USEDEFAULT, CW_USEDEFAULT, 1100, 150,
  109.         NULL, NULL, hInstance, NULL);
  110.  
  111.     if (hwnd == NULL)
  112.     {
  113.         MessageBox(NULL, L"Window Creation Failed!", L"Error!",
  114.             MB_ICONEXCLAMATION | MB_OK);
  115.         return 0;
  116.     }
  117.  
  118.     ShowWindow(hwnd, nCmdShow);
  119.     UpdateWindow(hwnd);
  120.  
  121.     // Step 3: The Message Loop
  122.     while (GetMessage(&Msg, NULL, 0, 0) > 0)
  123.     {
  124.         TranslateMessage(&Msg);
  125.         DispatchMessage(&Msg);
  126.     }
  127.     return Msg.wParam;
  128. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement