Guest User

Untitled

a guest
Mar 26th, 2015
276
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 3.03 KB | None | 0 0
  1. #define WINVER 0x0501
  2. #define _WIN32_WINNT 0x0501
  3. #include <tchar.h>
  4. #include <assert.h>
  5. #include <windows.h>
  6. #include <commctrl.h>
  7.  
  8. #define ok(cond, fmt)                    \
  9. if (!(cond))                             \
  10. {                                        \
  11.     MessageBox(NULL, fmt, _T("Error!"),  \
  12.         MB_ICONEXCLAMATION | MB_OK);     \
  13.     exit(1);                             \
  14. }
  15.  
  16. static LRESULT CALLBACK CustomDrawWndProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)
  17. {
  18.     switch(msg) {
  19.  
  20.     case WM_DESTROY:
  21.         PostQuitMessage(0);
  22.         break;
  23.  
  24.     default:
  25.         return DefWindowProc(hWnd, msg, wParam, lParam);
  26.     }
  27.  
  28.     return 0L;
  29. }
  30.  
  31. int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance,
  32.     LPSTR lpCmdLine, int nCmdShow)
  33. {
  34.  
  35.     WNDCLASS wc;
  36.     LRESULT   lResult;
  37.     MSG msg;
  38.  
  39.     /* Create a class to use the custom draw wndproc */
  40.     wc.style = CS_HREDRAW | CS_VREDRAW;
  41.     wc.cbClsExtra = 0;
  42.     wc.cbWndExtra = 0;
  43.     wc.hInstance = GetModuleHandle(NULL);
  44.     wc.hIcon = NULL;
  45.     wc.hCursor = LoadCursor(NULL, IDC_ARROW);
  46.     wc.hbrBackground = GetSysColorBrush(COLOR_WINDOW);
  47.     wc.lpszMenuName = NULL;
  48.     wc.lpszClassName = _T("CustomDrawClass");
  49.     wc.lpfnWndProc = CustomDrawWndProc;
  50.     RegisterClass(&wc);
  51.  
  52.  
  53.     HWND hwndMain, hwndTip;
  54.     TOOLINFO toolInfo = { 0 };
  55.  
  56.     /* Create a main window */
  57.     hwndMain = CreateWindowEx(0, _T("CustomDrawClass"), NULL,
  58.                               WS_CAPTION | WS_SYSMENU | WS_MINIMIZEBOX |
  59.                               WS_MAXIMIZEBOX | WS_VISIBLE,
  60.                               50, 50,
  61.                               300, 300,
  62.                               NULL, NULL, NULL, 0);
  63.     ok(hwndMain != NULL, _T("Creation of main window failed\n"));
  64.  
  65.     /* Make it show */
  66.     ShowWindow(hwndMain, SW_SHOWNORMAL);
  67.  
  68.     /* Create Tooltip */
  69.     hwndTip = CreateWindowEx(WS_EX_TOPMOST, TOOLTIPS_CLASS, NULL,
  70.                              TTS_NOPREFIX | TTS_ALWAYSTIP,
  71.                              CW_USEDEFAULT, CW_USEDEFAULT,
  72.                              CW_USEDEFAULT, CW_USEDEFAULT,
  73.                              hwndMain, NULL, GetModuleHandle(NULL), 0);
  74.     ok(hwndTip != NULL, _T("Creation of tooltip window failed\n"));
  75.  
  76.     /* Make it topmost, as per the MSDN */
  77.     SetWindowPos(hwndTip, HWND_TOPMOST, 0, 0, 0, 0,
  78.           SWP_NOMOVE | SWP_NOSIZE | SWP_NOACTIVATE);
  79.  
  80.     /* Create a tool */
  81.     toolInfo.cbSize = sizeof(TOOLINFO);
  82.     toolInfo.hwnd = hwndMain;
  83.     toolInfo.hinst = GetModuleHandle(NULL);
  84.     toolInfo.uFlags = TTF_SUBCLASS;
  85.     toolInfo.uId = 0x1234ABCD;
  86.     toolInfo.lpszText = (LPTSTR)_T("This is a test tooltip");
  87.     GetClientRect(hwndMain, &toolInfo.rect);
  88.     lResult = SendMessage(hwndTip, TTM_ADDTOOL, 0, (LPARAM)&toolInfo);
  89.     ok(lResult, _T("Adding the tool to the tooltip failed\n"));
  90.  
  91.  
  92.     // Step 3: The Message Loop
  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