CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Page 1 of 2 12 LastLast
Results 1 to 15 of 29
  1. #1
    Join Date
    Sep 2010
    Posts
    29

    Create Combobox with ToolTips

    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

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

    Re: Create Combobox with ToolTips

    What "seems not working"?
    Victor Nijegorodov

  3. #3
    Join Date
    Sep 2010
    Posts
    29

    Re: Create Combobox with ToolTips

    Quote Originally Posted by VictorN View Post
    What "seems not working"?
    PreSubclassWindow() is not automatically called, for this reason m_lstCombo is not initialized and also CreateEx() has wrong arguments.

    Also creating MyPreSubclassWindow() [equal to PreSubclassWindow()], my application crashes when I try to create m_lstCombo.

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

    Re: Create Combobox with ToolTips

    Quote Originally Posted by symreds View Post
    PreSubclassWindow() is not automatically called, for this reason m_lstCombo is not initialized and also CreateEx() has wrong arguments.

    Also creating MyPreSubclassWindow() [equal to PreSubclassWindow()], my application crashes when I try to create m_lstCombo.
    1. What type of application are you using (dialog, SDI, MDI, ...)?
    2. How do you create this combobox: in a resource editor or dynamically using Create/CreateEx (if dynamically - show your code)
    3. how did you implement the PreSubclassWindow call?
    4. What is the exact error message for 'CreateEx() has wrong arguments" and how do you call this CreateEx?
    Victor Nijegorodov

  5. #5
    Join Date
    Sep 2010
    Posts
    29

    Re: Create Combobox with ToolTips

    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]

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

    Re: Create Combobox with ToolTips

    Quote Originally Posted by symreds View Post
    ...
    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?
    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.
    Victor Nijegorodov

  7. #7
    Join Date
    Sep 2010
    Posts
    29

    Re: Create Combobox with ToolTips

    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>
    Last edited by symreds; October 19th, 2011 at 03:14 AM.

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

    Re: Create Combobox with ToolTips

    Quote Originally Posted by symreds View Post
    ...
    2 I answered to your questions...
    You didn't.
    I asked you to post your actual code (snippet), not a part of a line without any context.

    Quote Originally Posted by symreds View Post
    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).
    And how does this line 100 (and some others above and below it) look like?

    Quote Originally Posted by symreds View Post
    Sorry, but I don't see a button to add code quotes. Is this syntax correct?: <Code> example </Code>
    No, this syntax is wrong.
    Please, read what you had to read before doing any post here: Announcement: Before you post....
    Victor Nijegorodov

  9. #9
    Join Date
    Sep 2010
    Posts
    29

    Re: Create Combobox with ToolTips

    Code:
    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( );
    }
    PreSubclassWindow() is not called => m_lstCombo is not initialized => calling CTooltipComboBox::SetItemTip() my application crashes

    Code:
    int CTooltipComboBox::SetItemTip( int nRow, CString sTip )
    {
    	return m_lstCombo.SetItemTip( nRow, sTip );
    }
    Last edited by symreds; October 19th, 2011 at 04:02 AM.

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

    Re: Create Combobox with ToolTips

    What is CTooltipComboBox? how is it declared?
    What is m_lstCombo and which CreateEx method is used? Is it CTooltipListCtrl method?
    Victor Nijegorodov

  11. #11
    Join Date
    Sep 2010
    Posts
    29

    Re: Create Combobox with ToolTips

    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.

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

    Re: Create Combobox with ToolTips

    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?
    If we ignored this post#7 and suggested that your code compiles and links but then
    Quote Originally Posted by symreds
    PreSubclassWindow() is not automatically called
    then I'd say you implemented it wrong.

    Besides:
    Also creating MyPreSubclassWindow() [equal to PreSubclassWindow()], my application crashes when I try to create m_lstCombo.
    What is MyPreSubclassWindow? What does "[equal to PreSubclassWindow" mean in this context? How is this function called?
    How exactly does your app "crash"?
    Victor Nijegorodov

  13. #13
    Join Date
    Sep 2010
    Posts
    29

    Re: Create Combobox with ToolTips

    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

    Code:
    m_lstCombo.CreateEx( 0, dwStyle, rc, this, 0 );
    then in my program I declared the object in this way:

    Code:
    CTooltipComboBox *pCombo = (CTooltipComboBox*)GetDlgItem(IDC_... ); // IDC_... resource ID of my combo
    when I do
    Code:
    pCombo->SetItemTip(iCount, strTips);
    my application crashes. Call stack: m_lstCombo is not inizialized.

    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
    Code:
    m_lstCombo.CreateEx( 0, dwStyle, rc, this, 0 );
    in particular it crashes here:

    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
    }

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

    Re: Create Combobox with ToolTips

    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
    Victor Nijegorodov

  15. #15
    Join Date
    Sep 2010
    Posts
    29

    Re: Create Combobox with ToolTips

    ...but virtual PreSubclassWindow is already implemented in the code we download. I don't know how to do it "correctly".

Page 1 of 2 12 LastLast

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