SetWindowText or painting problem !

Posted on 2006-10-23
Last Modified: 2013-11-20
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)
         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"
Question by:mike_marquet
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 6
  • 4
LVL 44

Accepted Solution

AndyAinscow earned 20 total points
ID: 17788390
This might be a silly question but why not use a 'normal' tooltip control with a callback for the text to be displayed?

Author Comment

ID: 17788568
Because I want to set the position of the tooltip myself and not at the cursor position.
LVL 44

Expert Comment

ID: 17788590
You could do that with the normal windows functions (MoveWindow or SetWindowPos)
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!


Author Comment

ID: 17801833
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 ?
LVL 22

Assisted Solution

mahesh1402 earned 30 total points
ID: 17810645
>>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 :


Author Comment

ID: 17810947
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 !
LVL 44

Expert Comment

ID: 17810988
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.

Author Comment

ID: 17811038
It's the same using MoveWindow or SetWindowPos.

Seems to be that the TTF_TRACK flag has no effect !
LVL 44

Expert Comment

ID: 17811056
Do I understand correctly that you want the 'tip' to be displayed even when the mouse isn't over the edit box ?

Author Comment

ID: 17811135
Yes, the tip must be displayed ALSO when the mouse is not over the control for which the tip is registered.

Author Comment

ID: 17811375
It's now working.

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

Thanks to all for help.

Featured Post

Secure Your Active Directory - April 20, 2017

Active Directory plays a critical role in your company’s IT infrastructure and keeping it secure in today’s hacker-infested world is a must.
Microsoft published 300+ pages of guidance, but who has the time, money, and resources to implement? Register now to find an easier way.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
format the code in java 6 110
EvenOdd challenge 10 146
canBalance challenge 34 105
Adjust the codes 3 34
This is to be the first in a series of articles demonstrating the development of a complete windows based application using the MFC classes.  I’ll try to keep each article focused on one (or a couple) of the tasks that one may meet.   Introductio…
Introduction: Hints for the grid button.  Nested classes, templated collections.  Squash that darned bug! Continuing from the sixth article about sudoku.   Open the project in visual studio. First we will finish with the SUD_SETVALUE messa…
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit If you want to manage em…

733 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question