CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 4 of 4
  1. #1
    Join Date
    Aug 2009
    Posts
    1

    Question Using tooltips with dll

    I want to create tooltip. When i do this in main exe - all is ok, but when i write this in dll,
    SendMessage TTM_ADDTOOL return false always. What's wrong?
    Code:
    HWND hToolTip = NULL;
    HMODULE hGlobalModule = NULL;
    
    BOOL APIENTRY DllMain( HMODULE hModule,DWORD  ul_reason_for_call,LPVOID lpReserved)
    {
      switch (ul_reason_for_call)
      {
         case DLL_PROCESS_ATTACH:
         {
               hGlobalModule = hModule;
        
            WNDCLASS popupcl;
            memset(&popupcl, 0, sizeof(popupcl));
            popupcl.lpszClassName = POPUPCLASS;
            popupcl.lpfnWndProc = (WNDPROC)WinPopupProc;
            popupcl.hInstance = hGlobalModule;
            popupcl.style = CS_DBLCLKS | CS_HREDRAW | CS_VREDRAW;
            popupcl.hIcon = LoadIcon(NULL, IDI_APPLICATION);
            popupcl.hCursor = LoadCursor(NULL, IDC_ARROW);
            popupcl.hbrBackground = (HBRUSH)GetStockObject(BLACK_BRUSH);
            ATOM retpopup = RegisterClass(&popupcl);
    
            hThread = CreateThread( NULL,                   // default security attributes
                        0,                      // use default stack size  
                        ThreadMessages,         // thread function name
                        NULL,                   // argument to thread function 
                        0,                      // use default creation flags 
                        &dwThreadId);           // returns the thread identifier 
            }
            break;
         }
    .......................
    }
    
    DWORD WINAPI ThreadMessages( LPVOID lpParam ) 
    {
        hPopupInfo = CreateWindowEx(    WS_EX_TOPMOST,
                                POPUPCLASS,
                                L"popapchik",
                                WS_POPUP | WS_VISIBLE,
                                50, 50,
                                100, 100,
                                NULL,
                                (HMENU)NULL,
                                hGlobalModule,
                                NULL);
        if(hPopupInfo) ShowWindow(hPopupInfo, SW_SHOW);
    
        hToolTip = CreateWindowEx(WS_EX_TOPMOST, TOOLTIPS_CLASS, NULL,
                    TTS_ALWAYSTIP,
                    CW_USEDEFAULT, CW_USEDEFAULT,
                    CW_USEDEFAULT, CW_USEDEFAULT,
                    hPopupInfo, 0, hGlobalModule, NULL );
    
        MSG msg;
        while (GetMessage( &msg, NULL, 0, 0 ))
        {
            if (msg.message==WM_QUIT)  
                break;
            TranslateMessage(&msg);
            DispatchMessage(&msg);
        }
        return 0;
    }
    
    LRESULT CALLBACK WinPopupProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)
    {
        switch (msg)
        {
          case WM_LBUTTONUP:
            {
                TOOLINFO tooltip = {0};
                tooltip.cbSize = sizeof(TOOLINFO);
                tooltip.uFlags = TTF_SUBCLASS;
                tooltip.hinst = hGlobalModule;
                tooltip.uId = 0;
                tooltip.hwnd = hWnd;
                tooltip.lpszText = L"tooltip";
                tooltip.rect.right = 50;
                tooltip.rect.bottom = 50;
    
                if (SendMessage(hToolTip, TTM_ADDTOOL, 0, LPARAM(&tooltip)) != TRUE)
                    Logger::Log("Error add tooltip\n");      //////!!!!!!!!Всегда возвращается ошибка!!!
            }
                break;
        }
        return DefWindowProc(hWnd, msg, wParam, lParam);
    }

  2. #2
    VictorN's Avatar
    VictorN is offline Super Moderator Power Poster
    Join Date
    Jan 2003
    Location
    Hanover Germany
    Posts
    20,430

    Re: Using tooltips with dll

    1. 1You should never compare the API return values with TRUE. Ever!
    Because any return value != 0 is treated as TRUE.
    So you should write:
    Code:
                if (!SendMessage(hToolTip, TTM_ADDTOOL, 0, LPARAM(&tooltip)))
                    Logger::Log("Error add tooltip\n");      //////!!!!!!!!Всегда возвращается ошибка!!!
    2. Is there any reason you create your POPUPCLASS window in a secondary thread?
    Victor Nijegorodov

  3. #3
    Join Date
    Nov 2000
    Location
    Voronezh, Russia
    Posts
    6,633

    Re: Using tooltips with dll

    Quote Originally Posted by CoolFaer View Post
    I want to create tooltip. When i do this in main exe - all is ok, but when i write this in dll,
    SendMessage TTM_ADDTOOL return false always. What's wrong?
    Try this:
    Code:
                TOOLINFO tooltip = {0};
    #if (_WIN32_WINNT >= 0x0501)
                tooltip.cbSize = TTTOOLINFO_V1_SIZE;
    #else
                tooltip.cbSize = sizeof(TOOLINFO);
    #endif
    Best regards,
    Igor

  4. #4
    Join Date
    Nov 2000
    Location
    Voronezh, Russia
    Posts
    6,633

    Re: Using tooltips with dll

    One more point. Your dll with no change works fine with an executable that embeds common controls manifest. Otherwise the trick I showed you last time is needed.
    Code:
                if (SendMessage(hToolTip, TTM_ADDTOOL, 0, LPARAM(&tooltip)) != TRUE)
                {
                            tooltip.cbSize = TTTOOLINFO_V1_SIZE;
                            if (SendMessage(hToolTip, TTM_ADDTOOL, 0, LPARAM(&tooltip)) != TRUE)
                                    Logger::Log("Error add tooltip\n"); 
                }
    Last edited by Igor Vartanov; September 12th, 2009 at 01:38 AM.
    Best regards,
    Igor

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured