Hi everyone,
I must create a Combobox having ToolTips. I saw this article http://www.codeguru.com/cpp/controls...icle.php/c4949 but it seems not working.
Tooltip text and its combo item must be different.
Someone could help me?
Thank you
Printable View
Hi everyone,
I must create a Combobox having ToolTips. I saw this article http://www.codeguru.com/cpp/controls...icle.php/c4949 but it seems not working.
Tooltip text and its combo item must be different.
Someone could help me?
Thank you
What "seems not working"?
- What type of application are you using (dialog, SDI, MDI, ...)?
- How do you create this combobox: in a resource editor or dynamically using Create/CreateEx (if dynamically - show your code)
- how did you implement the PreSubclassWindow call?
- What is the exact error message for 'CreateEx() has wrong arguments" and how do you call this CreateEx?
1 Dialog called in a MDI application
2 Resource Editor
3 I've just created a method having the same code of PreSubclassWindow() and I've called it.
4 m_lstCombo.CreateEx( 0, WC_LISTVIEW, NULL, dwStyle, rc, this, 0 ); [from TooltipComboBox.cpp]
while
CListCtrl::CreateEx( In_ DWORD dwExStyle, _In_ DWORD dwStyle, _In_ const RECT& rect, In_ CWnd* pParentWnd, _In_ UINT nID); [from afxcmn.h]
1. What does the list view control class WC_LISTVIEW have to do with the combobox? :confused:
2. You haven't answered my questions 3 and 4. If you are not going to show your actual code and error messages then don't expect any real help.
3. Please, use Code tags while posting code snippets.
1 I don't know, I only reported the call made in CTooltipComboBox class found at that link (that is different to CListCtrl::CreateEx).
2 I answered to your questions.
2.3) I created a dummy method equal to CTooltipComboBox::PreSubclassWindow(). It was just a way to force PreSubclassWindow, that is an "event method" that should be automatically called during CTooltipComboBox creation but it doesn't. Forget this part.
2.4) Error code is ...\tooltipcombobox.cpp(100): error C2660: 'CListCtrl::CreateEx' : function does not take 7 arguments. This is due to the fact that in that class CreateEx has 7 paramaters, while CListBox::CreateEx has 5 (as I shown).
3 Sorry, but I don't see a button to add code quotes. Is this syntax correct?: <Code> example </Code>
You didn't.
I asked you to post your actual code (snippet), not a part of a line without any context.
And how does this line 100 (and some others above and below it) look like? :confused:
No, this syntax is wrong.
Please, read what you had to read before doing any post here: Announcement: Before you post....
PreSubclassWindow() is not called => m_lstCombo is not initialized => calling CTooltipComboBox::SetItemTip() my application crashesCode:void CTooltipComboBox::PreSubclassWindow()
{
CRect rc( 0, 0, 10, 10 );
DWORD dwStyle = WS_POPUP | WS_BORDER | LVS_REPORT | LVS_NOCOLUMNHEADER | LVS_SINGLESEL | LVS_OWNERDATA;
m_lstCombo.CreateEx( 0, WC_LISTVIEW, NULL, dwStyle, rc, this, 0 ); // row 100, m_lstCombo is CTooltipListCtrl object, where class CTooltipListCtrl : public CListCtrl.
DWORD dwStyleEx = m_lstCombo.GetExtendedStyle( );
m_lstCombo.SetExtendedStyle( dwStyleEx | LVS_EX_FULLROWSELECT );
m_lstCombo.Init( this );
CRect rcAll;
GetDroppedControlRect( &rcAll );
GetWindowRect( &rc );
SetDroppedWidth( rcAll.Width( ) );
SetDroppedHeight( rcAll.Height( ) - rc.Height( ) );
CComboBox::PreSubclassWindow( );
EnableToolTips( );
}
Code:int CTooltipComboBox::SetItemTip( int nRow, CString sTip )
{
return m_lstCombo.SetItemTip( nRow, sTip );
}
What is CTooltipComboBox? how is it declared?
What is m_lstCombo and which CreateEx method is used? Is it CTooltipListCtrl method? :confused:
In the first message of this thread I posted this link, telling that is not working: http://www.codeguru.com/cpp/controls...icle.php/c4949
at the end of the article there's a download part, where we can download CTooltipComboBox.cpp, CTooltipComboBox.h, CTooltipListCtrl.cpp and CTooltipListCtrl.h files.
I'm trying to use that two classes, but I have the problems I described.
I'm not going to download this code and then test it and compare with rgese couple of line you have posted.
It is very clear that if your code doesn't compile (as you stated in the post#7) it cannot run and therefore cannot produce any crash.
If it does compile then what does your post#7 mean? :confused:
If we ignored this post#7 and suggested that your code compiles and links but thenthen I'd say you implemented it wrong.Quote:
Originally Posted by symreds
Besides:What is MyPreSubclassWindow? What does "[equal to PreSubclassWindow" mean in this context? How is this function called? :confused:Quote:
Also creating MyPreSubclassWindow() [equal to PreSubclassWindow()], my application crashes when I try to create m_lstCombo.
How exactly does your app "crash"?
The code we can download does not compile because m_lstCombo.CreateEx() has 7 parameters instead of 5. For this reason I changed the code in this way
then in my program I declared the object in this way:Code:m_lstCombo.CreateEx( 0, dwStyle, rc, this, 0 );
when I doCode:CTooltipComboBox *pCombo = (CTooltipComboBox*)GetDlgItem(IDC_... ); // IDC_... resource ID of my combo
my application crashes. Call stack: m_lstCombo is not inizialized.Code:pCombo->SetItemTip(iCount, strTips);
I searched where m_lstCombo should be created (CTooltipComboBox::PreSubclassWindow()) => put a breakpoint inside it => PreSubclassWindow() is never called.
I tryed to create a public method (CTooltipComboBox::MyPreSubclassWindow()) with the same code of PreSubclassWindow() and I called it after pCombo definition => application crashes in
in particular it crashes here:Code:m_lstCombo.CreateEx( 0, dwStyle, rc, this, 0 );
Code:BOOL CListCtrl::Create(DWORD dwStyle, const RECT& rect, CWnd* pParentWnd,
UINT nID)
{
// initialize common controls
VERIFY(AfxDeferRegisterClass(AFX_WNDCOMMCTL_LISTVIEW_REG));
CWnd* pWnd = this;
return pWnd->Create(WC_LISTVIEW, NULL, dwStyle, rect, pParentWnd, nID); // here
}
Remove your MyPreSubclassWindow.
Implement the virtual PreSubclassWindow but do it correctly! usually you should use ClassWizard (in VC6 or VS2010) or some similar tool in other IDEs
...but virtual PreSubclassWindow is already implemented in the code we download. I don't know how to do it "correctly".
Of course I cannot post my code here because my company has rights on it. Anyway the code is more or less this:
Code:CTooltipComboBox *pCombo = (CTooltipComboBox*)GetDlgItem( IDC_... ); // IDC_.... resource index of my combo
for( number of combo items )
{
pCombo->AddString( combo item name );
pCombo->SetItemTip( counter, tooltip text );
}
Declaration/definition of PreSubclassWindow are in CTooltipComboBox.h/.cpp
Anyway, I've always used GetDlgItem instead of a control variable... I think it's the same...
I don't care what you have "lways used".
But my question is: do you only "think it's the same" or you are sure?
And how about the article you referred to:Quote:
To use this combo box, follow the following steps:
- Include TooltipComboBox.h, TooltipComboBox.cpp, TooltipListCtrl.h and TooltipListCtrl.cpp in your project.
- In the resource editor create a droplist combobox.
- Create a control member variable for the combobox in VC's classwizard.
- Include TooltipComboBox.h and replace CComboBox with CTooltipComboBox in your .h file. Also include afxtempl.h to support CMap.
- To have your own tips, you can either use SetItemTip, SetComboTip functions, or replace GetItemTip function in CTooltipListCtrl, and GetComboTip function in CTooltipComboBox.
Ok, I'm trying to create a control member variable...
I use VS2010 => Class View => I find my dialog class => right click => then? (is this the right procedure?)
Ok... got it, now the application doesn't crash anymore (and I hit the breakpoint inside PreSubclassWindow()!) but now AddStrings() is no more working: I created an empty combo... I'm going to investigate...
Sorry, typo error, I mean CComboBox::AddString() (without "s")
Post #18 (of course without initial GetDlgItem()...)
That code is into MyDialog::OnInitDialog()