如何添加子菜单 ( 积分: 100 )

  • 主题发起人 主题发起人 yangyih007
  • 开始时间 开始时间
Y

yangyih007

Unregistered / Unconfirmed
GUEST, unregistred user!
可以使用以下方式创建弹出式菜单,但是如何在创建好的菜单的某个项目添加子菜单?用API方式<br>var pm1:hmenu;<br>i:integer;<br>pm1:=CreatePopupMenu;<br>for i:=0 to 5 do<br>appendmenu(pm1, MF_string, i, pchar(popupstr));
 
可以使用以下方式创建弹出式菜单,但是如何在创建好的菜单的某个项目添加子菜单?用API方式<br>var pm1:hmenu;<br>i:integer;<br>pm1:=CreatePopupMenu;<br>for i:=0 to 5 do<br>appendmenu(pm1, MF_string, i, pchar(popupstr));
 
参考<br>http://www.delphibbs.com/delphibbs/dispq.asp?lid=515833<br>标题: PopupMenu怎样自动消失以及如何调用系统菜单 (150分)<br><br>-----------------------转自网络<br><br>在系统菜单加入子菜单<br>unit Unit1;<br><br>interface<br><br>uses<br> &nbsp;Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs;<br><br>type<br> &nbsp;TForm1 = class(TForm)<br> &nbsp; &nbsp;procedure FormCreate(Sender: TObject);<br> &nbsp;private<br> &nbsp; &nbsp;{ Private declarations }<br> &nbsp;public<br> &nbsp; &nbsp;{ Public declarations }<br> &nbsp; &nbsp;procedure RegisterMsg (var Msg: TMsg;var Handled: boolean);<br> &nbsp;end;<br><br>var<br> &nbsp;Form1: TForm1;<br><br>implementation<br><br>{$R *.DFM}<br><br>procedure AppendToSystemMenu (Form: TForm;<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Item: string; ItemID: word);<br>{----------------------------------------------------------------}<br>{ Appends menu item to end of system menu of specified form and &nbsp;}<br>{ to system menu of application's minimized icon. &nbsp;For separator }<br>{ bar, use '-' for the Item, and 0 for the ItemID. &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }<br>{----------------------------------------------------------------}<br> var<br> &nbsp; NormalSysMenu, MinimizedMenu: HMenu;<br> &nbsp; AItem: array[0..255] of Char;<br> &nbsp; PItem: PChar;<br> begin<br> &nbsp; NormalSysMenu := GetSystemMenu(Form.Handle, false);<br> &nbsp; MinimizedMenu := GetSystemMenu(Application.Handle, false);<br> &nbsp; if Item = '-' then<br> &nbsp; begin<br> &nbsp; &nbsp; AppendMenu(NormalSysMenu, MF_SEPARATOR, 0, nil);<br> &nbsp; &nbsp; AppendMenu(MinimizedMenu, MF_SEPARATOR, 0, nil);<br> &nbsp; end<br> &nbsp; else<br> &nbsp; begin<br> &nbsp; &nbsp; PItem := StrPCopy(@AItem, Item);<br> &nbsp; &nbsp; AppendMenu(NormalSysMenu, MF_STRING, ItemID, PItem);<br> &nbsp; &nbsp; AppendMenu(MinimizedMenu, MF_STRING, ItemID, PItem);<br> &nbsp; end;<br> end; {AppendToSystemMenu}<br><br>procedure TForm1.RegisterMsg (var Msg: TMsg;var Handled: boolean);<br>begin<br> &nbsp;if Msg.Message = WM_SYSCOMMAND then<br> &nbsp;begin<br> &nbsp; &nbsp;if Msg.wParam = 99 then<br> &nbsp; &nbsp;begin<br> &nbsp; &nbsp; &nbsp;ShowMessage('欢迎注册');<br> &nbsp; &nbsp; &nbsp; {Registration stuff}<br> &nbsp; &nbsp;end;<br> &nbsp;end;<br>end;<br><br><br>procedure TForm1.FormCreate(Sender: TObject);<br>begin<br> &nbsp;AppendToSystemMenu(Form1, '-', 0); &nbsp;{Separator bar}<br> &nbsp;AppendToSystemMenu(Form1, '&amp;Please Register...', 99);<br> &nbsp;Application.OnMessage := Form1.RegisterMsg;<br>end;<br><br>end. <br><br>参考<br>http://www.delphibbs.com/delphibbs/modifyl.asp?lid=2075320<br>标题: 在Windows右键菜单中加入像&quot;发送到&quot;一样的子菜单,先出300分 (300分)
 
首先感谢你的回应,不过你的不是我想要的东西,我的意思是创建好PM1弹出式菜单后,然后在上面的一个菜单项目中在加入一个子菜单,另外你说的那些东西我都懂,如果是这样的答案我就没有必要问了。我现在全部使用api编写一个程序,没有TFORM,如果不是这样我有更加方便的解决方法。而且那个菜单我已经编写完成,可是不知道如何按照我的要求在这个菜单里加入子菜单而已。
 
太难了,不过不知道为什么不能用AppendMenu,<br>关于菜单的API函数不多,<br>AppendMenu &nbsp;<br>CheckMenuItem &nbsp;<br>GetMenuCheckMarkDimensions &nbsp;<br>GetMenuState &nbsp;<br>GetMenuString &nbsp;<br>InsertMenu &nbsp;<br>ModifyMenu <br>好像MSND里面就这几个,而所谓API的其实只有AppendMenu和InsertMenu是和楼主程序相关的,我的MSDN太老了?等高手
 
我试验过insertmenu,那只是插入菜单而已,对这样的问题没有帮助,好像ModifyMenu也是不对题,不过我想在有TForm时候使用Tpopumenu却可以轻易实现,我有一个程序,全部动态创建所有菜单,所以我对菜单创建还是有些研究的,现在想用api的方式实现那些功能,但是到了子菜单时候却遇到死胡同,我是追求完美的人,如果这个问题无法解决,那么这个程序就没有生存的价值了。
 
先给一个建议,完美是无边,楼主还是不要自扰了。<br><br>楼主的问题实在太高深了,我回答不了,既然说到Popupmenu,就看一下代码吧,看看有用没有,他是用InsertMenu的<br><br>procedure TMenuItem.AppendTo(Menu: HMENU; ARightToLeft: Boolean);<br>const<br> &nbsp;IBreaks: array[TMenuBreak] of DWORD = (MFT_STRING, MFT_MENUBREAK, MFT_MENUBARBREAK);<br> &nbsp;IChecks: array[Boolean] of DWORD = (MFS_UNCHECKED, MFS_CHECKED);<br> &nbsp;IDefaults: array[Boolean] of DWORD = (0, MFS_DEFAULT);<br> &nbsp;IEnables: array[Boolean] of DWORD = (MFS_DISABLED or MFS_GRAYED, MFS_ENABLED);<br> &nbsp;IRadios: array[Boolean] of DWORD = (MFT_STRING, MFT_RADIOCHECK);<br> &nbsp;ISeparators: array[Boolean] of DWORD = (MFT_STRING, MFT_SEPARATOR);<br> &nbsp;IRTL: array[Boolean] of DWORD = (0, RightToLeftMenuFlag);<br> &nbsp;IOwnerDraw: array[Boolean] of DWORD = (MFT_STRING, MFT_OWNERDRAW);<br>var<br> &nbsp;MenuItemInfo: TMenuItemInfo;<br> &nbsp;Caption: string;<br> &nbsp;NewFlags: Integer;<br> &nbsp;IsOwnerDraw: Boolean;<br> &nbsp;ParentMenu: TMenu;<br>begin<br> &nbsp;if FVisible then<br> &nbsp;begin<br> &nbsp; &nbsp;Caption := FCaption;<br> &nbsp; &nbsp;if GetCount &gt; 0 then<br> &nbsp; &nbsp; &nbsp;MenuItemInfo.hSubMenu := GetHandle<br> &nbsp; &nbsp;else if (FShortCut &lt;&gt; scNone) and ((Parent = nil) or<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;(Parent.Parent &lt;&gt; nil) or not (Parent.Owner is TMainMenu)) then<br> &nbsp; &nbsp; &nbsp;Caption := Caption + #9 + ShortCutToText(FShortCut);<br> &nbsp; &nbsp;if Lo(GetVersion) &gt;= 4 then<br> &nbsp; &nbsp;begin<br> &nbsp; &nbsp; &nbsp;MenuItemInfo.cbSize := 44; // Required for Windows 95<br> &nbsp; &nbsp; &nbsp;MenuItemInfo.fMask := MIIM_CHECKMARKS or MIIM_DATA or MIIM_ID or<br> &nbsp; &nbsp; &nbsp; &nbsp;MIIM_STATE or MIIM_SUBMENU or MIIM_TYPE;<br> &nbsp; &nbsp; &nbsp;ParentMenu := GetParentMenu;<br>// &nbsp; &nbsp; &nbsp;IsOwnerDraw := Assigned(ParentMenu) and ParentMenu.IsOwnerDraw or<br> &nbsp; &nbsp; &nbsp;IsOwnerDraw := Assigned(ParentMenu) and<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; (ParentMenu.OwnerDraw or (GetImageList &lt;&gt; nil)) or<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Assigned(FBitmap) and not FBitmap.Empty;<br> &nbsp; &nbsp; &nbsp;MenuItemInfo.fType := IRadios[FRadioItem] or IBreaks[FBreak] or<br> &nbsp; &nbsp; &nbsp; &nbsp;ISeparators[FCaption = cLineCaption] or IRTL[ARightToLeft] or<br> &nbsp; &nbsp; &nbsp; &nbsp;IOwnerDraw[IsOwnerDraw];<br> &nbsp; &nbsp; &nbsp;MenuItemInfo.fState := IChecks[FChecked] or IEnables[FEnabled]<br> &nbsp; &nbsp; &nbsp; &nbsp;or IDefaults[FDefault];<br> &nbsp; &nbsp; &nbsp;MenuItemInfo.wID := Command;<br> &nbsp; &nbsp; &nbsp;MenuItemInfo.hSubMenu := 0;<br> &nbsp; &nbsp; &nbsp;MenuItemInfo.hbmpChecked := 0;<br> &nbsp; &nbsp; &nbsp;MenuItemInfo.hbmpUnchecked := 0;<br> &nbsp; &nbsp; &nbsp;MenuItemInfo.dwTypeData := PChar(Caption);<br> &nbsp; &nbsp; &nbsp;if GetCount &gt; 0 then<br> &nbsp; &nbsp; &nbsp; &nbsp;MenuItemInfo.hSubMenu := GetHandle;<br> &nbsp; &nbsp; &nbsp;InsertMenuItem(Menu, DWORD(-1), True, MenuItemInfo);<br> &nbsp; &nbsp;end<br> &nbsp; &nbsp;else<br> &nbsp; &nbsp;begin<br> &nbsp; &nbsp; &nbsp;NewFlags := Breaks[FBreak] or Checks[FChecked] or Enables[FEnabled] or<br> &nbsp; &nbsp; &nbsp; &nbsp;Separators[FCaption = cLineCaption] or MF_BYPOSITION;<br> &nbsp; &nbsp; &nbsp;if GetCount &gt; 0 then<br> &nbsp; &nbsp; &nbsp; &nbsp;InsertMenu(Menu, DWORD(-1), MF_POPUP or NewFlags, GetHandle,<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;PChar(FCaption))<br> &nbsp; &nbsp; &nbsp;else<br> &nbsp; &nbsp; &nbsp; &nbsp;InsertMenu(Menu, DWORD(-1), NewFlags, Command, PChar(Caption));<br> &nbsp; &nbsp;end;<br> &nbsp;end;<br>end;
 
估计你提的方法也无用,其实同样的程序我已经编写出来,只是觉得有可能用Api方式也能实现,所以我想试验一下而已。这样也是提高自己水平的一种方式。另外以前我编写一个dll作为资源管理器的扩展,居然很糊涂的实现了子菜单的功能,不过当时不是我需要的,所以没有心得留下,现在有些后悔。
 
那你就把比较完整的测试代码贴上来,或许大虾看到给你一些指点
 
我的程序比较复杂,其实大侠们是不需要的,所以我觉得没有必要,本来我觉得既然能够用api创建一个菜单,那么再添加一个子菜单应该也不是难题,所以才想来问一下,现在看来是难以实现了,因为如果可以实现也就是2-3行代码的问题而已,不会很复杂的,只是我现在不懂而已,我有个经验,就是当问题经过时间考验以后经常很容易解决。等一下可能会有收获。
 
果然是高手
 
可是问题还没有头绪呢?到时候我拿什么给别人?耐心点吧,其实一段优秀的代码比那些分更加重要。
 
既然这样,对我这样的初学者,楼主能不能把测试代码放出来,学习以下,同时也看看能不能做一定修改呢
 
chenybin:怎么到处看到你呢?你好像就是在要分啊?如果对别人有帮助的话,要求也是可以的。可是我的问题根本没有解决,就这样把分发出去不好吧?还是这里只要是灌水就可以得分呢?我认为这样得分很不好。
 
AppendMenu 函数原型:<br>  BOOL AppendMenu(<br>     HMENU hMenu, // 要定制的菜单句柄<br>     UINT uFlags, // 怎样定制菜单项<br>     UINT uIDNewItem, // 要定制的菜单项标识或子菜单句柄<br>     LPCTSTR lpNewItem // 要定制的菜单项(字串)<br>    );<br>  在 AppendMenu 函数里,lpNewItem 和 uIDNewItem 参数依赖 uFlags 的不同标志而有所变化。<br>  唯一限制:系统菜单中添加的菜单项的ID值(uIDNewItem)必须小于 $F000(十进制:61440);否则会与Windows系统菜单命令所使用的ID值相冲突。还要记住当为这些新菜单在窗口过程中处理WM_SYSCOMMAND消息时,必须把其它的WM_SYSCOMMAND消息发给DefWindowsProc(在Delphi中秩序在事件处理程序最后加入一句 Inherited;),否则,嘿嘿,你试试就知道了。<br><br>但我也没用这个函数来生成子菜单成功,我是用这个方法<br>var<br> &nbsp;Added &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; : UINT;<br> &nbsp;menuItemInfo &nbsp; &nbsp; &nbsp;: TMenuItemInfo;<br> &nbsp;TempMenu &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;: HMENU;<br><br> &nbsp;function Make_HResult(sev, fac, code: Word): DWord;<br> &nbsp;begin<br> &nbsp; &nbsp;Result := (sev shl 31) or (fac shl 16) or code;<br> &nbsp;end;<br><br> &nbsp;procedure BuildsubMenu(const ID: Integer; subMenuName: PAnsiChar;<br> &nbsp; &nbsp;resourceName:<br> &nbsp; &nbsp;string);<br> &nbsp;begin<br> &nbsp; &nbsp;menuitemInfo.dwTypeData := subMenuName;<br> &nbsp; &nbsp;menuitemInfo.cch := sizeof(subMenuName);<br> &nbsp; &nbsp;menuitemInfo.wID := IDCmdFirst + ID;<br> &nbsp; &nbsp;menuitemInfo.hSubMenu := 0;<br> &nbsp; &nbsp;InsertMenuItem(TempMenu, IndexMenu, True, menuItemInfo); //子菜单1<br> &nbsp; &nbsp;SetMenuItemBitmaps(TempMenu, indexMenu, MF_BYPOSITION,<br> &nbsp; &nbsp; &nbsp;LoadBitmap(HInstance, PChar(resourceName)), 0);<br> &nbsp;end;<br><br>begin<br> &nbsp;Result := 0;<br> &nbsp;if Menu = 0 then<br> &nbsp; &nbsp;TempMenu := CreateMenu<br> &nbsp;else<br> &nbsp; &nbsp; TempMenu := Menu;<br><br> &nbsp;with menuitemInfo do &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;// Build the menu items here<br> &nbsp;begin<br> &nbsp; &nbsp; cbSize := SizeOf(TMenuItemInfo);<br> &nbsp; &nbsp; fMask := MIIM_ID or MIIM_SUBMENU or MIIM_TYPE;<br> &nbsp; &nbsp; fType := MFT_STRING;<br> &nbsp; &nbsp; fState := MFS_ENABLED;<br> &nbsp; end;<br> &nbsp; InsertMenu(Menu, indexMenu, mfSeparator, 0, nil); //分隔线<br> &nbsp; Inc(IDCmdFirst);<br><br> &nbsp; menuitemInfo.dwTypeData := MenuStr;<br> &nbsp; menuitemInfo.cch := sizeof(MenuStr);<br> &nbsp; menuitemInfo.hSubMenu := CreatePopupMenu;<br> &nbsp; TempMenu := menuitemInfo.hSubMenu;<br> &nbsp; menuitemInfo.wID := IDCmdFirst + IDMainMenu;<br><br> &nbsp; InsertMenuItem(Menu, IndexMenu, True, menuItemInfo); //主菜单<br> &nbsp; SetMenuItemBitmaps(Menu, indexMenu, MF_BYPOSITION,<br> &nbsp; &nbsp; LoadBitmap(HInstance, PChar('myBitmap')), 0);<br> &nbsp; Inc(IDCmdFirst);<br><br> &nbsp; InsertMenu(Menu, indexMenu, mfSeparator, 0, nil); //分隔线 +Added<br> &nbsp; Inc(IDCmdFirst);<br><br> &nbsp; BuildsubMenu(idClearTemp, '子菜单1, 'mybmp1'); //生成子菜单<br> &nbsp; BuildsubMenu(idCopyAnywhere, '子菜单2', 'mybmp2');<br> &nbsp; BuildsubMenu(idWipeFile, '子菜单3', 'mybmp3');<br> &nbsp; BuildsubMenu(IDBatchRename, '子菜单4', 'mybmp3');<br>end;
 
API创建子菜单就像吃豆豆,具体我就没时间帮你写了,提示一下 MF_POPUP
 
其实说白了吧,我认为用AppendMenu可以解决,所以我想让楼主把代码贴出来,说不定可以帮你看到问题所在,就这么简单,但是楼主一直觉得不屑给我这样的初学者贴代码,唉……
 
我的程序初步如下,由于的API知识很有限,所以不足之处很多,如果有高手请为我修改一下:(主要目标是能够将几个菜单继承在mainmenu中,目前以我的能力无法办到)<br>program Menu2005;<br><br><br>uses<br> &nbsp;Windows,Messages,mmsystem,SysUtils,shellapi;<br><br>var<br> &nbsp;WinClass: TWndClassA;<br> &nbsp;Inst, Handle: Integer;<br> &nbsp;Msg: TMsg;<br> &nbsp;play,cdplay:boolean;<br> &nbsp;trueid,lockid,command,songpos,songsum:integer;<br> &nbsp;f:textfile;<br> &nbsp;mainmenu,urlmenu,myfilemenu,mediamenu,progmenu:hmenu;<br> &nbsp;aatom:atom;<br> &nbsp;cddrive:string;<br><br>{$R *.RES}<br>const extstr='.mp3.mpg.mpeg.mpga.mid.wav.wma';<br>maincount=6;<br>mainstr:array[0..maincount] of string=('我的菜单','快捷访问','网站','程序','多媒体','-',<br>'退出');<br><br>mediacount=3;<br>mediastr:array[0..mediacount]of string=('返回菜单','播放','停止','AudioCD');<br><br>function isfile(substr,str:string):boolean;<br>var i:integer;<br>begin<br>result:=false;<br>i:=pos(substr,str);<br>if i&gt;0 then result:=true;<br>end;<br><br>procedure closetimer;<br>begin<br>lockid:=Settimer(handle,1000,200,nil);<br>end;<br><br>procedure stopsong;<br>begin<br>play:=false;<br>//cdplay:=false;<br>Killtimer(handle,trueid);<br>mciSendString ('stop myAudio', nil, 0, 0);<br>mciSendString ('close myAudio', nil, 0, 0);<br>end;<br><br>function SendMCIString(cmd :PChar) : string;<br>var x: hwnd;<br> &nbsp; &nbsp;a: array [0..20] of char;<br>begin<br> x:=0;<br> mciSendString(cmd, a, 20, x);<br> SendMCIString := a;<br>end;<br><br>function gettime(track:integer):integer;<br>var min,sec,mci:string;<br>begin<br>mci:= 'seek myAudio to ' +inttostr(track+1);<br>SendMCIString(PChar(mci));<br>mci := SendMCIString('status myAudio media present');<br>if mci = 'true' then begin<br>mci := 'status myAudio length track ' + IntToStr(track+1);<br>mci:= SendMCIString(PChar(mci));<br>sec:= Copy(mci, 4, 2);<br>min:= Copy(mci, 0, 2);<br>end;<br>result:=strtoint(min)*60+strtoint(sec);<br>end;<br><br>procedure playcdtrack(track:integer);<br>begin<br>SendMCIString('open myAudio wait shareable');<br>mciSendString('play myAudio notify', nil, 0, 0);<br>mciSendString ('play myAudio', nil, 0, 0);<br>SendMCIString(PChar('play myAudio from ' + IntToStr(track+1)));<br>end;<br><br>procedure playsong(track:integer);<br>var i:integer;<br> f:textfile;<br>Buffer : array [0..255] of char;<br>ext:string;<br>begin<br>AssignFile(f,'song.txt');<br>Reset(f);<br>for i:=0 to track do<br>Readln(f,cddrive);<br>Closefile(f);<br>GetShortPathName(pchar(cddrive), @Buffer, sizeof(Buffer));<br>ext:=extractfileext(cddrive);<br>ext:=ansilowercase(ext);<br>if not &nbsp;isfile(ext,extstr) then begin<br>if songpos=songsum-1 then begin stopsong; exit;end;<br>songpos:=songpos+1;<br>play:=false;<br>playsong(songpos);<br>closetimer;<br>exit;<br>end;<br>mciSendString ('close myAudio', nil, 0, 0);<br>mciSendString (pChar('open ' + buffer + ' alias myAudio'), nil, 0, 0);<br>mciSendString('play myAudio notify', nil, 0, handle);<br>end;<br><br><br><br>procedure nextsong;<br>begin<br>if songpos=songsum-1 then begin stopsong; exit;end;<br>songpos:=songpos+1;<br>play:=false;<br>playsong(songpos);<br>closetimer;<br>end;<br><br><br>function getcdtrack(drive:string):integer;<br>var tracks:integer;<br>Buffer : array [0..255] of char;<br>begin<br>GetShortPathName(pchar( drive+'Track01.cda' ), @Buffer, sizeof(Buffer));<br>mciSendString ('stop myAudio', nil, 0, 0);<br>mciSendString ('close myAudio', nil, 0, 0);<br>mciSendString (pChar('open ' + buffer + ' alias myAudio'), nil, 0, 0);<br>mciSendString('play myAudio notify', nil, 0, handle);<br>mciSendString ('play myAudio', nil, 0, 0);<br><br>SendMCIString('open myAudio wait shareable');<br>SendMCIString('stop myAudio');<br>SendMCIString('set myAudio time format tmsf wait');<br>tracks:=strtoint(SendMCIString('status myAudio number of tracks'));<br>result:=tracks;<br>end;<br><br><br><br>function DiskInDrive(Drive: Char): Boolean;<br>var ErrorMode: word;<br>begin<br>{ make it upper case }<br>if Drive in ['a'..'z'] then Dec(Drive, $20);<br>{ make sure it's a letter }<br>if not (Drive in ['A'..'Z']) then<br>raise EConvertError.Create('Not a valid drive ID');<br>{ turn off critical errors }<br>ErrorMode := SetErrorMode(SEM_FailCriticalErrors);<br>try<br>{ drive 1 = a, 2 = b, 3 = c, etc. }<br>if DiskSize(Ord(Drive) - $40) = -1 then<br>Result := False<br><br>else<br>Result := True;<br>finally<br>{ restore old error mode }<br>SetErrorMode(ErrorMode);<br>end;<br>end;<br><br><br>function IsAudioCD(Drive : char):boolean;<br>var<br> &nbsp;DrivePath : string;<br> &nbsp; MaximumComponentLength : DWORD;<br> &nbsp; FileSystemFlags : DWORD;<br> &nbsp; VolumeName : string;<br> &nbsp; DriveType: UINT;<br> begin<br> &nbsp; Result := false;<br> &nbsp; DrivePath := Drive + ':/';<br> &nbsp; DriveType := GetDriveType(Pchar(DrivePath));<br> &nbsp; if DriveType &lt;&gt; DRIVE_CDROM then<br> &nbsp; &nbsp; &nbsp;exit;<br> &nbsp; SetLength(VolumeName, 64);<br> &nbsp; GetVolumeInformation(PChar(DrivePath),<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;PChar(VolumeName),<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;Length(VolumeName),<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;nil,<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;MaximumComponentLength,<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;FileSystemFlags,<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;nil,<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;0);<br> &nbsp; if lStrCmp(PChar(VolumeName),'Audio CD') = 0 then result := true;<br> end;<br><br>Function FindCDROMDrive: Char;<br>Var<br>drivemap, mask: DWORD;<br>i: Integer;<br>root: String;<br>Begin<br>Result := #0;<br>root := 'A:/';<br>drivemap := GetLogicalDrives;<br>mask := 1;<br>For i:= 1 To 32 Do Begin<br>If (mask and drivemap) &lt;&gt; 0 Then<br>If GetDriveType( PChar(root) ) = DRIVE_CDROM Then Begin<br>Result := root[1];<br>if diskindrive(result)and isaudiocd(result) then begin<br>cddrive:=result+':/';<br>end &nbsp;else begin<br>setwindowtext(handle,pchar('No AudioCD'));<br>cddrive:='';<br>end;<br>end;<br>mask := mask shl 1;<br>Inc( root[1] );<br>end;<br>End;<br><br>procedure playcd;<br>var i:integer;<br>begin<br>if not cdplay then begin<br>FindCDROMDrive;<br>if cddrive='' then exit;<br>songsum:=getcdtrack(cddrive);<br><br>AssignFile(f,'audio.txt');<br>ReWrite(f);<br><br>AppendMenu (mediamenu, MF_STRING, 4, '-');<br><br>for i:=0 to songsum-1 do &nbsp;begin<br>Writeln(f,inttostr(gettime(i)));<br>AppendMenu (mediamenu, MF_STRING, i+5, pchar('Track'+inttostr(i+1)));<br>end;<br>Closefile(f);<br>playcdtrack(0);<br>cdplay:=true;<br>end;<br><br>end;<br><br><br><br><br>procedure myfilemenucreate;<br>var i,p:integer;<br>str:string;<br>pt:tpoint;<br>begin<br>AssignFile(f,'myfile.txt');<br>Reset(f);<br>i:=0;<br>myfilemenu:=CreatePopupMenu;<br>appendmenu(myfilemenu, MF_popup, 0, '返回菜单');<br>repeat<br>i:=i+1;<br>Readln(f,str);<br>p:=pos('|',str);<br>str:=copy(str,1,p-1);<br>appendmenu(myfilemenu, MF_popup, i, pchar(str));<br>until eof(f);<br>getcursorpos(pt);<br>TrackPopupMenu (myfilemenu, tpm_BottomAlign or tpm_RightAlign,<br>pt.x+150,pt.y-10, 0, handle, Nil);<br><br>end;<br><br>procedure urlmenucreate;<br>var i,p:integer;<br>str:string;<br>pt:tpoint;<br>begin<br>AssignFile(f,'url.txt');<br>Reset(f);<br>i:=0;<br>urlmenu:=CreatePopupMenu;<br>appendmenu(urlmenu, MF_popup, 0, '返回菜单');<br>repeat<br>i:=i+1;<br>Readln(f,str);<br>p:=pos('|',str);<br>str:=copy(str,1,p-1);<br>appendmenu(urlmenu, MF_popup, i, pchar(str));<br>until eof(f);<br>getcursorpos(pt);<br>TrackPopupMenu (urlmenu, tpm_BottomAlign or tpm_RightAlign,<br>pt.x+150,pt.y-10, 0, handle, Nil);<br>end;<br><br>procedure progcreate;<br>var i,p:integer;<br>str:string;<br>pt:tpoint;<br>begin<br>AssignFile(f,'program.txt');<br>Reset(f);<br>i:=0;<br>progmenu:=CreatePopupMenu;<br>appendmenu(progmenu, MF_popup, 0, '返回菜单');<br>repeat<br>i:=i+1;<br>Readln(f,str);<br>p:=pos('|',str);<br>str:=copy(str,1,p-1);<br>appendmenu(progmenu, MF_popup, i, pchar(str));<br>until eof(f);<br>getcursorpos(pt);<br>TrackPopupMenu (progmenu, tpm_BottomAlign or tpm_RightAlign,<br>pt.x+150,pt.y-10, 0, handle, Nil);<br>end;<br><br><br>procedure mediacreate;<br>var i:integer;<br>begin<br>mediamenu:=createpopupmenu;<br>for i:=0 to mediacount do<br>appendmenu(mediamenu, MF_popup, i, pchar(mediastr));<br>end;<br><br><br>procedure mainmenuclick(cmd:word);<br>var <br>i,p:integer;<br>str:string;<br>begin<br><br>case command of<br><br>//myfile<br>1:begin<br>if cmd=0 then begin<br>command:=0;<br>exit;<br>end;<br><br>AssignFile(f,'myfile.txt');<br>Reset(f);<br>for i:=0 to cmd-1 do<br>Readln(f,str);<br>p:=pos('|',str);<br>delete(str,1,p);<br>ShellExecute(handle,nil,pchar(str),nil,nil,sw_shownormal);<br>end;<br>//net<br>2:begin<br><br>if cmd=0 then begin<br>command:=0;<br>exit;<br>end;<br>AssignFile(f,'url.txt');<br>Reset(f);<br>for i:=0 to cmd-1 do<br>Readln(f,str);<br>p:=pos('|',str);<br>delete(str,1,p);<br>ShellExecute(handle,nil,pchar(str),nil,nil,sw_shownormal);<br>end;<br>//program<br>3:begin<br>if cmd=0 then begin<br>command:=0;<br>exit;<br>end;<br>AssignFile(f,'program.txt');<br>Reset(f);<br>for i:=0 to cmd-1 do<br>Readln(f,str);<br>p:=pos('|',str);<br>delete(str,1,p);<br>ShellExecute(handle,nil,pchar(str),nil,nil,sw_shownormal);<br><br><br>end;<br><br>//mediaplay<br>4:begin<br><br>case cmd of<br>0:begin<br>command:=0;<br>exit;<br>end;<br>//playsong;<br>1:begin<br>AppendMenu (mediamenu, MF_STRING, 4, '-');<br>AssignFile(f,'song.txt');<br>Reset(f);<br>i:=0;<br>repeat<br>i:=i+1;<br>Readln(f,str);<br>str:=extractfilename(str);<br>AppendMenu (mediamenu, MF_STRING, i+4, pchar(str));<br>until eof(f);<br>songsum:=i;<br>Closefile(f);<br>songpos:=0;<br>playsong(0);<br>cdplay:=false;<br>end;<br>//stopsong;<br>2:begin<br>stopsong;<br>cdplay:=false;<br>end;<br><br>//play AudioCD<br>3:begin<br>stopsong;<br>playcd;<br><br>end;<br>//plyasong(i);<br>5..1000:begin<br>songpos:=cmd-5;<br>if cdplay then playcdtrack(songpos) else<br>begin<br>stopsong;<br>playsong(songpos);<br>end;<br>end;<br><br><br>end;<br><br><br><br><br>end;<br><br><br><br>0:begin<br><br>case cmd of<br><br>1:begin<br>myfilemenucreate;<br>command:=1;<br>end;<br><br>2:begin<br>urlmenucreate;<br>command:=2;<br>end;<br><br>3:begin<br>progcreate;<br>command:=3;<br><br>end;<br><br>4:begin<br>mediacreate;<br>command:=4;<br><br>end;<br><br>maincount:PostMessage (handle, wm_Close, 0, 0);<br>end;<br><br><br><br>end;<br><br>end;<br>end;<br><br><br>procedure creatmainmenu;<br>var i:integer;<br>begin<br>mainmenu:=CreatePopupMenu;<br>for i:=0 to maincount do<br>appendmenu(mainmenu, MF_string, i, pchar(mainstr));<br><br>aatom:=globaladdatom('hot key');<br>RegisterHotKey(handle,aatom,0,VK_F2);<br><br>end;<br><br><br><br><br>{ Custom WindowProc function }<br>function WindowProc(hWnd, uMsg, wParam, lParam: Integer): Integer; stdcall;<br>var pt: TPoint;<br>begin<br><br>Result := DefWindowProc(hWnd, uMsg, wParam, lParam);<br><br>case uMsg of<br><br>wm_hotkey:begin<br>GetCursorPos (pt);<br>case command of<br><br>0:TrackPopupMenu (mainmenu, tpm_BottomAlign or tpm_RightAlign,<br>pt.x,pt.y, 0, handle, Nil);<br><br>1:TrackPopupMenu (myfilemenu, tpm_BottomAlign or tpm_RightAlign,<br>pt.x,pt.y, 0, handle, Nil);<br><br>2:TrackPopupMenu (urlmenu, tpm_BottomAlign or tpm_RightAlign,<br>pt.x,pt.y, 0, handle, Nil);<br><br>3:TrackPopupMenu (progmenu, tpm_BottomAlign or tpm_RightAlign,<br>pt.x,pt.y, 0, handle, Nil);<br><br><br>4:TrackPopupMenu (mediamenu, tpm_BottomAlign or tpm_RightAlign,<br>pt.x,pt.y, 0, handle, Nil);<br>end;<br><br>closetimer;<br>end;<br><br>wm_timer:begin<br>if command=4 then play:=true;<br>Killtimer(handle,lockid);<br>end;<br><br>MM_MCINOTIFY:<br>if play then nextsong;<br><br>WM_COMMAND:begin<br>mainmenuclick(wparam);<br>end;<br><br>wm_create:begin<br><br>end;<br><br>wm_close:begin<br><br>end;<br><br>WM_DESTROY:begin<br>stopsong;<br>UnRegisterClass('mymenu',Inst);<br>ExitProcess(Inst);<br>halt;<br>end;<br>end;<br><br><br>end;<br><br><br>begin<br><br> &nbsp;{ ** Register Custom WndClass ** }<br> &nbsp;Inst := hInstance;<br><br> &nbsp;with WinClass do<br> &nbsp;begin<br> &nbsp; &nbsp;style &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;:= CS_CLASSDC or CS_PARENTDC;<br> &nbsp; &nbsp;hIcon &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;:= LoadIcon(Inst,'MAINICON');<br> &nbsp; &nbsp;lpfnWndProc &nbsp; &nbsp; &nbsp; &nbsp;:= @WindowProc;<br> &nbsp; &nbsp;hInstance &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;:= Inst;<br> &nbsp; &nbsp;hbrBackground &nbsp; &nbsp; &nbsp;:= color_btnface + 1;<br> &nbsp; &nbsp;lpszClassname &nbsp; &nbsp; &nbsp;:= 'mymenu';<br> &nbsp; &nbsp;hCursor &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;:= LoadCursor(0, IDC_ARROW);<br> &nbsp;end; { with }<br> &nbsp;RegisterClass(WinClass);<br><br> &nbsp;{ ** Create Main Window ** }<br> &nbsp;Handle := CreateWindowEx(WS_EX_TOOLWINDOW , 'mymenu', 'Mymenu 1.0',<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; WS_CAPTION or WS_SYSMENU,<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;150, 150,205, 48, 0, 0, Inst, nil);<br><br>UpdateWindow(Handle);<br>creatmainmenu;<br>command:=0;<br> &nbsp; &nbsp; &nbsp;{ ** Message Loop ** }<br>while(GetMessage(Msg, Handle, 0, 0)) do<br>begin<br>TranslateMessage(msg);<br>DispatchMessage(msg);<br>end; { with }<br><br><br>end.
 
myfile.txt内容<br>驱动器 A |a:/<br>驱动器 C |c:/<br>驱动器 D |d:/<br>驱动器 E |e:/<br>驱动器 F|F:/<br>驱动器 G|G:/<br><br>program.txt内容<br>计算器|C:/WINDOWS/system32/calc.exe<br>画笔|C:/WINDOWS/system32/mspaint.exe<br>记事本|C:/WINDOWS/notepad.exe<br>regedit|C:/WINDOWS/regedit.exe<br>DELPHI32|C:/Program Files/Borland/Delphi6/Bin/DELPHI32.EXE<br>FLASHGET|C:/Program Files/FlashGet/FLASHGET.EXE<br>HappyEO3pc|C:/Program Files/HappyEO3pc/HappyEO3pc.exe<br>Word2003|C:/Program Files/Microsoft Office/OFFICE11/WINWORD.EXE<br>EXCEL2003|C:/Program Files/Microsoft Office/OFFICE11/EXCEL.EXE<br>ONENOTE2003|C:/Program Files/Microsoft Office/OFFICE11/ONENOTE.EXE<br>MyIE|C:/Program Files/MYIE2/MyIE.exe<br>媒体播放器|C:/Program Files/Windows Media Player/wmplayer.exe<br>Windows优化大师|C:/Program Files/Wom/Windows优化大师.exe<br>mywork|C:/mywork20/mywork.exe<br>vdtask|C:/Program Files/FarStone/VirtualDrive/vdtask.exe<br>PowerDVD|C:/Program Files/CyberLink/PowerDVD/PowerDVD.exe<br>dxdiag|C:/WINDOWS/system32/dxdiag.exe<br>realplay|C:/Program Files/Real/RealPlayer/realplay.exe<br>openurl|D:/myfile/test/mymenu/openurl.exe<br><br>url.txt内容<br>网易|http://www.163.com<br>新浪|http://www.sina.com.cn/<br>搜狐首页|http://www.sohu.com/<br>千龙网|http://www.beijingnews.com.cn/<br>新华网|http://www.xinhuanet.com/<br>Msn频道|http://www.msn.com.cn/<br>太平洋硬件|http://www.pconline.com.cn/notebook/<br>本本玩家|http://itbbs.pconline.com.cn/forum.jsp?fid=6<br>中广在线|http://211.89.225.2/<br>在线广播|http://radio.skyhits.com/
 
上面两条是抛砖引玉的内容,还不完善。
 
后退
顶部