CStatic & Tooltip

I'm tring to add a tooltip to my static control (I have a CStatic
derived class).
I read some posts and some articles about this but I don't know what I
do wrong.

My control has SS_NOTIFY and I use this code 

CRect rect; 
GetClientRect(rect);
m_ttToolTip.Create(this);
m_ttToolTip.AddTool(this, _T("TOOLTIP"), rect);
m_ttToolTip.Activate(TRUE);


I have modified also PreTranslateMessage in this way

BOOL CMyHyperLink::PreTranslateMessage(MSG* pMsg) 
{
	// TODO: Add your specialized code here and/or call the base
class
	
	m_ttToolTip.RelayEvent(pMsg);
	return CMyStatic::PreTranslateMessage(pMsg);
}

Can some help me ?

       Stefano Malavasi
__________________________________________________________________________________________
Email:		s_malavasi_REMOVE_@_REMOVE_lycos.it
Note: 		Remove _REMOVE_ string to reply


0
Stefano
1/2/2004 6:35:05 AM
vc.mfc 33608 articles. 0 followers. Follow

4 Replies
2593 Views

Similar Articles

[PageSpeed] 13

Please do as below.

const UINT ID_TOOLTIP = 1;

void CPictureCtrl::PreSubclassWindow()  // override PreSubclassWindow
{	
    // Create the Tool Tip.
    CRect rect;
    GetClientRect(rect);
    m_toolTip.Create(this);
    m_toolTip.AddTool(this, m_szToolTipText, rect, ID_TOOLTIP);
    m_toolTip.Activate(TRUE);
CStatic::PreSubclassWindow();
}

BOOL CPictureCtrl::PreTranslateMessage(MSG* pMsg)
{
    m_toolTip.RelayEvent(pMsg);
return CStatic::PreTranslateMessage(pMsg);
}
// 2 member functions which will set and update the Tool tip text
void CPictureCtrl::SetToolTipText(const CString &szTip)
{
	m_szToolTipText = szTip;
	UpdateToolTipText();
return;
}

void CPictureCtrl::UpdateToolTipText()
{
if (::IsWindow(GetSafeHwnd()))
{
	m_toolTip.UpdateTipText(m_szToolTipText, this, ID_TOOLTIP);
}
return;
}

Sreeram



Stefano Malavasi wrote:
> I'm tring to add a tooltip to my static control (I have a CStatic
> derived class).
> I read some posts and some articles about this but I don't know what I
> do wrong.
> 
> My control has SS_NOTIFY and I use this code 
> 
> CRect rect; 
> GetClientRect(rect);
> m_ttToolTip.Create(this);
> m_ttToolTip.AddTool(this, _T("TOOLTIP"), rect);
> m_ttToolTip.Activate(TRUE);
> 
> 
> I have modified also PreTranslateMessage in this way
> 
> BOOL CMyHyperLink::PreTranslateMessage(MSG* pMsg) 
> {
> 	// TODO: Add your specialized code here and/or call the base
> class
> 	
> 	m_ttToolTip.RelayEvent(pMsg);
> 	return CMyStatic::PreTranslateMessage(pMsg);
> }
> 
> Can some help me ?
> 
>        Stefano Malavasi
> __________________________________________________________________________________________
> Email:		s_malavasi_REMOVE_@_REMOVE_lycos.it
> Note: 		Remove _REMOVE_ string to reply
> 
> 

0
1/2/2004 8:19:02 AM
Also you should set SS_NOTIFY for the control.

Sreeram


Stefano Malavasi wrote:
> I'm tring to add a tooltip to my static control (I have a CStatic
> derived class).
> I read some posts and some articles about this but I don't know what I
> do wrong.
> 
> My control has SS_NOTIFY and I use this code 
> 
> CRect rect; 
> GetClientRect(rect);
> m_ttToolTip.Create(this);
> m_ttToolTip.AddTool(this, _T("TOOLTIP"), rect);
> m_ttToolTip.Activate(TRUE);
> 
> 
> I have modified also PreTranslateMessage in this way
> 
> BOOL CMyHyperLink::PreTranslateMessage(MSG* pMsg) 
> {
> 	// TODO: Add your specialized code here and/or call the base
> class
> 	
> 	m_ttToolTip.RelayEvent(pMsg);
> 	return CMyStatic::PreTranslateMessage(pMsg);
> }
> 
> Can some help me ?
> 
>        Stefano Malavasi
> __________________________________________________________________________________________
> Email:		s_malavasi_REMOVE_@_REMOVE_lycos.it
> Note: 		Remove _REMOVE_ string to reply
> 
> 

0
1/2/2004 8:21:09 AM
On Fri, 02 Jan 2004 13:49:02 +0530, Sreeram
<sreeram0425.remove@netscape.net> wrote:

First of all thanks for you answer.
I do as you suggest (the only thing that was different from my code
was the ID_TOOLTIP) but it still doesn't work. Any other suggestion ?
(My control had already the SS_NOTIFY)

       Stefano Malavasi
__________________________________________________________________________________________
Email:		s_malavasi_REMOVE_@_REMOVE_lycos.it
Note: 		Remove _REMOVE_ string to reply


0
Stefano
1/2/2004 9:44:38 AM
I did not follow the whole thread but looking at supertips example in MSDN will be
helpful.

-- 
Ajay Kalra [MVP - VC++]
ajaykalra@yahoo.com


"Stefano Malavasi" <s_malavasi_REMOVE_@_REMOVE_lycos.it> wrote in message
news:ubfavvc8i733ona49nvjg434cp3tqa5pbl@4ax.com...
| On Fri, 02 Jan 2004 13:49:02 +0530, Sreeram
| <sreeram0425.remove@netscape.net> wrote:
|
| First of all thanks for you answer.
| I do as you suggest (the only thing that was different from my code
| was the ID_TOOLTIP) but it still doesn't work. Any other suggestion ?
| (My control had already the SS_NOTIFY)
|
|        Stefano Malavasi
|
__________________________________________________________________________________________
| Email: s_malavasi_REMOVE_@_REMOVE_lycos.it
| Note: Remove _REMOVE_ string to reply
|
|

0
ajaykalra (6842)
1/3/2004 9:03:55 PM
Reply:

Similar Artilces:

Why "CStatic" always lost?
I have found many times,when i use CStatic,how can we make it's painting absolutely stable?The drawing on it always disapears after other windows cover it. I also tried to create a new class "MyStatic" derived from "CStatic", I put the drawing in the function "OnPaint()",however it always flashes. Please help me to solve the problem,Thank you very much! > I have found many times,when i use CStatic,how can we make it's > painting absolutely stable?The drawing on it always disapears after > other windows cover it. > I also tried to create a new...

CSliderCtrl : Overwriting the tooltip text
Hello All, I would like to change the text from the default tooltip of a Slider control. The default settings show the position but I would like to show a range name instead. Anyone knows how to do this? Regards, Well, I found a way... I have created an object CToolTipCtrl which I update the rect to reflect the thumb rect position and the text in WS_HSSCROLL and NM_RELEASEDCAPTURE with the functions UpdateTipText() and SetToolRect(). Don`t know if there are better ways to do it but this work well for now. "Keaven Pineau" <keavenpineau-no-more-spam@v...

CTabCtrl tabs and tooltips #2
Sorry if this is a repost. I need to get tooltips working for tabs on a CTabCtrl. I use the following code (pTips is a CToolTipCtrl*, pTab is a CTabCtrl*) pTab->SetToolTips(pTips); // then for each tab I do pTab->InsertItem( index, text ); pTab->GetItemRect( index, someCRect ); pTips->AddTool( pTab, sometext, someCRect, index ); I get tooltips just fine on all tabs except tab zero, which causes an ASSERT failure (if I ignore the ASSERT it works OK but this isn't allowed where I work -- it must run without ASSERTing in debug mode). Does anyone know how to get a tooltip on th...

Balloon style Tooltip control
Hello, I am trying to create a Tooltip control with TTS_BALLOON style. It is giving compilation error when I used it. TTS_BALLOON - Undeclared identifier. I checked the commctrl.h, it doesn't contain TTS_BALLOON. My environment is Win XP, VC++ 6.0, SP-6, IE-6.0 and my comctl32.dll version is 5.82(checked using DllGetVersion). MSDN says, TTS_BALLOON style is available from the version 5.80 I think the problem is I do not have proper header files. Is there any seperate installation package available for common controls, so that it will update the system directory/Visual studio install di...

Device Context problems with CStatic
I have added a CStatic control (Picture) to display thumbnails, on a Dialog window. The image file is loaded and a pointer to IPicture (IPicture *m_pPic;) is set. I get a pointer to the CStatic's DC using: CDC* pdc = m_cPicture.GetDC(); I later use Render() to draw the image into the DC. It works but the image is displayed far beyond the bounds of the CStatic control! I would like to force it to a 96 x 96 pixel size, and eventually resize the image(s) with a correct aspect ratio. Thanks. Why not CClientDC dc(&m_cPicture); which gives you the DC without any problem. In additi...

Connexion between CToolBar / CStatusBar / ToolTip
Hi, How are managed tooltip and text in the status bar, when a user if over a button in a toolbar ? I have a special toolbar, where this behavior is not working, so i need to manualy update my status bar, and the tooltip window. In TOOLTIP.CPP, a tooltip is created CWnd::FilterToolTipMessage() (in normal way). In my case, this method is not called, and i have not foud where status bar is updated. Thanks for your help. I am not exactly sure what you asked. The tooltip for a toolbar button is extracted from the string that you can edit in properties dialog of the button(in resource editor)...

How to display TOOLTIPS
Hello, I am quite new to working with CToolbar and I am trying to figure out how to add tooltips(the one that displays information about button's purpose) to each individual button. I've included CBRS_TOOLTIPS in my code but other than that I have no idea how to add comments to each one. Could somebody help me with that please? Here is my toolbar creation code: if (!m_toolbar.Create(this) || !m_toolbar.LoadBitmap(IDR_TOOLBAR1) || !m_toolbar.SetButtons(MainButtons, sizeof(MainButtons)/sizeof(UINT))) { TRACE0("Failed to create mainbar\n"); return -1; // fail ...

Changing Background Color in a CStatic object
I'm trying to change the background of a static text string within a CFormView dialog box. I can change the background of the dialog box, but not the static strings, e.g., the dialog box is set to white, but the background of the CStatic text string is still gray. I've tried trapping out the object when I get the WM_ERASEBKGND for the dialog box, but no success. Any ideas? Joseph Rooney wrote: > I'm trying to change the background of a static text string within a > CFormView dialog box. I can change the background of the dialog box, but not > the static strings, e.g.,...

Transparent Flag for CStatic in resource Editor
Is this flag supposed to work? I am trying to see what this flag does. My text is still covering up the background behind it when I set it to true. Thanks Simon I'm not sure what that does and the help says precious little too, but this control that Ali wrote works well. http://www.codeguru.com/cpp/controls/staticctrl/datadisplaycontrols/article.php/c8829/ http://www.codeproject.com/staticctrl/TransparentStaticCtrl.asp Tom "Simon Guertin" <sguertin@AtTrelliaNetworks.com> wrote in message news:OwlDTKMLGHA.3064@TK2MSFTNGP10.phx.gbl... > Is this flag supposed to ...

How to determine the width of CStatic
Hi, My env: Windows2000, VC++6.00, MFC I am wondering how to dynamically determine the width of CStatic, so that the text will be displayed in full. Thanks. ------------------ William Hello William, > I am wondering how to dynamically determine the width of CStatic, You can use GetClientRect/GetWindowRect to get the size of a window. -- Ajay Kalra [MVP - VC++] ajaykalra@yahoo.com Thanks Ajay. But what I want was "set" the size of CStatic not "get". I mean that before calling SetWindowPos(,,,cx,,SWP_NOMOVE|SWP_SHOWWINDOW), how should I calculate the cx of the...

Transparent CStatic on Dialog with image in background
Hi everyone! I'm developing a little program for windows mobile (think problem should be the same for Win32) in MFC and have problems displaying a dialog with an JPEG-image in the background and placing some transparent CStatic's above it. Here is what I dit: BOOL CMyDialog::OnEraseBkgnd(CDC * pDC) { BOOL bRet = CDialog::OnEraseBkgnd(pDC); // draw background image CComPtr<IImagingFactory>pFactory; HRESULT hr = pFactory.CoCreateInstance(CLSID_ImagingFactory); IImage* pImg; hr = pFactory->CreateImageFromFile(_T("\\myBackImage.jpg"), &pImg); RECT a; a.bott...

Not able to handle WM_CHAR in CStatic-derived control
Hello, I have a CStatic-derived control inside a CFormView-derived window. That control would need to handle WM_CHAR messages, so I have written the corresponding OnChar handle as a member of the control class. Unfortunately, nothing happens durgin the execution when I press a key like 'a'. The code inside "OnChar()" never gets reached (I have put a "AfxMessageBox()" in it for tracking). The focus is own by th control, I have verified it. I would really appreciate some help in finding out the cause of this strange (to me) behaviour. T...

Background of CStatic derived-class
I have a CStatic derived-class to draw text with color and what not. The simplified code for OnPaint() looks as follows: ----------------------------- CPaintDC dc(this); // device context for painting CRect rClient; GetClientRect( &rClient ); int iSavedDC = dc.SaveDC(); UINT nMode = dc.SetBkMode( TRANSPARENT ); COLORREF crPrevText = dc.SetTextColor( m_crText ); CFont* pOldFont = dc.SelectObject( m_pFont ); dc.DrawText( m_csText, &rClient, DT_VCENTER | DT_SINGLELINE ); dc.SetBkMode( nMode ); dc.SetTextColor( crPrevText ); dc.SelectObject( pOldFont ); dc.RestoreDC( iSavedDC ); -------...

How to make CStatic just like ToolTip on the dialog
Good afternoon everybody. I have a dialog window where I need to show something like a tooltip or a hint. Some message that have to be visible on the dialog until I'll hide. Other controls placed on the dialog should be able to redraw that part of dialog and make my tooltip partly or full hidden. For that I choose a CStatic. When I need to show a hint I call ModifyStyle(NULL, WS_VISIBLE) and the same function for hiding. But. On the background there are buttons that are owner draw. so even if my CStatic is visible it is transparent for a mouse. and if user put a cursor on my CStatic an te...

Datatip tooltip problem
I've a view containing a chart control and would lke to have datatips similar to an Excel chart. class CChildView:public CWnd { CChartCtrl m_chart; } class CChartCtrl:public CWnd{} I've tried EnableTrackingToolTips() in CChartCtrl::OnCreate() and overriding the HitTest (returning -1 if the point is close to the previous call and 1 otherwise) and TTN_NEEDTEXT handler. This just about works, but the tip only continues to be displayed while the cursor is over the tip, so moving down/right keeps the tip but up/left hides it. And the tip is partially hidden under the cursor and has ...

Adding ToolTips to Toolbar
I have a CToolbar object with some of the buttons assigned to dynamically generated menu ID's. How do I create and attach a ToolTip to a button with a dynamically generated menu ID? > I have a CToolbar object with some of the buttons assigned to dynamically > generated menu ID's. How do I create and attach a ToolTip to a button with a > dynamically generated menu ID? You need to handle TTN_NEEDTEXT. See this link for previous discussion on this: http://tinyurl.com/3m339 --- Ajay That worked. Thanks, Ajay! "Ajay Kalra" wrote: > > I have a CToolbar obj...

Onenote should have a way to turn tooltips off.
OneNote presents a tooltip whenever the cursor/pen hovers over a notebook, a page tab, etc. It is distracting and is really unnecessary. It might be of use to some folk, but not all. A switch should be added to allow the user to turn it off or on. ---------------- This post is a suggestion for Microsoft, and Microsoft responds to the suggestions with the most votes. To vote for this suggestion, click the "I Agree" button in the message pane. If you do not see the button, follow this link to open the suggestion in the Microsoft Web-based Newsreader and then click &qu...

Multiline tooltips #2
hi, Is it possible to have multiline tooltips ? thanks, Behzad "behzad Nazari" <behzadvc@yahoo.com> wrote in message news:%23BUIWwptDHA.3468@TK2MSFTNGP11.phx.gbl... > hi, > Is it possible to have multiline tooltips ? > > thanks, > Behzad > > Yes it is. I am not sure as the version specifics, however Baloon tooltips can accomplish this (and iirc so can normal tooltips). Check the MSDN documentation on the CreateToolTipEx function (this may or may not be the correct function, but it is sure to find you the correct one). "behzad Nazari" ...

Tooltips
Hello! This may be asking a lot from Excel, but is there a way to do th following, in Excel 2000: When you move the cursor over a cell with a date in it, for a toolti to appear above it showing the difference in days between that date an today? Thanks, Dan -- Message posted from http://www.ExcelForum.com Cells do not have tool tips. The nearest thing may be cell comments but cell comments are static text. You could use a macro to add the comment text you want to all date cells but it would have to be re-run every day. This example works on date cells in the current selection. Sub Date...

MDI document window and toolbar tooltips
I have MDI application. There is class CMyMDIChildFrame derived from CMDIChildWindow (used for creating document template) I have added toolbar. Toolbar is created with CBRS_TOOLTIPS style. Problem is that when mouse on some button in toolbar, then it displays tooltip only if window ownering toolbar is not active. When I activate (by mouse click) child window with toolbar, it does not display tooltips, when I activate other child window then tooltips for my child window is displayed. I tried also to use way: EnableTooltips() and ON_NOTIFY_EX( TTN_NEEDTEXT, 0, OnTTNNeedText ), but result...

dynamic_cast<CStatic*>(GetDlgItem(...)) => 0 but (CStatic*)GetDlgItem(...) works
{ CWnd* p1 = GetDlgItem(IDC_STATICABOUTVERSION); CStatic *p2 = dynamic_cast<CStatic*>(p1); LOGINFO((void*)p1 << " => " << (void*)p2); } 17:15:34.792 - INFO - CAboutDlg::OnInitDialog() - 016B46A8 => 00000000 Any thoughts? Bill Out until Monday - hooray! Turn on RTTI, under the C/C++/Language settings. AliR. "Bill Davy" <Bill@XchelSys.co.uk> wrote in message news:uoK%232r6LJHA.1304@TK2MSFTNGP02.phx.gbl... > { > > CWnd* p1 = GetDlgItem...

problem with clearing image in a CStatic control
Hi, I'm working on a code to load a preview image. I'm able to load the image in the control but unable to clear it. I'm developing something like an Open file dialog where in if I click a file I should see the preview of the file. Once I double click on a subfolder, it should show me the contents of the subfolder and reset the image in the Static control. Now I'm able to load my Bitmap using CStatic::SetBitmap(hBitmap). But once I click on a folder I should reset it to nothing and I dont know how to do that. Thank you. Rajesh. How about setting it to a bitmap that is 1x1 ...

redraw CStatic Custom when dialog get focus ?
I have a CStatic custom control, when I start my dialog its draw very good, but when after I display and close a MessageBox over it only a few areas of the statc contrl is redraw. Why OnPaint() didn't paint a complete control as it does when I start my dialog. but when I put another app that cover all dialog's area and back to my project the static contol is paint complete as I started it. do I need to do semething else to make CStatic1::OnPaint () run after messagebox() ? Thanks in advance for your help, Eduardo This is surprising. The only condition under which this norma...

How to show tooltip in Statusbar?
Platform: Windows 2000, VC++ .NET Hello, In my MDI application, I am working on displaying a document's complete detail information on the status bar.However if the detail is too long then user is unable to read whole detail as there is no provision for scrolling in statusbar. Is there some way I can implement a tooltip in status bar. Any pointers or help would be of great use. Thanks and Regards Rinku. "Ganga Sridhar" <gangasridhar@abosoftware.com> wrote in message news:eIL%236ayRFHA.3336@TK2MSFTNGP10.phx.gbl... > > > Platform: Windows 2000, VC+...

Tooltips working in MFC app, but not from DLL
I have a class which is derived from CWnd. It creates a couple of buttons, which have tooltips. Tooltips is implemented by calling EnableToolTips() and by handling the generated messages: ON_NOTIFY_EX_RANGE(TTN_NEEDTEXTW, 0, 0xFFFF, OnToolTipNotify) ON_NOTIFY_EX_RANGE(TTN_NEEDTEXTA, 0, 0xFFFF, OnToolTipNotify) The code works fine. But, I have taken my code and placed it into a DLL. The DLL has one entry point. There I create my class, including the buttons. When my code is in a dll, tooltips no longer works. OnToolTipNotify never gets called. In stepping through the code, ...