Click here to Skip to main content
13,594,948 members
Rate this:
Please Sign up or sign in to vote.
See more:

I use GetDlgCtrlID to show tooltips on my buttons.

This worked well before.

Now I copied a bunch of buttons to an other dialog, which gave me some issues with the resource.h file.
I fixed these manually

Now it seems the buttons that were copied don't return their ID with GetDlgCtrlID
not in the new dialog, neither in the original dialog.

However, in the solution explorer visual studio fives me a tooltip with the correct ID
#define IDC_LOCK 11297    (tooltip this corresponds with resource.h)

Any ideas on this one?
my guess is to clean the resources, but that will be a pain, since it is a big file.
or can it be done automatically?

Posted 15-Nov-12 3:54am
Rate this: bad
Please Sign up or sign in to vote.

Solution 1

If the function is not returning the id then you need to check with GetLastError() to find out why. Also the piece of code you posted above does not prove anything. Having a #define statement in a file does not mean it matches anything else in your project. Maybe you need to show some more of your code.
Rate this: bad
Please Sign up or sign in to vote.

Solution 2

Here is the code that handles the tooltips

It works fine for all original buttons.
for the ones i copied from an other dialog, it does not work
it will not return an ID

BOOL CSend_DataDlg::OnToolTipNotify( UINT id,
                                  NMHDR * pNMHDR,
                                  LRESULT * pResult )
	AFX_MODULE_THREAD_STATE* pModuleThreadState =AfxGetModuleThreadState();
		CToolTipCtrl* pToolTip = pModuleThreadState->m_pToolTip;
    // Get the tooltip structure.

    // Actually the idFrom holds Control's handle.
    UINT CtrlHandle = pNMHDR->idFrom;

    // Check once again that the idFrom holds handle itself.
    if ((pTTT->uFlags & TTF_IDISHWND))
        // Get the control's ID.
        UINT nID = ::GetDlgCtrlID( HWND( CtrlHandle ));
        // Now you have the ID. depends on control,
        // set your tooltip message.
		CString str;
		str.Format("%i", nID);
//this is just to check if the ID is read
		switch( nID )
			//activate button
	    case IDC_MAP_1:
                pTTT->lpszText = _T("Write curves of map 1");
	    case IDC_MAP_2:
		pTTT->lpszText = _T("Write curves of map 2");
Richard MacCutchan 16-Nov-12 6:26am
Use your debugger to look at all the returned values, and check what error is being raised when GetDlgCtrlID() returns 0.
Richard MacCutchan 16-Nov-12 6:27am
Also please don't post additional information as a solution (it's not). Use the "Improve Question" link.
Rate this: bad
Please Sign up or sign in to vote.

Solution 3


I solved it, appearently by copying the buttons they were placed "beneath" a group box that groups the buttons.

So the mouse pointer actually pointed to the group box instead of the buttons...

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month

Advertise | Privacy | Cookies | Terms of Service
Web04 | 2.8.180621.3 | Last Updated 19 Nov 2012
Copyright © CodeProject, 1999-2018
All Rights Reserved.
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100