Robertas
Robertas

Reputation: 1222

How to get control id from its handle?

How would one get an id of a control given its handle?

I want to set a tooltip on ListView control's header. As far as I figured out I need an id of the control to which I want to add this tooltip. As described in MSDN.

Upvotes: 3

Views: 20243

Answers (3)

ewu11
ewu11

Reputation: 65

Here is a simple method I wrote for that:

// get identifier to a window
void showWindowID(HWND windowTarget) {
    int theID = GetDlgCtrlID(windowTarget);

    wchar_t text_buffer[100] = { 0 }; 

    // convert
    swprintf(text_buffer, _countof(text_buffer), L"%d", theID); 

    // print to console
    //OutputDebugString(text_buffer); 

    // output result to a messagebox
    MessageBox(nullptr, text_buffer, L"The ID", MB_OK);
}

Upvotes: 0

Remy Lebeau
Remy Lebeau

Reputation: 596497

Use ListView_GetHeader() to get the HWND of the ListView's Header control (which would be the replacement for the GetDlgItem() call in the sample you linked to). You do not need to get the Header's Control ID.

Upvotes: -1

Deanna
Deanna

Reputation: 24273

To answer your immediate question, GetDlgCtrlID().

Note that the sample you linked to immediately converts the toolID back to a handle again making your call redundant.

Upvotes: 13

Related Questions