Improve company productivity with a Business Account.Sign Up

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 637
  • Last Modified:

SetWindowText or painting problem !

I have created a derived CEdit control who displays a tooltip control to show how much character can still be displayed to reach the GetLimitText value.

Therefore, I have created a tooltip from scratch using CreateWindow all is working fine until I wanted to set the background color of my tooltip
to an other color that the default STATIC color (gray).

Tooltip is created like this :

     m_hToolTipWnd = CreateWindowEx(0, "STATIC", "", WS_BORDER | WS_POPUP | SS_CENTER | SS_CENTERIMAGE, 0, 0, 10, 10, m_hWnd, NULL, hInstance, 0);

To change the background color, I have added :

     LONG nRet = SetWindowLong(m_hToolTipWnd, GWL_WNDPROC, (LONG)(LRESULT)ToolTipWndProc);

     LRESULT CALLBACK CEditWithLimitToolTip::ToolTipWndProc(HWND hWnd, UINT uiMsg, WPARAM wParam, LPARAM lParam)
      {
       switch(uiMsg)
        {
         case WM_ERASEBKGND :
                              {
                               CDC *pDC = CDC::FromHandle( (HDC)wParam );
                         
                               CRect rect;
                         
                               ::GetClientRect(hWnd, &rect);
                         
                               pDC->FillSolidRect(&rect, GetSysColor(COLOR_INFOBK));

                               return TRUE;
                              }
        }

       return ::DefWindowProc(hWnd, uiMsg, wParam, lParam);
      }

The background is correctly painted but the text is no more painted also if I call SetWindowText with a new string

P.S. : I have the same problem if I use RegisterClassEx and use the Atom value instead of "STATIC"
0
mike_marquet
Asked:
mike_marquet
  • 6
  • 4
2 Solutions
 
AndyAinscowFreelance programmer / ConsultantCommented:
This might be a silly question but why not use a 'normal' tooltip control with a callback for the text to be displayed?
0
 
mike_marquetAuthor Commented:
Because I want to set the position of the tooltip myself and not at the cursor position.
0
 
AndyAinscowFreelance programmer / ConsultantCommented:
You could do that with the normal windows functions (MoveWindow or SetWindowPos)
0
Upgrade your Question Security!

Your question, your audience. Choose who sees your identity—and your question—with question security.

 
mike_marquetAuthor Commented:
If I use the CToolTipCtrl instead, I have the problem that the mouse pointer must be over the edit control for the tooltip to be displayed and the mouse pointer can NOT be over it. How can I force the CToolTipCtrl to be displayed without mouse pointer over edit control ?
0
 
mahesh1402Commented:
>>Because I want to set the position of the tooltip myself and not at the cursor position.

Send a TTM_TRACKPOSITION message  which sets the coordinates of ToolTip ..

SendMessage (hwndTT, TTM_TRACKPOSITION, 0, (LPARAM) (DWORD) MAKELONG (X, Y)); // X & Y position of tooltip

For more see : Display ToolTip in any place on the screen : http://www.codeproject.com/miscctrl/tooltipzen.asp

-MAHESH
0
 
mike_marquetAuthor Commented:
To mahesh1402 :

I have used the flag TTF_TRACK when creating the tooltip control but when I use the TTM_TRACKPOSITION message, the tooltip is always under the cursor postion and not at specified position.

I'm using Microsoft Visual Studio .NET 2003 and use the CToolTipCtrl MFC Class instead of the Win32 API functions.

Full code can be provided !
0
 
AndyAinscowFreelance programmer / ConsultantCommented:
As a tooltip is a CWnd based window you can use the normal MoveWindow or SetWindowPos functions to try to position it where you want.
0
 
mike_marquetAuthor Commented:
It's the same using MoveWindow or SetWindowPos.

Seems to be that the TTF_TRACK flag has no effect !
0
 
AndyAinscowFreelance programmer / ConsultantCommented:
Do I understand correctly that you want the 'tip' to be displayed even when the mouse isn't over the edit box ?
0
 
mike_marquetAuthor Commented:
Yes, the tip must be displayed ALSO when the mouse is not over the control for which the tip is registered.
0
 
mike_marquetAuthor Commented:
It's now working.

I have used the win32 API instead of the MFC CToolTipCtrl class.

Thanks to all for help.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

  • 6
  • 4
Tackle projects and never again get stuck behind a technical roadblock.
Join Now