Get HWND from ToolBar

  • Thread starter Thread starter Andreas Selle
  • Start date Start date
A

Andreas Selle

Hi,

I know the FAQ and tried it using GetCapture. However { aControl.Capture =
true; } does not work, the Capture property remains false and the native
GetCapture returns zero. The very same code works with other control types
well.

Any alternative suggestions?

BTW: I try to get the HWND because I want to send a TB_SETTOOLTIPS message
which I already prepared so nicely.

Andreas
 
Thanks, it works! I now have ToolTips for my ToolBar items! For those who
dare to do that same, find my C# (well looks more like C++) code below.
Please note, that one must pass a ToolTip entry for every Menu Bar item, not
just buttons.

Andreas Selle
http://subsembly.com/

-------

private unsafe void SetMenuBarToolTips(string[] vsToolTips)
{
// HACK: 1000 bytes should be large enough for our tool tips.
IntPtr pMemory = LocalAlloc(0, 1000); // P/Invoke

int nToolTips = vsToolTips.Length;
IntPtr* pToolTipArray = (IntPtr*)pMemory.ToPointer();
char* pToolTip = (char*)(pToolTipArray + nToolTips + 1);

for (int i = 0; i < nToolTips; ++i)
{
*pToolTipArray++ = new IntPtr(pToolTip);
string sToolTip = vsToolTips;
if (sToolTip != null)
{
for (int j = 0; j < sToolTip.Length; ++j)
{
*pToolTip++ = sToolTip[j];
}
}
*pToolTip++ = '\0';
}
*pToolTipArray++ = IntPtr.Zero;

this.Capture = true;
IntPtr hWndParent = GetCapture(); // P/Invoke
this.Capture = false;
IntPtr hWnd = SHFindMenuBar(hWndParent); // P/Invoke

int lResult = SendMessage(hWnd, 0x0400 + 81, nToolTips, pMemory); //
P/Invoke
}

[DllImport("coredll.dll")]
private static extern IntPtr LocalAlloc(uint fuFlags, uint cbBytes);

[DllImport("coredll.dll", SetLastError=true)]
private extern static IntPtr GetCapture();

[DllImport("aygshell.dll")]
private extern static IntPtr SHFindMenuBar(IntPtr hwnd);

[DllImport("coredll.dll", SetLastError=true)]
private extern static int SendMessage(IntPtr hWnd, int nMsg, IntPtr wParam,
IntPtr lParam);
 
Back
Top