首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > .NET > .NET >

如果使用api 隐藏任务栏下的标题栏

2013-01-06 
如果使用api 隐藏任务栏上的标题栏?是其它程序的标题栏,只隐藏任务栏上的标题,但不隐藏程序窗口即不使用Sh

如果使用api 隐藏任务栏上的标题栏?
如果使用api 隐藏任务栏下的标题栏

是其它程序的标题栏,只隐藏任务栏上的标题,但不隐藏程序窗口即不使用ShowWindow,如何实现?谢谢
[解决办法]
隐藏任务管理器在任务栏上的标题栏:
OperateButtonInTaskbar('Windows 任务管理器', otHide)

uses CommCtrl;

type
  TOperationType = (otHide = 1, otShow = 0, otDelete = 2);

function OperateButtonInTaskbar(const ACaption: string; AOperation:
  TOperationType = otHide): Boolean;
type
  PTBButtonEx = ^TTBButtonEx;
  TTBButtonEx = packed record
    Button: TTBButton;
    Caption: array[0..MAXBYTE-1] of Char;
  end;
var
  TaskbarHandle: HWND;
  PID, ProcessHandle, NumberOfBytesRead: Cardinal;
  AllocatedMem: PTBButtonEx;
  ButtonInfo: TTBButtonEx;
  I, CaptionLength: Integer;
begin
  Result := False;

  TaskbarHandle := FindWindow('Shell_TrayWnd', nil);
  TaskbarHandle := FindWindowEx(TaskbarHandle, 0, 'ReBarWindow32', nil);
  TaskbarHandle := FindWindowEx(TaskbarHandle, 0, 'MSTaskSwWClass', nil);
  TaskbarHandle := FindWindowEx(TaskbarHandle, 0, 'ToolbarWindow32', nil);
  if TaskbarHandle = 0 then Exit;

  GetWindowThreadProcessId(TaskbarHandle, PID);
  ProcessHandle := OpenProcess(PROCESS_VM_OPERATION or PROCESS_VM_READ, False,
    PID);
  if ProcessHandle = 0 then Exit;
  AllocatedMem := VirtualAllocEx(ProcessHandle, nil, SizeOf(TTBButtonEx),
    MEM_COMMIT, PAGE_READWRITE);
  if AllocatedMem = nil then Exit;

  for I := 0 to SendMessage(TaskbarHandle, TB_BUTTONCOUNT, 0, 0)-1 do
  begin
    if SendMessage(TaskbarHandle, TB_GETBUTTON, I, Integer(AllocatedMem)) = 0
      then Exit;
    if not ReadProcessMemory(ProcessHandle, AllocatedMem, @ButtonInfo,
      SizeOf(TTBButton), NumberOfBytesRead) then Exit;
    CaptionLength := SendMessage(TaskbarHandle, TB_GETBUTTONTEXT,
      ButtonInfo.Button.idCommand, Integer(@AllocatedMem^.Caption));
    if CaptionLength = -1 then Exit;
    if not ReadProcessMemory(ProcessHandle, @AllocatedMem^.Caption,
      @ButtonInfo.Caption, SizeOf(ButtonInfo.Caption), NumberOfBytesRead) then Exit;
    if ButtonInfo.Caption = ACaption then
    begin
      if AOperation = otDelete then
        Result := BOOL(SendMessage(TaskbarHandle, TB_DELETEBUTTON, I, 0))
      else
        Result := BOOL(SendMessage(TaskbarHandle, TB_HIDEBUTTON,
          ButtonInfo.Button.idCommand, Ord(AOperation)));


      SendMessage(TaskbarHandle, TB_AUTOSIZE, 0, 0);
      Break
    end
  end;

  VirtualFreeEx(ProcessHandle, AllocatedMem, 0, MEM_RELEASE);
  CloseHandle(ProcessHandle);
end;

热点排行