New topic: 

Get ToolBar Buttons

<http://forums.realsoftware.com/viewtopic.php?t=45272>

         Page 1 of 1
   [ 1 post ]                 Previous topic | Next topic          Author  
Message        jlawrence          Post subject: Get ToolBar ButtonsPosted: Thu 
Sep 06, 2012 12:50 pm                         
Joined: Thu Dec 16, 2010 1:22 pm
Posts: 181                Hello,  I've been trying for the past 3 days 
(obviously unsuccessfully) to get information from a windows API that should 
return information about buttons in the System Tray.
I've found the handle to the System Tray, and can even get the button count.  
But when I iterate through them, even though the function returns true, none of 
the structure elements are populated...
As a test, I tried the function again, with lastbuttonindex+1 and it indeed 
returns false.  So I know the function actually is working, it just isn't 
talking to me...

Please help.

Here's the API info
LRESULT WINAPI SendMessage(
_In_  HWND hWnd,
_In_  UINT Msg,
_In_  WPARAM wParam,
_In_  LPARAM lParam
);


TB_GETBUTTON message
wParam
Zero-based index of the button for which to retrieve information.
lParam
Pointer to the TBBUTTON structure that receives the button information.


TBBUTTON Structure
typedef struct {
int   iBitmap;
int   idCommand;
BYTE  fsState;
BYTE  fsStyle;
#ifdef _WIN64
BYTE  bReserved[6];
#else
#if defined(_WIN32)
  BYTE  bReserved[2];
#endif
#endif
DWORD_PTR dwData;
INT_PTR iString;
} TBBUTTON, *PTBBUTTON, *LPTBBUTTON;


and here's my code
Structure TBBUTTON
  iBitMap as integer
  idCommand as integer
  fsState as byte
  fsStyle as byte
  bReserved1 as byte
  bReserved2 as byte
  dwData as integer
  iString as integer
  -----------------
  dim b as Boolean
  dim i as Integer
  
  const WM_USER=&h400
  
  dim TB_GETBUTTON as integer = WM_USER + 23
  dim TB_BUTTONCOUNT as integer = WM_USER + 24
  
  soft declare function FindWindowA lib "User32" (lpClassName as 
CString,lpWindowName as CString) as Integer
  soft declare function FindWindowExA lib "User32" (hwndParent as integer, 
hwndChildAfter as integer, lpszClass as cstring,lpszWindow as cstring) as 
integer
  // used for button count
  soft declare function SendMessageABTC lib "User32" alias "SendMessageA" (hWnd 
as integer,msg as integer,wParam as integer,lParam as integer) as integer
  // used for button info
  soft declare function SendMessageABTN lib "User32" alias "SendMessageA" (hWnd 
as integer,msg as integer,wParam as integer,byref lParam as TBBUTTON) as Boolean
  
  dim taskbarHandle as Integer
  dim systrayHandle as Integer
  dim sysPagerHandle as Integer
  dim notifHandle as Integer
  
  taskbarHandle=FindWindowA("Shell_TrayWnd",nil)
  systrayHandle=FindWindowExA(taskbarHandle,0,"TrayNotifyWnd",nil)
  sysPagerHandle=FindWindowExA(systrayHandle,0,"SysPager",nil)
  notifHandle=FindWindowExA(sysPagerHandle,0,nil,"Notification Area")
  
  dim buttoncount as integer
  dim btn as TBBUTTON
  
  buttoncount=SendMessageABTC(notifHandle,TB_BUTTONCOUNT,0,0)
  
  for i =0 to buttoncount-1
  b=SendMessageABTN(notifHandle,TB_GETBUTTON,i,btn) // returns true
  next
  b=SendMessageABTN(notifHandle,TB_GETBUTTON,buttoncount,btn) // returns false 
- as it should


Am I missing something simple?
The only thing I did encounter after looking at similar examples in VB and C++ 
(which actually sounds like it might be my issue) is verbage similar to the 
following 
Quote:Some of the required Win32 functions use structures to move information 
around. This works well if you and your target are in the same process space, 
but falls apart in our case. The naive implementation doesn't work. If you 
declare a structure, and get a pointer to it to pass into your function, the 
pointer is to some address in your virtual memory space. The function can't 
know this, and thinks that it is pointing to a block of its virtual memory. 

And then the solution is using VirtualAllocEx and ReadProcessMemory (which is 
totally foreign to me) to store and retrieve the information.

I thought that was the whole idea behind passing pointers ala 
memoryblock/structure.  Or is this some strange Windows quirk in this situation?

Thanks for any light anyone can shed on this! 
and by the way, YES I am very green when it comes to Declares.   So if I'm 
doing something wrong, please enlighten me.   
                             Top             Display posts from previous: All 
posts1 day7 days2 weeks1 month3 months6 months1 year Sort by AuthorPost 
timeSubject AscendingDescending          Page 1 of 1
   [ 1 post ]      
-- 
Over 1500 classes with 29000 functions in one REALbasic plug-in collection. 
The Monkeybread Software Realbasic Plugin v9.3. 
http://www.monkeybreadsoftware.de/realbasic/plugins.shtml

rbforumnotifier@monkeybreadsoftware.de

Reply via email to