Guest User

Untitled

a guest
Jul 29th, 2022
255
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.47 KB | None | 0 0
  1. #define no_init_all
  2. #define WIN32_LEAN_AND_MEAN
  3. #define _CRT_SECURE_NO_WARNINGS
  4. #include <Windows.h>
  5. #include <iostream>
  6. #include <vector>
  7. #include <strsafe.h>
  8. #include <CommCtrl.h>
  9. #pragma comment(lib, "comctl32.lib")
  10. #pragma comment(linker, "\"/manifestdependency:type='win32' \
  11. name='Microsoft.Windows.Common-Controls' version='6.0.0.0' \
  12. processorArchitecture='*' publicKeyToken='6595b64144ccf1df' language='*'\"")
  13.  
  14. #define WC_WINDOW "WC_WINDOW"
  15.  
  16. LRESULT WINAPI WndProc(HWND hwnd, UINT msg, WPARAM wp, LPARAM lp);
  17.  
  18. HWND mainHwnd, sb;
  19.  
  20. int main(int args, char* argv[])
  21. {
  22. InitCommonControls();
  23. HINSTANCE hInst = GetModuleHandle(NULL);
  24. WNDCLASSEX wc{};
  25. wc.cbSize = sizeof(wc);
  26. wc.hbrBackground = (HBRUSH)GetStockObject(DKGRAY_BRUSH);
  27. wc.hInstance = hInst;
  28. wc.hCursor = LoadCursor(NULL, IDC_ARROW);
  29. wc.lpszClassName = WC_WINDOW;
  30. wc.style = CS_VREDRAW | CS_HREDRAW;
  31. wc.lpfnWndProc = WndProc;
  32. GetClassInfoEx(wc.hInstance, wc.lpszClassName, &wc);
  33. RegisterClassEx(&wc);
  34.  
  35. mainHwnd = CreateWindowEx(NULL, wc.lpszClassName, WC_WINDOW,
  36. WS_POPUP | WS_VISIBLE | WS_VSCROLL, 600, 400, 700, 380, nullptr, 0, wc.hInstance, NULL);
  37.  
  38. MSG msg{};
  39. while (GetMessage(&msg, NULL, 0, 0))
  40. {
  41. TranslateMessage(&msg);
  42. DispatchMessage(&msg);
  43. }
  44. return msg.lParam;
  45. }
  46.  
  47. LRESULT WINAPI WndProc(HWND hwnd, UINT msg, WPARAM wp, LPARAM lp)
  48. {
  49. static HBRUSH br;
  50. static int client_y;
  51. int totalWord = 50;
  52. static int yPos;
  53. static int rows;
  54. static int fontHeight;
  55. switch (msg)
  56. {
  57. case WM_CREATE: {
  58. HDC dc = GetWindowDC(hwnd);
  59. TEXTMETRIC tm;
  60. GetTextMetrics(dc, &tm);
  61. fontHeight = tm.tmHeight;
  62. ReleaseDC(hwnd, dc);
  63. br = CreateSolidBrush(RGB(90, 130, 200));
  64. }break;
  65. case WM_PAINT: {
  66. PAINTSTRUCT ps{};
  67. HDC dc = BeginPaint(hwnd, &ps);
  68. int count;
  69. int lineCount = 0;
  70. int startLine = GetScrollPos(hwnd, SB_VERT);
  71. int endLine = startLine + rows;
  72. int strLength = 0;
  73. CHAR buf[10];
  74. SetTextColor(dc, RGB(190, 190, 190));
  75. SetBkMode(dc, TRANSPARENT);
  76. for (count = startLine; count < endLine; count++) {
  77. strLength = sprintf(buf, "%d", count);
  78. TextOut(dc, 12, lineCount, buf, strLength);
  79. lineCount = lineCount + fontHeight;
  80. }
  81. SCROLLBARINFO info{};
  82. info.cbSize = sizeof(SCROLLBARINFO);
  83. GetScrollBarInfo(hwnd, OBJID_VSCROLL, &info);
  84.  
  85. RECT rc = info.rcScrollBar;
  86. MapWindowPoints(HWND_DESKTOP, hwnd, (POINT*)&rc, 2);
  87. rc.left -= 50;
  88. FillRect(dc, &rc, br);
  89.  
  90. EndPaint(hwnd, &ps);
  91. }break;
  92. case WM_SIZE: {
  93. client_y = HIWORD(lp);
  94. rows = client_y / fontHeight;
  95. int tLine = totalWord * fontHeight;
  96. SCROLLINFO info{};
  97. info.cbSize = sizeof(SCROLLINFO);
  98. info.fMask = SIF_ALL;
  99. info.nMin = 0;
  100. info.nMax = totalWord - rows;
  101. info.nPage = 10;
  102.  
  103. SetScrollInfo(hwnd, SB_VERT, &info, TRUE);
  104. InvalidateRect(hwnd, NULL, TRUE);
  105. }break;
  106. case WM_VSCROLL: {
  107. SCROLLINFO info{};
  108. info.cbSize = sizeof(SCROLLINFO);
  109. info.fMask = SIF_ALL;
  110. GetScrollInfo(hwnd, SB_VERT, &info);
  111.  
  112. WORD code = LOWORD(wp);
  113. switch (code)
  114. {
  115. case SB_TOP: info.nPos = info.nMin; break;
  116. case SB_BOTTOM: info.nPos = info.nMax; break;
  117. case SB_THUMBTRACK: info.nPos = info.nTrackPos; break;
  118. case SB_PAGEUP: info.nPos -= 2; break;
  119. case SB_PAGEDOWN: info.nPos += 2; break;
  120. default: break;
  121. }
  122. info.fMask = SIF_POS;
  123. SetScrollInfo(hwnd, SB_VERT, &info, TRUE);
  124. InvalidateRect(hwnd, NULL, TRUE);
  125. }break;
  126. default:
  127. break;
  128. }
  129. return DefWindowProc(hwnd, msg, wp, lp);
  130. }
  131.  
  132.  
  133.  
Advertisement
Add Comment
Please, Sign In to add comment