Advertisement
Guest User

Untitled

a guest
Feb 25th, 2017
185
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.18 KB | None | 0 0
  1. #include <windows.h>
  2. #include <tchar.h>
  3. #include "Shellapi.h"
  4. #include "Commctrl.h"
  5.  
  6. LPTSTR g_szClassName = _T("myWindowClass");
  7.  
  8. HIMAGELIST imageList;
  9. SHFILEINFO shfi;
  10.  
  11. LRESULT CALLBACK WndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
  12. {
  13.     switch (msg)
  14.     {
  15.     case WM_PAINT:
  16.         {
  17.             PAINTSTRUCT ps;
  18.             HDC hdc = BeginPaint(hwnd, &ps);
  19.             ImageList_Draw(imageList, shfi.iIcon, hdc, 0, 0, ILD_NORMAL);
  20.             EndPaint(hwnd, &ps);
  21.         }
  22.         break;
  23.     case WM_CLOSE:
  24.         DestroyWindow(hwnd);
  25.         break;
  26.     case WM_DESTROY:
  27.         PostQuitMessage(0);
  28.         break;
  29.     default:
  30.         return DefWindowProc(hwnd, msg, wParam, lParam);
  31.     }
  32.     return 0;
  33. }
  34.  
  35. int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance,
  36.     LPSTR lpCmdLine, int nCmdShow)
  37. {
  38.     WNDCLASSEX wc;
  39.     HWND hwnd;
  40.     MSG Msg;
  41.  
  42.     // Get the path to the OneDrive folder
  43.     LPTSTR src = _T("%USERPROFILE%\\OneDrive");
  44.     TCHAR dest[MAX_PATH];
  45.     ExpandEnvironmentStrings(src, dest, MAX_PATH);
  46.  
  47.     // Load the image from the OneDrive folder
  48.     ZeroMemory(&shfi, sizeof(shfi));
  49.     imageList = (HIMAGELIST)SHGetFileInfo(
  50.         dest,
  51.         FILE_ATTRIBUTE_NORMAL,
  52.         &shfi,
  53.         sizeof(shfi),
  54.         SHGFI_ICON | SHGFI_SYSICONINDEX);
  55.    
  56.     wc.cbSize = sizeof(WNDCLASSEX);
  57.     wc.style = 0;
  58.     wc.lpfnWndProc = WndProc;
  59.     wc.cbClsExtra = 0;
  60.     wc.cbWndExtra = 0;
  61.     wc.hInstance = hInstance;
  62.     wc.hIcon = LoadIcon(NULL, IDI_APPLICATION);
  63.     wc.hCursor = LoadCursor(NULL, IDC_ARROW);
  64.     wc.hbrBackground = (HBRUSH)(COLOR_WINDOW + 1);
  65.     wc.lpszMenuName = NULL;
  66.     wc.lpszClassName = g_szClassName;
  67.     wc.hIconSm = LoadIcon(NULL, IDI_APPLICATION);
  68.  
  69.     if (!RegisterClassEx(&wc))
  70.     {
  71.         MessageBox(NULL, _T("Window Registration Failed!"), _T("Error!"), MB_ICONEXCLAMATION | MB_OK);
  72.         return 0;
  73.     }
  74.  
  75.     hwnd = CreateWindowEx(
  76.         WS_EX_CLIENTEDGE,
  77.         g_szClassName,
  78.         _T("Title"),
  79.         WS_OVERLAPPEDWINDOW,
  80.         CW_USEDEFAULT, CW_USEDEFAULT, 240, 120,
  81.         NULL, NULL, hInstance, NULL);
  82.  
  83.     if (hwnd == NULL)
  84.     {
  85.         MessageBox(NULL, _T("Window Creation Failed!"), _T("Error!"),
  86.             MB_ICONEXCLAMATION | MB_OK);
  87.         return 0;
  88.     }
  89.  
  90.     ShowWindow(hwnd, nCmdShow);
  91.     UpdateWindow(hwnd);
  92.  
  93.     while (GetMessage(&Msg, NULL, 0, 0) > 0)
  94.     {
  95.         TranslateMessage(&Msg);
  96.         DispatchMessage(&Msg);
  97.     }
  98.     return Msg.wParam;
  99. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement