0

I want to get quick launch bar size, but my code returns false, where is the problem?

REBARBANDINFOW prbi;
memset(&prbi, 0, sizeof(REBARBANDINFOW));

prbi.cbSize = sizeof(REBARBANDINFOW);
prbi.fMask = 892;

HWND hWndTray = ::FindWindow(L"Shell_TrayWnd", 0);
HWND hRebar = ::FindWindowEx(hWndTray, NULL, L"ReBarWindow32", 0);
int i = ::SendMessage(hRebar, RB_GETBANDINFOW, 0, (LPARAM)(LPREBARBANDINFOW)&prbi);
Furqan Safdar
  • 16,260
  • 13
  • 59
  • 93

2 Answers2

1

The problem is with the LPARAM of RB_GETBANDINFOW. The address of the structure you are sending is only valid in your own address space, not that of Explorer. Luckily, Explorer detects this and fails gracefully instead of blowing up.

One way to solve this is to use VirtualAllocEx to allocate the REBARBANDINFOW in Explorer's memory, use WriteProcessMemory to initialize it, send the message, and finally call ReadProcessMemory to read the result.

I've successfully used this technique in a Python script to automatically set the Quick Launch's size.

efotinis
  • 14,565
  • 6
  • 31
  • 36
  • Make sure you are setting prbi.cbSize to the correct size for XP (i.e. 80, if I'm not mistaken). Notice that REBARBANDINFO contains extra members if `_WIN32_WINNT >= 0x0600`. Therefore, if you're compiling in Win7, the structure you'll be sending to XP's Explorer will be too big and it will be rejected. – efotinis Nov 08 '12 at 15:35
  • Thank you,it's resolved.But there is another quesion [about show quick launch bar] (http://stackoverflow.com/questions/13302460/i-want-show-quick-launch-bar-in-code) – user1805887 Nov 09 '12 at 05:30
  • @user1805887 If it the answer resolved your problem, you should mark it as the accepted answer. Refer to the [faq] for more information. – Mohammad Dehghan Nov 10 '12 at 08:51
0

You are trying to get too much info. Place prbi.fMask = 32; or prbi.fMask = 64;.

Brian Cannard
  • 852
  • 9
  • 20