用户登录  |  用户注册
首 页商业源码原创产品编程论坛
当前位置:PB创新网文章中心编程技巧VisualBasic

用VB创建Windows快捷方式(无需DLL)

减小字体 增大字体 作者:佚名  来源:本站整理  发布时间:2009-03-16 19:55:21
  创建开始菜单快捷方式

Option Explicit

Private Sub Command1_Click()

CreateProgManGroup Me, "测试", "test.grp"
CreateProgManItem Me, "d:\ghost.exe", "Ghost"
CreateProgManItem Me, "d:\setupQQ.exe", "QQ"

End Sub

Sub CreateProgManGroup(X As Form, GroupName$, GroupPath$)
Dim i As Integer
X.Label1.LinkTopic = "ProgManProgman"
X.Label1.LinkMode = 2
Rem 空循环使DDE有时间执行
For i = 1 To 10
DoEvents
Next
X.Label1.LinkTimeout = 100
Rem LinkExecute 是在DDE通道中传送这样的命令
'──建立一个名为GroupName $的程序组。
X.Label1.LinkExecute "[ CreateGroup (" + GroupName$ + Chr$(44) + GroupPath$ + ") ]"
X.Label1.LinkTimeout = 50 '恢复Label1 的属性值
X.Label1.LinkMode = 0
End Sub


Sub CreateProgManItem(X As Form, CmdLine$, IconTitle$)
Dim i As Integer
X.Label1.LinkTopic = "ProgManProgman"
X.Label1.LinkMode = 2
For i = 1 To 10
DoEvents
Next
X.Label1.LinkTimeout = 100
X.Label1.LinkExecute "[AddItem(" + CmdLine$ + Chr$(44) + IconTitle$ + Chr$(44) + ", ,) ]"
X.Label1.LinkTimeout = 50 '恢复Label1 的属性值
X.Label1.LinkMode = 0
Screen.MousePointer = 0
End Sub



  将程序建立成“启动”文件夹的捷径

Text1.LinkTopic = "ProgmanProgman"
Text1.LinkMode = 2 '手动
Text1.LinkExecute "[ShowGroup(启动, 4)]"
Text1.LinkExecute "[AddItem(可执行文件完整路径, 捷径名称)]"


  假设我们想把“c:\vb5db\myprog.exe”建立成“启动”资料夹名称为“我的程序”的捷径,则最后一行的 LinkExecute 应该如下:

Text1.LinkExecute "[AddItem(c:\vb5db\myprog.exe, 我的程序)]"



  在桌面上添加程序的快捷方式
  假如程序为C:\Program Files\MyProg\Prog.exe,需加参数/Para
  新键一个项目,添加命令按钮和标签各一个,把下面的代码加上去,一运行,你将如愿以偿!

Option Explicit
Private Sub Command1_Click()
  CreateGroup "MyProg", "", "", 2, True
  CreateGroup "MyProg", "C:\ProgramFiles\MyProg\Prog.exe/Para", _
  "Para", 3, True
End Sub
Sub CreateGroup(ByVal strGroup As String, ByVal strCmd As String, ByVal _
strTitle As String, ByVal intDDE As Integer, ByVal fLog As Boolean)
  Const strCOMMA$ = ","
  Const strRESTORE$ = ", 1)]"
  Const strACTIVATE$ = ", 5)]"
  Const strENDCMD$ = ")]"
  Const strSHOWGRP$ = "[ShowGroup("
  Const strADDGRP$ = "[CreateGroup("
  Const strREPLITEM$ = "[ReplaceItem("
  Const strADDITEM$ = "[AddItem("

  Dim i As Integer
  Dim Sourcefile As String, Destinationfile As String

  Form1.Label1.LinkMode = 0
  For i% = 1 To 20
   On Error Resume Next
   Form1.Label1.LinkTopic = "PROGMANPROGMAN" '设置发送端应用程序和主题
   If Err = 0 Then Exit For
   DoEvents
  Next
  Form1.Label1.LinkMode = 2 '采用手动方式建立连接
  For i% = 1 To 10
   DoEvents
  Next
  Form1.Label1.LinkTimeout = 100 '设置等待 DDE 响应消息的时间。

  If Err = 0 Then
   Select Case intDDE
     Case 1 '建立程序项
      Form1.Label1.LinkExecute strADDGRP & strGroup & strENDCMD
      Form1.Label1.LinkExecute strADDITEM & strCmd & strCOMMA & _
        strTitle & String$(3, strCOMMA) & strENDCMD
     Case 2 '建立程序组
      Form1.Label1.LinkExecute strADDGRP & strGroup & strENDCMD
      Form1.Label1.LinkExecute strSHOWGRP & strGroup & strRESTORE
VB论坛

[1] [2]  下一页

Tags:

作者:佚名

文章评论评论内容只代表网友观点,与本站立场无关!

   评论摘要(共 0 条,得分 0 分,平均 0 分) 查看完整评论
PB创新网ourmis.com】Copyright © 2000-2009 . All Rights Reserved .
页面执行时间:7,343.75000 毫秒
Email:ourmis@126.com QQ:2322888 蜀ICP备05006790号