DELPHI盒子
!实时搜索: 盒子论坛 | 注册用户 | 修改信息 | 退出
检举帖 | 全文检索 | 关闭广告 | 捐赠
技术论坛
 用户名
 密  码
自动登陆(30天有效)
忘了密码
≡技术区≡
DELPHI技术
lazarus/fpc/Free Pascal
移动应用开发
Web应用开发
数据库专区
报表专区
网络通讯
开源项目
论坛精华贴
≡发布区≡
发布代码
发布控件
文档资料
经典工具
≡事务区≡
网站意见
盒子之家
招聘应聘
信息交换
论坛信息
最新加入: monica9612
今日帖子: 0
在线用户: 4
导航: 论坛 -> 论坛精华贴 斑竹:liumazi,iamdream  
作者:
男 richar (旺仔) ★☆☆☆☆ -
盒子活跃会员
2005/4/2 17:29:29
标题:
已知一个窗口的Handle,如何让它不在任务栏上显示. 浏览:6897
加入我的收藏
楼主: 知道QQ的句柄,如何让它不在任务栏上显示。
查了MSDN,SetWindowLong这个函数我的用法是
SetWindowLong(AHandle,WS_EX_TOOLWINDOW,0);
WS_EX_TOOLWINDOW:MSDN中说:
A tool window does not appear in the taskbar ;
为什么使用会无效,
----------------------------------------------
瑞盈软件 http://www.dgwewin.com
blog: http://hi.baidu.com/cnCharles
delphi群:16497064
作者:
男 gzgzlxg (lxg) ★☆☆☆☆ -
盒子活跃会员
2005/4/2 18:11:30
1楼: 我不完QQ,下面给出的是一般程序不在任务栏显示的方法,如没有用,只当没看见。

unit Unit1;

interface

uses
  ShellAPI, Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, Menus;

const
  WM_ICONMESSAGE = WM_USER + 100;

type
  TForm1 = class(TForm)
    PopupMenu1: TPopupMenu;
    Close1: TMenuItem;
    procedure FormShow(Sender: TObject);
    procedure FormCreate(Sender: TObject);
    procedure FormClose(Sender: TObject; var Action: TCloseAction);
    procedure Close1Click(Sender: TObject);
  private
    FWinIcon: HICON;
    procedure minimise(var msg: TMessage); message WM_SYSCOMMAND;
    procedure TaskBarHandler(var msg: TMessage); message WM_ICONMESSAGE;
  end;

var
  Form1: TForm1;
  TrayIcon: TNotifyIconData;

implementation

{$R *.dfm}

procedure TForm1.FormShow(Sender: TObject);
begin
  showwindow(Application.Handle, SW_HIDE);
end;

procedure TForm1.minimise(var msg: TMessage);
begin
  case msg.WParam of
    SC_CLOSE: close;
    SC_MINIMIZE:
      begin
        showwindow(Application.Handle, SW_HIDE);
        showwindow(Form1.Handle, SW_HIDE);
      end;
  else
    DefWindowProc(Form1.Handle, msg.msg, msg.WParam, msg.LParam);
  end;
end;

procedure TForm1.FormCreate(Sender: TObject);
begin
//因为在任务栏没有显示,如果窗口最小化,程序就找不到了,不得已加一个托盘
//显示,并加一个弹出式菜单,以便能够关闭程序。
//因为没有资源文件,只好随便抓一个系统的Icon来使用。
  FWinIcon := LoadImage(0, IDI_INFORMATION, IMAGE_ICON, LR_DEFAULTSIZE,
    LR_DEFAULTSIZE, LR_DEFAULTSIZE or LR_DEFAULTCOLOR or LR_SHARED);
  TrayIcon.cbSize := sizeof(TNotifyIconData);
  TrayIcon.Wnd := Form1.handle;
  TrayIcon.uID := $5678;
  TrayIcon.uFlags := NIF_MESSAGE or NIF_ICON or NIF_TIP;
  TrayIcon.uCallbackMessage := WM_ICONMESSAGE;
  TrayIcon.hIcon := FwinIcon;
  Shell_NotifyIcon(NIM_ADD, @TrayIcon);
end;

procedure TForm1.FormClose(Sender: TObject; var Action: TCloseAction);
begin
  TrayIcon.uFlags := 0;
  Shell_NotifyIcon(NIM_DELETE, @TrayIcon);
end;

procedure TForm1.TaskBarHandler(var msg: TMessage);
var
  Pt: TPoint;
begin
  case msg.LParamLo of
    WM_LBUTTONDOWN:
      begin
        if not IsWindowVisible(Form1.handle) then
          showWindow(Form1.handle, sw_show);
      end;
    WM_RBUTTONDOWN:
      begin
        GetCursorPos(Pt);
        SetForegroundWindow(Handle);
        PopupMenu1.Popup(Pt.X, Pt.Y);
      end;
  end;
end;

procedure TForm1.Close1Click(Sender: TObject);
begin
  Close;
end;

end.
----------------------------------------------
ask not what your country can do for you--ask what you can do for your country.
作者:
男 ruralboy (青瓜白菜番茄红) ★☆☆☆☆ -
盒子活跃会员
2005/4/2 18:20:44
2楼: QQ 本来就是 托盘 运行的。

不过楼上的老兄也是有心了。
----------------------------------------------
作者:
男 gzgzlxg (lxg) ★☆☆☆☆ -
盒子活跃会员
2005/4/3 0:56:22
3楼: 可以使用 ITaskBArList 接口,可以去网上查找相应的资料,等我有空,会详细说明。
----------------------------------------------
ask not what your country can do for you--ask what you can do for your country.
作者:
男 richar (旺仔) ★☆☆☆☆ -
盒子活跃会员
2005/4/5 10:41:35
4楼: 是任务栏不是通知区,有没有人知道呀!
我使用
SetWindowLong(AHandle,GWL_EXSTYLE,WS_EX_TOOLWINDOW)
无效。
----------------------------------------------
瑞盈软件 http://www.dgwewin.com
blog: http://hi.baidu.com/cnCharles
delphi群:16497064
作者:
男 ruralboy (青瓜白菜番茄红) ★☆☆☆☆ -
盒子活跃会员
2005/4/5 17:28:33
5楼: 到现在还不知道你说的是任务栏还是系统托盘。在任务栏的可以用

ShowWindow 隐藏他。
----------------------------------------------
作者:
男 richar (旺仔) ★☆☆☆☆ -
盒子活跃会员
2005/4/6 8:39:25
6楼: 是任务栏上不是系统托盘,接收与发送窗口当然是显示在任务上。
现在我知道QQ进程所有的IsWindowVisible为true的窗口的Handle,
如果我用GetWindow真的太费时,找到很多没有的Handle.
//copy from MSDN.net
The Taskbar
The Microsoft® Windows® interface includes a special application desktop toolbar called the taskbar. You can use the taskbar for such tasks as switching between open windows and starting new applications. This topic has the following two sections.

About the Taskbar 
Using the Taskbar 
About the Taskbar
The taskbar includes the following:

Start menu 
Quick Launch bar 
Taskbar buttons 
Status area 
 
The Start menu contains commands that can access programs, documents, and settings. These commands include Programs, Documents, Settings, Find, Help, Run, and Shut Down.

The Quick Launch bar contains shortcuts to applications. Windows provides default entries, such as Internet Explorer, and the user may add any further shortcuts that they choose. A single click on the application's icon in this area launches the application.

The Shell places a button on the taskbar whenever an application creates an unowned window—that is, a window that doesn't have a parent and that has the appropriate extended style bits (see Managing Taskbar Buttons, below). To switch to a window, the user clicks its window button.

Applications can put icons in the status area to indicate the status of an operation or to notify the user about an event. For example, an application might put a printer icon in the status area to show that a print job is under way. The status area is located at the right edge of the taskbar (if the taskbar is horizontal) or at the bottom (if the taskbar is vertical). The status area also displays the current time if the Show clock check box is selected in the taskbar properties.

The user can right-click the taskbar to display the shortcut menu. The shortcut menu includes commands to cascade windows, tile windows, minimize all windows, and set taskbar properties. The shortcut menu also provides the option to add or remove the Quick Launch bar and the Address, Links, and Desktop toolbars from the taskbar. You can add new toolbars to this menu by registering them under the CATID_DeskBand category. For more information, see Implementing Band Objects.

Taskbar Display Options
The taskbar supports two display options: Auto Hide and Always On Top. To set these options, the user must open the taskbar shortcut menu, click Properties, and select or clear the Auto Hide check box or the Always On Top check box. There is no way to set these options programmatically. To retrieve the state of these display options, use the ABM_GETSTATE message. If you would like to be notified when the state of these display options changes, process the ABN_STATECHANGE notification message in your window procedure. To change the state of these display options, use the ABM_SETSTATE message.

The work area is the portion of the screen not obscured by the taskbar. To retrieve the size of the work area, call the SystemParametersInfo function with the SPI_GETWORKAREA value set. To retrieve the rectangle coordinates that describe the location of the taskbar, use the ABM_GETTASKBARPOS message.

It is possible to cover the taskbar by explicitly setting the size of the window rectangle equal to the size of the screen with SetWindowPos. For Microsoft® Windows® 2000 systems or later, the window must lack either WS_CAPTION or WS_THICKFRAME, or else the window must be sized so that the client area covers the entire screen. Also particular to those systems, if the taskbar is set to Always On Top, it will remain hidden only while the application is the foreground application.

Adding Shortcuts to the Start Menu
To add an item to the Programs submenu on Microsoft® Windows NT® 4.0, Windows® 2000 and later, or Windows® 95 and later, follow these steps.

Create a Shell link by using the IShellLink interface. 
Obtain the PIDL of the Programs folder by using SHGetSpecialFolderLocation, passing CSIDL_PROGRAMS. 
Add the Shell link to the Programs folder. You can also create a folder in the Programs folder and add the link to that folder. 
For systems prior to Windows NT 4.0 and Windows 95, use the Shell dynamic data exchange interface to add items to the Programs submenu of the Start menu, just as you would use it to add items to a group in Program Manager.

Managing Taskbar Buttons
The Shell creates a button on the taskbar whenever an application creates a window that isn't owned. To ensure that the window button is placed on the taskbar, create an unowned window with the WS_EX_APPWINDOW extended style. To prevent the window button from being placed on the taskbar, create the unowned window with the WS_EX_TOOLWINDOW extended style. As an alternative, you can create a hidden window and make this hidden window the owner of your visible window.

The Shell will remove a window's button from the taskbar only if the window's style supports visible taskbar buttons. If you want to dynamically change a window's style to one that doesn't support visible taskbar buttons, you must hide the window first (by calling ShowWindow with SW_HIDE), change the window style, and then show the window.

The window button typically contains the application icon and title. However, if the application does not contain a system menu, the window button is created without the icon.

If you want your application to get the user's attention when the window is not active, use the FlashWindow function to let the user know that a message is waiting. This function flashes the window button. Once the user clicks the window button to activate the window, your application can display the message.

Modifying the contents of the taskbar
Version 4.71 and later of Shell32.dll adds the capability to modify the contents of the taskbar. From an application, you can now add, remove, and activate taskbar buttons. Activating the item does not activate the window; it shows the item as pressed on the taskbar.

The taskbar modification capabilities are implemented in a COM object (CLSID_TaskbarList) that exposes the ITaskbarList interface (IID_ITaskbarList). You must call the ITaskbarList::HrInit method to initialize the object. You can then use the methods of the ITaskbarList interface to modify the contents of the taskbar.

Adding, Modifying, and Deleting Icons in the Status Area
Use the Shell_NotifyIcon function to add, modify, or delete icons from the status area. The dwMessage parameter of Shell_NotifyIcon is a message to the taskbar that specifies the action to be taken. The pnid parameter is a pointer to a NOTIFYICONDATA structure that is used to identify the icon and pass any additional information that is needed for the system to process the message.

You can perform the following actions with status area icons.

To add an icon to the taskbar's status area, call Shell_NotifyIcon with the dwMessage parameter set to NIM_ADD. The NOTIFYICONDATA structure is used to specify the icon's handle and identifier, and any ToolTip text. If the user has selected the Show Clock check box in the taskbar properties, the system places the icon to the immediate left of the clock. Otherwise, the icon appears on the right side or at the bottom of the taskbar. Any existing icons are shifted to the left to make room for the new icon. 
To modify an icon's information, including its icon handle, ToolTip text, and callback message identifier, call Shell_NotifyIcon with dwMessage set to NIM_MODIFY. 
To delete an icon from the status area, call Shell_NotifyIcon with the dwMessage parameter set to NIM_DELETE. 
When you have completed a user interface operation, return focus to the status area by calling Shell_NotifyIcon with dwMessage set to NIM_SETFOCUS. For example, you could do this when a taskbar icon displays a shortcut menu, but the user cancels it by pressing the ESCAPE key.

Receiving status area callback messages
Applications commonly put icons in the status area of the taskbar to serve as status indicators. You can provide additional information when the user performs mouse actions, such as moving the mouse pointer over the icon or clicking the icon.

The system notifies you of mouse and keyboard events by sending an application-defined callback message that is associated with a particular icon. In this way, the system can notify an application when the user, for instance, clicks the icon or selects it by pressing a key.

You define an icon's callback message when you add the icon to the taskbar. The callback message identifier is specified in the uCallbackMessage member of the NOTIFYICONDATA structure passed with NIM_ADD. When an event occurs, the system sends the callback message to the window procedure of the window specified by the hWnd member. The wParam parameter of the message contains the identifier of the taskbar icon in which the event occurred. The lParam parameter holds the mouse or keyboard message associated with the event. For example, when the mouse pointer moves onto a taskbar icon, lParam contains WM_MOUSEMOVE.

The results of various mouse events can be summarized as follows:

When the user moves the mouse pointer over the icon, the system displays the ToolTip text that was specified in NOTIFYICONDATA. 
When the user clicks the icon, your application receives a WM_LBUTTONDOWN notification. 
When the user right-clicks the icon, your application receives a WM_RBUTTONDOWN notification. 
When the user double-clicks the icon, your application receives a WM_LBUTTONDBLCLK notification. 
Typically, clicking the icon causes the application to display a window with additional information, right-clicking displays a shortcut menu, and double-clicking executes the default shortcut menu command.

For an example of how to change the ToolTip text associated with a status area icon, see Balloon ToolTips for Status Bar Icons.

Versions 5.0 and later of the Shell handle Shell_NotifyIcon mouse and keyboard events in different ways than earlier Shell versions found on Windows NT 4.0, Windows 95, and Windows 98. The differences are as follows:

If a user requests a notify icon's shortcut menu with the keyboard, the version 5.0 Shell sends the associated application a WM_CONTEXTMENU message. Earlier versions send WM_RBUTTONDOWN and WM_RBUTTONUP messages. 
If a user selects a notify icon with the keyboard and activates it with the space bar or ENTER key, the version 5.0 Shell sends the associated application an NIN_KEYSELECT notification. Earlier versions send WM_RBUTTONDOWN and WM_RBUTTONUP messages. 
If a user selects a notify icon with the mouse and activates it with the ENTER key, the version 5.0 Shell sends the associated application an NIN_SELECT notification. Earlier versions send WM_RBUTTONDOWN and WM_RBUTTONUP messages. 
If a user passes the mouse pointer over an icon with which a balloon ToolTip is associated, the version 5.0 Shell sends the following messages. 
NIN_BALLOONSHOW - Sent when the balloon is shown (balloons are queued). 
NIN_BALLOONHIDE - Sent when the balloon disappears—for example, when the icon is deleted. This message is not sent if the balloon is dismissed because of a timeout or a mouse click. 
NIN_BALLOONTIMEOUT - Sent when the balloon is dismissed because of a timeout. 
NIN_BALLOONUSERCLICK - Sent when the balloon is dismissed because of a mouse click. 
You can select which way the Shell should behave by calling Shell_NotifyIcon with dwMessage set to NIM_SETVERSION. Set the uVersion member of the NOTIFYICONDATA structure to indicate whether you want version 5.0 or pre-version 5.0 behavior.

Taskbar Creation Notification
With Microsoft® Internet Explorer 4.0 and later, the Shell notifies applications that the taskbar has been created. When the taskbar is created, it registers a message with the TaskbarCreated string and then broadcasts this message to all top-level windows. When your taskbar application receives this message, it should assume that any taskbar icons it added have been removed and add them again. This feature generally applies only to services that are already running when the Shell begins execution. The following example shows a very simplified method for handling this case.

LRESULT CALLBACK WndProc(HWND hWnd, UINT uMessage, WPARAM wParam, 
    LPARAM lParam)
{
static UINT s_uTaskbarRestart;

switch(uMessage)
    {
    case WM_CREATE:
        s_uTaskbarRestart = RegisterWindowMessage(TEXT("TaskbarCreated"));
        break;
        
    default:
        if(uMessage == s_uTaskbarRestart)
          AddTaskbarIcons();
        break;
    }
return DefWindowProc(hWnd, uMessage, wParam, lParam);
}

Using the Taskbar
This section includes examples that demonstrate how to add icons to the taskbar status area and how to process callback messages for taskbar icons.

Adding and Deleting Taskbar Icons in the Status Area
You add an icon to the taskbar status area by filling in a NOTIFYICONDATA structure and then passing the structure to Shell_NotifyIcon with dwMessage set to NIM_ADD. The structure members must specify the handle to the window that is adding the icon, as well as the icon identifier and icon handle. You can also specify ToolTip text for the icon. If you need to receive mouse messages for the icon, specify the identifier of the callback message that the system should use to send the message to the window procedure.

The function in the following example demonstrates how to add an icon to the taskbar.

// MyTaskBarAddIcon - adds an icon to the taskbar status area. 
// Returns TRUE if successful, or FALSE otherwise. 
// hwnd - handle to the window to receive callback messages. 
// uID - identifier of the icon. 
// hicon - handle to the icon to add. 
// lpszTip - ToolTip text. 
BOOL MyTaskBarAddIcon(HWND hwnd, UINT uID, HICON hicon, LPSTR lpszTip) 

    BOOL res; 
    NOTIFYICONDATA tnid; 
 
    tnid.cbSize = sizeof(NOTIFYICONDATA); 
    tnid.hWnd = hwnd; 
    tnid.uID = uID; 
    tnid.uFlags = NIF_MESSAGE | NIF_ICON | NIF_TIP; 
    tnid.uCallbackMessage = MYWM_NOTIFYICON; 
    tnid.hIcon = hicon; 
    if (lpszTip) 
        lstrcpyn(tnid.szTip, lpszTip, sizeof(tnid.szTip)); 
    else 
        tnid.szTip[0] = '\0'; 
 
    res = Shell_NotifyIcon(NIM_ADD, &tnid); 
 
    if (hicon) 
        DestroyIcon(hicon); 
 
    return res; 


To delete an icon from the taskbar status area, fill a NOTIFYICONDATA structure and call Shell_NotifyIcon with dwMessage set to NIM_DELETE. When deleting a taskbar icon, specify only the cbSize, hWnd, and uID members of the structure. For example

// MyTaskBarDeleteIcon - deletes an icon from the taskbar status area. 
// Returns TRUE if successful, or FALSE otherwise. 
// hwnd - handle to the window that added the icon. 
// uID - identifier of the icon to delete. 
BOOL MyTaskBarDeleteIcon(HWND hwnd, UINT uID) 

    BOOL res; 
    NOTIFYICONDATA tnid; 
 
    tnid.cbSize = sizeof(NOTIFYICONDATA); 
    tnid.hWnd = hwnd; 
    tnid.uID = uID; 
         
    res = Shell_NotifyIcon(NIM_DELETE, &tnid); 
    return res; 


Receiving Mouse Events
If you specify a callback message for a taskbar icon, the system sends the message to your application whenever a mouse event occurs in the icon's bounding rectangle. The wParam parameter of the message specifies the identifier of the taskbar icon, and the lParam parameter of the message specifies the message that the system generated as a result of the mouse event.

The function in the following example is from an application that adds both battery and printer icons to the taskbar. The application calls the function when it receives a callback message. The function determines whether the user has clicked one of the icons and, if a click has occurred, calls an application-defined function to display status information.

// On_MYWM_NOTIFYICON - processes callback messages for taskbar icons. 
// wParam - first message parameter of the callback message. 
// lParam - second message parameter of the callback message. 
void On_MYWM_NOTIFYICON(WPARAM wParam, LPARAM lParam) 

    UINT uID; 
    UINT uMouseMsg; 
 
    uID = (UINT) wParam; 
    uMouseMsg = (UINT) lParam; 
 
    if (uMouseMsg == WM_LBUTTONDOWN) { 
        switch (uID) { 
          case IDI_MYBATTERYICON: 
 
          // The user clicked the battery icon. Display the 
          // battery status. 
          ShowBatteryStatus(); 
          break; 
 
          case IDI_MYPRINTERICON: 
 
          // The user clicked the printer icon. Display the 
          // status of the print job. 
          ShowJobStatus(); 
          break; 
 
          default: 
          break; 
        } 
     } 
     return; 
 }
----------------------------------------------
瑞盈软件 http://www.dgwewin.com
blog: http://hi.baidu.com/cnCharles
delphi群:16497064
作者:
男 useeamj (天外非仙) ★☆☆☆☆ -
普通会员
2005/4/11 4:10:08
7楼: QQ本来就不在任务栏显示,也可以不在系统栏显示。
   至于编程实现,我懒得查了,前者大概是用api,后者用systrayicon控件就可以
----------------------------------------------
-
懒人喜欢RAD
作者:
男 richar (旺仔) ★☆☆☆☆ -
盒子活跃会员
2005/4/11 8:15:37
8楼: 没有看明白我的意思,我是说它接收与发送消息的时候
在任务栏上的窗口。
----------------------------------------------
瑞盈软件 http://www.dgwewin.com
blog: http://hi.baidu.com/cnCharles
delphi群:16497064
作者:
男 gzgzlxg (lxg) ★☆☆☆☆ -
盒子活跃会员
2005/4/11 17:11:56
9楼: 下面给出的是一个完整的实例,程序启动后列出所有在任务栏的按键小窗口。选择任意一个,按 Hide TaskBar 将隐含该小窗口,按 Add TaskBar 键将隐含的按键小窗口打开。程序引用了 VBTaskbarList_TLB.PAS 其实就是 ITaskBarList 的接口说明文件,也可以不要,自己写一个简单的调用 ITaskBarList 的 COM 接口。

unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, VBTaskbarList_TLB, ComCtrls, ExtCtrls, StdCtrls;

type
  TForm1 = class(TForm)
    Panel1: TPanel;
    Panel2: TPanel;
    Panel3: TPanel;
    TaskBarListView: TListView;
    BtReflush: TButton;
    BtHideTaskBar: TButton;
    BtAddTaskBar: TButton;
    procedure FormCreate(Sender: TObject);
    procedure BtReflushClick(Sender: TObject);
    procedure BtHideTaskBarClick(Sender: TObject);
    procedure BtAddTaskBarClick(Sender: TObject);
  private
    TaskBarList: TTaskbarList;
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation

{$R *.dfm}

{ TForm1 }

function EnumWindowsProc(HW: Hwnd; Param: LPARAM): Boolean; stdcall;
var
  WinName, CName: array[0..144] of char;
  ListItem: TListItem;

  function IsTaskbarWindow(WinHandle: THandle): Boolean;
  var
    lExStyle: Integer;
    hParent: THandle;
  begin
    lExStyle := GetWindowLong(WinHandle, GWL_EXSTYLE);
    hParent := GetParent(WinHandle);
    Result := IsWindowVisible(WinHandle)
      and (GetWindow(WinHandle, GW_OWNER) = 0)
      and ((hParent = 0) or (hParent = GetDesktopWindow));
    if (lExStyle and WS_EX_TOOLWINDOW) <> 0 then
      Result := False;
    if (lExStyle and WS_EX_APPWINDOW) <> 0 then
      Result := True;
  end;

begin
  Result := True;
  if IsTaskbarWindow(HW) then
  begin
    GetWindowText(Hw, WinName, 144);
    GetClassName(Hw, CName, 144);
    ListItem := TListView(Pointer(param)^).Items.Add;
    ListItem.Caption := WinName;
    ListItem.SubItems.Add(CName);
    ListItem.SubItems.Add(IntToStr(Hw));
  end;
end;

function CheckNumber(s: string): Boolean;
asm
        PUSH    ESI
        TEST    EAX, EAX
        JE      @@ErrEXIT
        MOV     ESI, EAX
        CALL    system.@LStrLen
        MOV     ECX, EAX
   @@Loop:
        LODSB
        CMP     AL, '0'
        JB      @@ErrExit
        CMP     AL, '9'
        JA      @@ErrExit
        LOOP    @@Loop
        JMP     @@NormalExit
   @@ErrExit:
        XOR     EAX, EAX
        JMP     @@Exit
   @@NormalExit:
        MOV     EAX, 1
   @@Exit:
        POP     ESI
end;

procedure TForm1.FormCreate(Sender: TObject);
begin
  TaskBarList := TTaskbarList.Create(Self);
  TaskBarList.HrInit;
  BtReflushClick(Self);
end;

procedure TForm1.BtReflushClick(Sender: TObject);
begin
  TaskBarListView.Clear;
  EnumWindows(@EnumWindowsProc, LPARAM(@TaskBarListView))
end;

procedure TForm1.BtHideTaskBarClick(Sender: TObject);
var
  TaskBarHandle: THandle;
  ListItem: TListItem;
  S: string;
begin
  with TaskBarListView do
  begin
    ListItem := Items.Item[Selected.Index];
    S := ListItem.SubItems.strings[1];
    if CheckNumber(S) then
    begin
      TaskBarHandle := StrToInt(S);
      TaskBarList.DeleteTab(TaskBarHandle);
    end;
  end;
end;

procedure TForm1.BtAddTaskBarClick(Sender: TObject);
var
  TaskBarHandle: THandle;
  ListItem: TListItem;
  S: string;
begin
  with TaskBarListView do
  begin
    ListItem := Items.Item[Selected.Index];
    S := ListItem.SubItems.strings[1];
    if CheckNumber(s) then
    begin
      TaskBarHandle := StrToInt(S);
      TaskBarList.AddTab(TaskBarHandle);
    end;
  end;
end;

end.

下面是 ITaskBArList的接口文件

unit VBTaskbarList_TLB;

// ********** //
// WARNING          
// -------          
// The types declared in this file were generated from data read from a       
// Type Library. If this type library is explicitly or indirectly (via        
// another type library referring to this type library) re-imported, or the   
// 'Refresh' command of the Type Library Editor activated while editing the   
// Type Library, the contents of this file will be regenerated and all        
// manual modifications will be lost.          
// ********** //

// PASTLWTR : 1.2
// File generated on 2005-4-3 10:28:47 from Type Library described below.

// **********  //
// Type Lib: C:\LxgProgram\answer question\²»ÔÚÈÎÎñÀ¸ÏÔʾ\TaskbarList.tlb (1)
// LIBID: {C52C7F93-54B9-11D3-ABF9-0040F6A4BFEC}
// LCID: 0
// Helpfile : 
// HelpString: ITaskbarList - Mattias Sjögren
// DepndLst: 
//   (1) v2.0 stdole, (C:\WINNT\system32\stdole2.tlb)
// ********** //
// **********//
// NOTE:          
// Items guarded by $IFDEF_LIVE_SERVER_AT_DESIGN_TIME are used by properties  
// which return objects that may need to be explicitly created via a function 
// call prior to any access via the property. These items have been disabled  
// in order to prevent accidental use from within the object inspector. You   
// may enable them by defining LIVE_SERVER_AT_DESIGN_TIME or by selectively   
// removing them from the $IFDEF blocks. However, such items must still be    
// programmatically created via a method of the appropriate CoClass before    
// they can be used.          
{$TYPEDADDRESS OFF} // Unit must be compiled without type-checked pointers. 
{$WARN SYMBOL_PLATFORM OFF}
{$WRITEABLECONST ON}
{$VARPROPSETTER ON}
interface

uses Windows, ActiveX, Classes, Graphics, OleServer, StdVCL, Variants;
  

// **********//
// GUIDS declared in the TypeLibrary. Following prefixes are used:        
//   Type Libraries     : LIBID_xxxx          
//   CoClasses          : CLASS_xxxx          
//   DISPInterfaces     : DIID_xxxx          
//   Non-DISP interfaces: IID_xxxx          
// **********//
const
  // TypeLibrary Major and minor versions
  VBTaskbarListMajorVersion = 1;
  VBTaskbarListMinorVersion = 0;

  LIBID_VBTaskbarList: TGUID = '{C52C7F93-54B9-11D3-ABF9-0040F6A4BFEC}';

  IID_ITaskbarList: TGUID = '{56FDF342-FD6D-11D0-958A-006097C9A090}';
  CLASS_TaskbarList: TGUID = '{56FDF344-FD6D-11D0-958A-006097C9A090}';

// **********//
// Declaration of Enumerations defined in Type Library          
// **********//
// Constants for enum DLLVER_PLATFORMS
type
  DLLVER_PLATFORMS = TOleEnum;
const
  DLLVER_PLATFORM_WINDOWS = $00000001;
  DLLVER_PLATFORM_NT = $00000002;

type

// **********//
// Forward declaration of types defined in TypeLibrary          
// **********//
  ITaskbarList = interface;

// **********//
// Declaration of CoClasses defined in Type Library          
// (NOTE: Here we map each CoClass to its Default Interface)          
// **********//
  TaskbarList = ITaskbarList;


// **********//
// Declaration of structures, unions and aliases.          
// **********//
  DLLVERSIONINFO = packed record
    cbSize: Integer;
    dwMajorVersion: Integer;
    dwMinorVersion: Integer;
    dwBuildNumber: Integer;
    dwPlatformID: DLLVER_PLATFORMS;
  end;


// **********//
// Interface: ITaskbarList
// Flags:     (0)
// GUID:      {56FDF342-FD6D-11D0-958A-006097C9A090}
// **********//
  ITaskbarList = interface(IUnknown)
    ['{56FDF342-FD6D-11D0-958A-006097C9A090}']
    function HrInit: HResult; stdcall;
    function AddTab(hwnd: Integer): HResult; stdcall;
    function DeleteTab(hwnd: Integer): HResult; stdcall;
    function ActivateTab(hwnd: Integer): HResult; stdcall;
    function SetActivateAlt(hwnd: Integer): HResult; stdcall;
  end;

// **********//
// The Class CoTaskbarList provides a Create and CreateRemote method to          
// create instances of the default interface ITaskbarList exposed by          
// the CoClass TaskbarList. The functions are intended to be used by          
// clients wishing to automate the CoClass objects exposed by the         
// server of this typelibrary.          
// **********//
  CoTaskbarList = class
    class function Create: ITaskbarList;
    class function CreateRemote(const MachineName: string): ITaskbarList;
  end;


// **********//
// OLE Server Proxy class declaration
// Server Object    : TTaskbarList
// Help String      : TaskbarList class
// Default Interface: ITaskbarList
// Def. Intf. DISP? : No
// Event   Interface: 
// TypeFlags        : (2) CanCreate
// **********//
{$IFDEF LIVE_SERVER_AT_DESIGN_TIME}
  TTaskbarListProperties= class;
{$ENDIF}
  TTaskbarList = class(TOleServer)
  private
    FIntf:        ITaskbarList;
{$IFDEF LIVE_SERVER_AT_DESIGN_TIME}
    FProps:       TTaskbarListProperties;
    function      GetServerProperties: TTaskbarListProperties;
{$ENDIF}
    function      GetDefaultInterface: ITaskbarList;
  protected
    procedure InitServerData; override;
  public
    constructor Create(AOwner: TComponent); override;
    destructor  Destroy; override;
    procedure Connect; override;
    procedure ConnectTo(svrIntf: ITaskbarList);
    procedure Disconnect; override;
    function HrInit: HResult;
    function AddTab(hwnd: Integer): HResult;
    function DeleteTab(hwnd: Integer): HResult;
    function ActivateTab(hwnd: Integer): HResult;
    function SetActivateAlt(hwnd: Integer): HResult;
    property DefaultInterface: ITaskbarList read GetDefaultInterface;
  published
{$IFDEF LIVE_SERVER_AT_DESIGN_TIME}
    property Server: TTaskbarListProperties read GetServerProperties;
{$ENDIF}
  end;

{$IFDEF LIVE_SERVER_AT_DESIGN_TIME}
// **********//
// OLE Server Properties Proxy Class
// Server Object    : TTaskbarList
// (This object is used by the IDE's Property Inspector to allow editing
//  of the properties of this server)
// **********//
 TTaskbarListProperties = class(TPersistent)
  private
    FServer:    TTaskbarList;
    function    GetDefaultInterface: ITaskbarList;
    constructor Create(AServer: TTaskbarList);
  protected
  public
    property DefaultInterface: ITaskbarList read GetDefaultInterface;
  published
  end;
{$ENDIF}


procedure Register;

resourcestring
  dtlServerPage = 'ActiveX';

  dtlOcxPage = 'ActiveX';

implementation

uses ComObj;

class function CoTaskbarList.Create: ITaskbarList;
begin
  Result := CreateComObject(CLASS_TaskbarList) as ITaskbarList;
end;

class function CoTaskbarList.CreateRemote(const MachineName: string): ITaskbarList;
begin
  Result := CreateRemoteComObject(MachineName, CLASS_TaskbarList) as ITaskbarList;
end;

procedure TTaskbarList.InitServerData;
const
  CServerData: TServerData = (
    ClassID:   '{56FDF344-FD6D-11D0-958A-006097C9A090}';
    IntfIID:   '{56FDF342-FD6D-11D0-958A-006097C9A090}';
    EventIID:  '';
    LicenseKey: nil;
    Version: 500);
begin
  ServerData := @CServerData;
end;

procedure TTaskbarList.Connect;
var
  punk: IUnknown;
begin
  if FIntf = nil then
  begin
    punk := GetServer;
    Fintf:= punk as ITaskbarList;
  end;
end;

procedure TTaskbarList.ConnectTo(svrIntf: ITaskbarList);
begin
  Disconnect;
  FIntf := svrIntf;
end;

procedure TTaskbarList.DisConnect;
begin
  if Fintf <> nil then
  begin
    FIntf := nil;
  end;
end;

function TTaskbarList.GetDefaultInterface: ITaskbarList;
begin
  if FIntf = nil then
    Connect;
  Assert(FIntf <> nil, 'DefaultInterface is NULL. Component is not connected to Server. You must call ''Connect'' or ''ConnectTo'' before this operation');
  Result := FIntf;
end;

constructor TTaskbarList.Create(AOwner: TComponent);
begin
  inherited Create(AOwner);
{$IFDEF LIVE_SERVER_AT_DESIGN_TIME}
  FProps := TTaskbarListProperties.Create(Self);
{$ENDIF}
end;

destructor TTaskbarList.Destroy;
begin
{$IFDEF LIVE_SERVER_AT_DESIGN_TIME}
  FProps.Free;
{$ENDIF}
  inherited Destroy;
end;

{$IFDEF LIVE_SERVER_AT_DESIGN_TIME}
function TTaskbarList.GetServerProperties: TTaskbarListProperties;
begin
  Result := FProps;
end;
{$ENDIF}

function TTaskbarList.HrInit: HResult;
begin
  Result := DefaultInterface.HrInit;
end;

function TTaskbarList.AddTab(hwnd: Integer): HResult;
begin
  Result := DefaultInterface.AddTab(hwnd);
end;

function TTaskbarList.DeleteTab(hwnd: Integer): HResult;
begin
  Result := DefaultInterface.DeleteTab(hwnd);
end;

function TTaskbarList.ActivateTab(hwnd: Integer): HResult;
begin
  Result := DefaultInterface.ActivateTab(hwnd);
end;

function TTaskbarList.SetActivateAlt(hwnd: Integer): HResult;
begin
  Result := DefaultInterface.SetActivateAlt(hwnd);
end;

{$IFDEF LIVE_SERVER_AT_DESIGN_TIME}
constructor TTaskbarListProperties.Create(AServer: TTaskbarList);
begin
  inherited Create;
  FServer := AServer;
end;

function TTaskbarListProperties.GetDefaultInterface: ITaskbarList;
begin
  Result := FServer.DefaultInterface;
end;

{$ENDIF}

procedure Register;
begin
  RegisterComponents(dtlServerPage, [TTaskbarList]);
end;

end.
----------------------------------------------
ask not what your country can do for you--ask what you can do for your country.
作者:
男 richar (旺仔) ★☆☆☆☆ -
盒子活跃会员
2005/4/12 8:16:04
10楼: 哇靠,大哥你那牛呀,小弟看不懂呀,太长了。
----------------------------------------------
瑞盈软件 http://www.dgwewin.com
blog: http://hi.baidu.com/cnCharles
delphi群:16497064
作者:
男 gzgzlxg (lxg) ★☆☆☆☆ -
盒子活跃会员
2005/4/12 12:28:45
11楼: 后面的接口文件不用看,拷贝下来,直接使用就行了,其实接口文件也很简单,只不过有些机器生成的说明,可以完全删除。
前面的那个程序应该很好的读一下,这里面涉及到许多人会经常提问的东西,主要有以下几点:
1、CallBack:
  EnumWindowsProc 是回调函数,这里的调用给出了Delphi组件如何通过回调函数的参数传递,这个东西很有用。
2、怎样使用COM接口:
  ITaskbarList是Windows 管理 TaskBar Button 的 COM 接口程序,通过程序,可以理解如何使用这个玩意儿。
3、汇编语言在Delphi中的应用:
  这是随手写的东西,说实话,我一生只学过汇编语言,而且一直从事汇编的开发,其他语言都是随用随学,都不太认真。但汇编语言在许多地方确实是非常好用的,你可以看到在VCL中也掺杂着许多汇编程序。这个短短的汇编说明了几个问题:
  a、如何在汇编中调用VCL中的函数和功能;
  b、function 的入口参数是如何传递的;
  c、结果是怎样返回的。
你粗看这段程序,好像没有使用入口参数,也没有返回,这就是运用了Delphi的汇编调用的约定。
入门靠师父,修行在各人。
----------------------------------------------
ask not what your country can do for you--ask what you can do for your country.
作者:
男 richar (旺仔) ★☆☆☆☆ -
盒子活跃会员
2005/4/12 13:52:40
12楼: 说实话非常感谢你手把手教我,怎么你那么牛!上面程序代码是你自己写的
还是有这些的类。VBTaskbarList_TLB是那个库文件,我从Project->Import
Library Type中找不到VBTaskbarList,这是一个Ocx,还是一个Dll.
----------------------------------------------
瑞盈软件 http://www.dgwewin.com
blog: http://hi.baidu.com/cnCharles
delphi群:16497064
作者:
男 gzgzlxg (lxg) ★☆☆☆☆ -
盒子活跃会员
2005/4/12 14:35:23
13楼: 上面程序当然是自己写的,如果是转自他人,我会加以说明,否则不成了剽窃,在技术区->论坛精华贴中《数据导出为Excel格式》中楼主的贴子就是我以前贴在DelphiBoy网站的,那个家伙拿来一个字都没有改,就作为自己的作品,这种事我是做不出来的。

我在前面不是说过(3楼)“可以使用 ITaskBArList 接口,可以去网上查找相应的资料,等我有空,会详细说明。”那几天没有时间,昨天有点时间就写了这个玩意儿。

你说的ITaskbarList是VB的接口,老盖当然优先考虑自己的产品,从VB的.TLB文件转到TLB.PAS,然后再使用。

ITaskbarList 是 shell32.dll 中的一部分,和许多其他的简单的COM接口不同,Shell32.dll 有许多独立的接口,独立的使用,然而却打在一个大包里。
----------------------------------------------
ask not what your country can do for you--ask what you can do for your country.
作者:
男 richar (旺仔) ★☆☆☆☆ -
盒子活跃会员
2005/4/13 8:07:22
14楼: 哦,同情老大的不是被剽窃,其实你可以向 斑竹:zizii,sephil,liumazi
他们投诉的他们应该帮你解决的。
----------------------------------------------
瑞盈软件 http://www.dgwewin.com
blog: http://hi.baidu.com/cnCharles
delphi群:16497064
信息
登陆以后才能回复
Copyright © 2CCC.Com 盒子论坛 v3.0.1 版权所有 页面执行361.3281毫秒 RSS