我只知道程序名比如:ndasmgmt.exe
该程序运行只在托盘有一个图标,不知道有没有主窗体(我没有取到主窗体句柄)
点击图标会有一个弹出菜单,
我用钩子点击图标时会获取到一个句柄。不知道这个句柄是什么句柄。
我想做的就是在我的程序里可以操作这个托盘,
并操作弹出菜单里面的菜单。
请高手赐教啊。很急。
我没有分,真的,这是我能放的最多的分了。

解决方案 »

  1.   

    通过进程PID去查这个程序的主窗口句柄EnumWindows(@EnumTopProc, PID);  //通过PID枚举窗口
    ...
    ...function EnumTopProc(wnd: HWND; LParam: DWORD): BOOL; stdcall;
    var
     ID: DWORD;
     WndCaption: array[0..254] of char;
     WndClassName: array[0..254] of char;
     ListItem:TListItem;
    begin GetWindowThreadProcessId(wnd, @ID);
     GetWindowText(wnd, @WndCaption, 254);
     GetClassName(wnd, @WndClassName, 254); if ID = LParam then
      begin
         ListItem:=Form1.ListView1.Items.Add;
         ListItem.Caption:=StrPas(WndCaption);// 这个是窗口名
         ListItem.SubItems.Add(IntToHex(wnd, 6));//窗口句柄
         ListItem.SubItems.Add(StrPas(WndClassName)); //窗口类名
      end;
      Result := True;
    end;