Advertisement
Guest User

Untitled

a guest
Jan 6th, 2013
322
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.87 KB | None | 0 0
  1. #pragma comment(linker,"\"/manifestdependency:type='win32' name='Microsoft.Windows.Common-Controls' version='6.0.0.0' processorArchitecture='*' publicKeyToken='6595b64144ccf1df' language='*'\"")
  2.  
  3. #include <Windows.h>
  4. #include <Uxtheme.h>
  5. #include <vsstyle.h>
  6. #include <CommCtrl.h>
  7. #include <sstream>
  8.  
  9. LRESULT CALLBACK WindowProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
  10. {
  11.     switch (message)
  12.     {
  13.     case WM_DESTROY:
  14.         {
  15.             PostQuitMessage(0);
  16.  
  17.             return 0;
  18.             break;
  19.         }
  20.     case WM_PAINT:
  21.         {
  22.             PAINTSTRUCT ps;
  23.             HDC hdc = BeginPaint(hwnd, &ps);
  24.            
  25.             HTHEME theme = OpenThemeData(hwnd, L"TREEVIEW");
  26.             RECT rect;
  27.             rect.left = 100;
  28.             rect.top = 100;
  29.             rect.right = 200;
  30.             rect.bottom = 200;
  31.            
  32.             RECT glyphRect;
  33.             glyphRect.left = 84;
  34.             glyphRect.top = 142;
  35.             glyphRect.right = 84 + 16;
  36.             glyphRect.bottom = 142 + 16;
  37.  
  38.             DrawThemeBackground(theme,
  39.                 hdc,
  40.                 TVP_GLYPH,
  41.                 GLPS_CLOSED,
  42.                 &glyphRect,
  43.                 &glyphRect);
  44.  
  45.             DrawThemeBackground(theme,
  46.                 hdc,
  47.                 TVP_TREEITEM,
  48.                 TREIS_SELECTED,
  49.                 &rect,
  50.                 &rect);
  51.            
  52.             DrawThemeText(theme,
  53.                 hdc,
  54.                 TVP_TREEITEM,
  55.                 TREIS_SELECTED,
  56.                 L"Ala ma kota",
  57.                 11,
  58.                 DT_VCENTER | DT_CENTER | DT_SINGLELINE,
  59.                 0,
  60.                 &rect);
  61.            
  62.             CloseThemeData(theme);
  63.            
  64.             EndPaint(hwnd, &ps);
  65.             return 0L;
  66.         }
  67.     default:
  68.         {
  69.             return DefWindowProc(hwnd, message, wParam, lParam);
  70.         }
  71.     }
  72. }
  73.  
  74. int CALLBACK WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow)
  75. {
  76.     INITCOMMONCONTROLSEX ctrl;
  77.     ctrl.dwSize = sizeof(ctrl);
  78.     ctrl.dwICC = ICC_TREEVIEW_CLASSES;
  79.     InitCommonControlsEx(&ctrl);
  80.  
  81.     // Rejestracja klasy okna
  82.     WNDCLASSEX winClass;
  83.     winClass.cbClsExtra = 0;
  84.     winClass.cbSize = sizeof(WNDCLASSEX);
  85.     winClass.cbWndExtra = 0;
  86.     winClass.hbrBackground = (HBRUSH)(COLOR_BTNFACE + 1);
  87.     winClass.hCursor = LoadCursor(NULL, IDC_ARROW);
  88.     winClass.hIcon = LoadIcon(NULL, IDI_WINLOGO);
  89.     winClass.hIconSm = LoadIcon(NULL, IDI_WINLOGO);
  90.     winClass.hInstance = hInstance;
  91.     winClass.lpfnWndProc = WindowProc;
  92.     winClass.lpszClassName = L"MainWindowClass";
  93.     winClass.lpszMenuName = NULL;
  94.     winClass.style = CS_HREDRAW | CS_VREDRAW;
  95.  
  96.     if (!RegisterClassEx(&winClass))
  97.         return -1;
  98.  
  99.     // Tworzenie okna
  100.     HWND mainWinHWND = CreateWindowEx(WS_EX_WINDOWEDGE | WS_EX_CLIENTEDGE,
  101.         L"MainWindowClass",
  102.         L"WinAPI window",
  103.         WS_OVERLAPPEDWINDOW,
  104.         CW_USEDEFAULT,
  105.         CW_USEDEFAULT,
  106.         640,
  107.         480,
  108.         NULL,
  109.         NULL,
  110.         hInstance,
  111.         NULL);
  112.  
  113.     if (!mainWinHWND)
  114.         return -1;
  115.  
  116.     SetWindowTheme(mainWinHWND, L"explorer", nullptr);
  117.     ShowWindow(mainWinHWND, SW_SHOW);
  118.  
  119.     // Obsługa kolejki komunikatów
  120.     MSG message;
  121.     BOOL getMsgResult;
  122.  
  123.     while ((getMsgResult = GetMessage(&message, NULL, 0, 0)) != 0 && getMsgResult != -1)
  124.     {
  125.         TranslateMessage(&message);
  126.         DispatchMessage(&message);
  127.     }
  128.  
  129.     return message.lParam;
  130. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement