CnPack Forum


 
Subject: 关于 CnShellUtils 中DisplayContextMenu显示文件上下文右键菜单bug
dongshengyun
新警察
Rank: 1



UID 62894
Digest Posts 0
Credits 8
Posts 3
点点分 8
Reading Access 10
Registered 2011-4-13
Status Offline
Post at 2011-4-13 14:59  Profile | Blog | P.M. 
关于 CnShellUtils 中DisplayContextMenu显示文件上下文右键菜单bug

我利用关CnShellUtils单元中DisplayContextMenu函数,来显示我需要的右键上下文菜单。
右键上下文菜单显示了,但是其中cut和Copy不起作用。在详细一些就是我选择了一个文件或文件夹,调用DisplayContextMenu函数,右键菜单出来了。点击cut或copy但是在别去paste按钮是灰色不能用。

调用代码如下:

unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Menus,
  Dialogs, StdCtrls, VirtualTrees, ImgList, ExtCtrls, ComCtrls, AppEvnts, CnShellUtils;

type  
  TForm1 = class(TForm)
    btn4: TButton;
    btn1: TButton;
    procedure btn4Click(Sender: TObject);
    procedure btn1Click(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation

uses
  ShellAPI;

{$R *.dfm}

procedure TForm1.btn4Click(Sender: TObject);
var
  pos: TPoint;
begin
  GetCursorPos(pos);
  pos:= ScreenToClient(pos);
  DisplayContextMenu(Self.Handle, 'C:\Documents and Settings\admin\Desktop\????\Everything\', pos);
end;

procedure TForm1.btn1Click(Sender: TObject);
var
  pos: TPoint;
begin
  GetCursorPos(pos);
  pos:= ScreenToClient(pos);
  DisplayContextMenu(Self.Handle, 'C:\Documents and Settings\admin\Desktop\????\Everything\Everything-1.2.1.371.exe', pos)
end;

end.

希望cnpack的大侠们给解决一下。
Top
dongshengyun
新警察
Rank: 1



UID 62894
Digest Posts 0
Credits 8
Posts 3
点点分 8
Reading Access 10
Registered 2011-4-13
Status Offline
Post at 2011-4-13 15:47  Profile | Blog | P.M. 
怎么没有人回答解决问题呢?
Top
dongshengyun
新警察
Rank: 1



UID 62894
Digest Posts 0
Credits 8
Posts 3
点点分 8
Reading Access 10
Registered 2011-4-13
Status Offline
Post at 2011-4-18 17:49  Profile | Blog | P.M. 
本文自己回答。

此问题已解决。
因为剪切板是com组件范畴,所以在调用之前应该初始化。
顾在程序主单元加入如下代码即可:
initialization
  OleInitialize(nil);

finalization
  try
    OleUninitialize;
  except
  end;

end.
Top
 




All times are GMT++8, the time now is 2024-11-23 19:40

    本论坛支付平台由支付宝提供
携手打造安全诚信的交易社区 Powered by Discuz! 5.0.0  © 2001-2006 Comsenz Inc.
Processed in 0.009090 second(s), 7 queries , Gzip enabled

Clear Cookies - Contact Us - CnPack Website - Archiver - WAP