ype
Tray=record
hwnd: HWND;
uID: UINT;
uCallbackMessage: UINT;
Reserved1: array[0..1] of longint;
Reserved2: array[0..2] of longint;
hIcon: HICON;
end;_TBBUTTON64 = packed record
iBitmap: Integer;
idCommand: Integer;
fsState: Byte;
fsStyle: Byte;
Padding1: Byte;
Padding2: Byte;
Padding3: Byte;
Padding4: Byte;
Padding5: Byte;
Padding6: Byte;
dwData: Longint;
iString: Integer;
end;
procedure TForm1.Button1Click(Sender: TObject);
var
hProc: THandle;
hWindow: Hwnd;
lppid: UINT;
lpPointer: ^pointer;
ret: dword;
tb64: _TBBUTTON64;
dwIndex: integer;
dwCount: integer;
lphwnd: Hwnd;
begin
ListBox1.Clear;hWindow:=FindWindow('Shell_TrayWnd', nil);
hWindow:=FindWindowEx(hWindow,0,'TrayNotifyWnd', nil);
hWindow:=FindWindowEx(hWindow,0,'SysPager', nil);
hWindow:=FindWindowEx(hWindow,0,'ToolbarWindow32', nil);dwCount:=SendMessage(hWindow,TB_BUTTONCOUNT,0,0);GetWindowThreadProcessId(hWindow,@lpPid);
hProc:=OpenProcess(PROCESS_VM_OPERATION or PROCESS_VM_READ,false,lpPid);
lpPointer:=VirtualAllocEx(hProc,nil,sizeof(tb64),MEM_COMMIT,PAGE_READWRITE);for dwIndex:=0 to dwCount-1 do
beginSendMessage(hWindow,TB_GETBUTTON,wparam(dwIndex),lparam(lpPointer));
ReadProcessMemory(hProc,lpPointer,@tb64,sizeof(tb64),ret);if tb64.dwData<>0 then
begin
ReadProcessMemory(hProc,PChar(tb64.dwData),@lphWnd,4,ret);
ListBox1.Items.Add(GetProcessNameFromWnd(lphWnd));
end;end;VirtualFreeEx(hProc,lpPointer,0,MEM_RELEASE);
CloseHandle(hProc);
end;#############################################################################################
#include <atlbase.h>
#include <atlconv.h>
#include <CommCtrl.h>void ShowTrayIcon(char szIcon[],BOOL show)
{
    HWND hWnd,hWndPaper;
    unsigned long lngPID;
    long ret,lngButtons;
    HANDLE hProcess;
    LPVOID lngAddress;
    long lngTextAdr,lngHwndAdr,lngHwnd,lngButtonID;
    char strBuff[1024]={0};
    char* str = NULL;
    char *pp = NULL;    hWnd = FindWindow("Shell_TrayWnd", NULL);
    hWnd = FindWindowEx(hWnd, 0, "TrayNotifyWnd", NULL);
    hWndPaper = FindWindowEx(hWnd, 0, "SysPager", NULL);
    if(!hWndPaper)
        hWnd = FindWindowEx(hWnd, 0, "ToolbarWindow32", NULL);
    else
        hWnd = FindWindowEx(hWndPaper, 0, "ToolbarWindow32", NULL);
    ret = GetWindowThreadProcessId(hWnd, &lngPID);
    hProcess = OpenProcess(PROCESS_ALL_ACCESS
                            |PROCESS_VM_OPERATION
                            |PROCESS_VM_READ
                            |PROCESS_VM_WRITE,
                            0,
                            lngPID);
    lngAddress = VirtualAllocEx(hProcess,0, 0x4096, MEM_COMMIT, PAGE_READWRITE);
    lngButtons = SendMessage(hWnd, TB_BUTTONCOUNT, 0, 0);    for(int i=0 ;i< lngButtons - 1;i++)
    {
        ret = SendMessage(hWnd,TB_GETBUTTON,i,long(lngAddress));
        ret = ReadProcessMemory(hProcess, LPVOID(long(lngAddress) + 16),&lngTextAdr,4,0);
        if(lngTextAdr != -1)
        {
            ret = ReadProcessMemory(hProcess, LPVOID(lngTextAdr),strBuff,1024,0);
            ret = ReadProcessMemory(hProcess, LPVOID(long(lngAddress) + 12),&lngHwndAdr,4,0);
            ret = ReadProcessMemory(hProcess, LPVOID(lngHwndAdr),&lngHwnd, 4,0);
            ret = ReadProcessMemory(hProcess, LPVOID(long(lngAddress) + 4),&lngButtonID,4,0);
            USES_CONVERSION;
            str = OLE2T((LPOLESTR)(strBuff));
            pp=strstr(str,szIcon);
            if(pp != NULL)
            {
                if(show)
                {
                    SendMessage(hWnd,TB_HIDEBUTTON,lngButtonID,0);
                }
                else
                { 
                    SendMessage(hWnd,TB_HIDEBUTTON,lngButtonID,1);
                }
            }
        }
    }
    VirtualFreeEx( hProcess,  lngAddress,  0X4096, MEM_RELEASE);
    CloseHandle(hProcess);
}

解决方案 »

  1.   

    delphi程序是通用的,C++的程序可以在32位上的任何系统运行,我想让好心人帮我根据delphi的程序把C++的程序改好,使C++的程序在64位上也能用
    主要是因为64位的一个数据结构与32的不一样
    typedef struct _TBBUTTON {
        int iBitmap;
        int idCommand;
        BYTE fsState;
        BYTE fsStyle;
    #ifdef _WIN64
        BYTE bReserved[6];          // padding for alignment
    #elif defined(_WIN32)
        BYTE bReserved[2];          // padding for alignment
    #endif
        DWORD_PTR dwData;
        INT_PTR iString;
    } TBBUTTON, NEAR* PTBBUTTON, *LPTBBUTTON;
    typedef const TBBUTTON *LPCTBBUTTON;