VB °æ (¾«»ªÇø)
·¢ÐÅÈË: xiangchu (Ìì¸è), ÐÅÇø: VisualBasic
±ê Ìâ: Visual Basic±à³ÌÎÊ´ð¼¯(Èý)
·¢ÐÅÕ¾: ×Ï ¶¡ Ïã (Tue Aug 31 14:59:22 1999), תÐÅ
(½ÓÉÏÆÚ)
¡õ ÔõôÔÚVBÖÐʵÏÖDelphiÄÇÑùµÄMouseEnterºÍMouseExitµÄ¹¦ÄÜ£¿
VBÖеÄÊó±êʼþÇý¶¯Ö»ÓÐMouseDown,MouseMove,MouseUpÈý¸öʼþ£¬Ã»ÓÐÏó
DelphiÄÇÑùÌṩMouseEnter(OnEnter)ºÍMouseExit(OnExit)µÄʼþ¡£¶øÕâÁ½¸ö
ʼþÊÇÆ½Ê±±àд³ÌÐò¾³£ÒªÓõ½µÄ£¬ÎÒÃÇ¿ÉÒÔͨ¹ýµ÷ÓÃSetCaptureºÍReleaseCapture
ÕâÁ½¸öWindows APIº¯ÊýµÄ·½·¨À´ÊµÏÖËü¡£¾ßÌå²½ÖèÈçÏ£º
1) ÔÚVBÖÐн¨Ò»¸ö±ê×¼EXE¹¤³Ì£»
2) »³öÒ»¸ö°´Å¥Command1£»
3) ÔÚ´°ÌåForm1Öж¨ÒåWindows APIµÄÉùÃ÷£»
Private Declare Function SetCapture Lib "user32" (ByVal hWnd As Long) As Long
Private Declare Function ReleaseCapture Lib "user32" () As Long
4) ÔÚCommand1µÄMouseMoveʼþÖбàдÒÔÏ´úÂ룺
Private Sub Command1_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
Dim MouseEnter As Boolean 'Êó±ê½øÈëµÄ±ê־λ
MouseEnter = (0 <= X) And (X <= Command1.Width) And _
(0 <= Y) And (Y <= Command1.Height) '¼ÆËãÊó±êµÄÒÆ¶¯ÊÇ·ñÔÚCommand1ÀïÃæ
If MouseEnter Then 'Êó±êÒѾ½øÈë
Me.Caption = "Mouse In Button!"
SetCapture Command1.hWnd
Else 'Êó±êÒѾÀ뿪
Me.Caption = "Mouse Out!"
ReleaseCapture
End If
End Sub
¡õ Èç¹ûÔÚWindowsÖÐΪ×Ô¼ºµÄÈí¼þ½¨Á¢³ÌÐò×éºÍ³ÌÐòÏ
¿ÉÒÔÓÃWindows DDE(¶¯Ì¬Êý¾Ý½»»»)µÄ°ì·¨¸úProgram Manager(³ÌÐò¹ÜÀíÆ÷)
½øÐÐÓ¦´ð£¬½¨Á¢³ÌÐò×éºÍ³ÌÐòÏî¡£³ÌÐòʵÏÖÈçÏ£º
1) ÔÚVBÖÐн¨Ò»¸ö±ê×¼EXE¹¤³Ì£»
2) ½¨Á¢Ò»¸öÓÃÓÚDDEÊý¾Ý½»»»µÄLabel1£»
3) ±àд´´½¨³ÌÐò×éCreateProgManGroup()ºÍ´´½¨³ÌÐòÏîCreateProgManItem()º¯ÊýÈçÏ£º
Sub CreateProgManGroup(frm As Form, GroupName$, GroupPath$)
On Error Resume Next
Screen.MousePointer = 11
frm.Label1.LinkTopic = "ProgMan|Progman"
frm.Label1.LinkMode = 2
For i% = 1 To 10 'µÈ´ýÓ¦´ð
z% = DoEvents()
Next i%
frm.Label1.LinkTimeout = 100
frm.Label1.LinkExecute _
"[CreateGroup(" + GroupName$ + Chr$(44) + GroupPath$ + ")]"
DoEvents
frm.Label1.LinkTimeout = 50
frm.Label1.LinkMode = 0
Screen.MousePointer = 0
End Sub
Private Sub CreateProgManItem(frm As Form, CmdLine$, IconTitle$, IconFile$)
On Error Resume Next
Screen.MousePointer = 11
frm.Label1.LinkTopic = "ProgMan|Progman"
frm.Label1.LinkMode = 2
For i% = 1 To 10
z% = DoEvents()
Next i%
frm.Label1.LinkTimeout = 100
frm.Label1.LinkExecute "[ReplaceItem(" + IconTitle$ + ")]"
frm.Label1.LinkExecute "[AddItem(" + CmdLine$ + Chr$(44) + _
IconTitle$ + Chr$(44) + IconFile$ + Chr$(44) + ",,)]"
frm.Label1.LinkTimeout = 50
frm.Label1.LinkMode = 0
Screen.MousePointer = 0
End Sub
4) ÔÚForm_Click()ÖбàдÖ÷³ÌÐò£»
Sub Form_Click()
fname = "C:\TEST\TEST.EXE"
icontle = "ͼ±ê±êÌâ"
iconpath = "C:\TEST\TEST.ICO" + ",0"
'½¨Á¢Í¼±ê
CreateProgManGroup Form1, "ÎҵijÌÐò×é", "TEST.GRP"
CreateProgManItem Form1, fname, icontle, iconpath
End Sub
¡õ ÌÖÑáÁËǧ±àÒ»ÂɵľØÐδ°Ì壬ÈçºÎ½¨Á¢Ò»¸ö²»¹æÔòÐÎ×´µÄ´°Ì壿
Windows APIº¯ÊýSetWindowRgn»áÈÃÄãµÃµ½ÂúÒâµÄ´ð¸´£¬ÏÂÃæµÄ³ÌÐòÏÔʾһ¸öÍÖÔ²ÐεĴ°Ì壬³ÌÐòʵÏÖÈçÏ£º
Private Declare Function CreateEllipticRgn Lib "gdi32" _
(ByVal X1 As Long, ByVal Y1 As Long, _
ByVal X2 As Long, ByVal Y2 As Long) As Long
Private Declare Function SetWindowRgn Lib "user32" _
(ByVal hWnd As Long, ByVal hRgn As Long, ByVal bRedraw As Boolean) As Long
Private Sub Form_Load()
SetWindowRgn hWnd, CreateEllipticRgn(100, 100, 320, 200), True
Me.Show
End Sub
¡õ °²×°Èí¼þµÄʱºò×ÜÓÐÓÉÀ¶µ½ºÚ½¥±äµÄ±³¾°£¬ÊÇÈçºÎʵÏֵģ¿
Æäʵ¾ÍÊÇÓÉÉϵ½Ï»½¥±äÑÕÉ«µÄÏߣ¬³ÌÐòÈçÏ£º
Private Sub DrawBackGround()
Const intBLUESTART% = 255
Const intBLUEEND% = 0
Const intBANDHEIGHT% = 2
Const intSHADOWSTART% = 8
Const intSHADOWCOLOR% = 0
Const intTEXTSTART% = 4
Const intTEXTCOLOR% = 15
Dim sngBlueCur As Single
Dim sngBlueStep As Single
Dim intFormHeight As Integer
Dim intFormWidth As Integer
Dim intY As Integer
intFormHeight = ScaleHeight
intFormWidth = ScaleWidth
sngBlueStep = intBANDHEIGHT * (intBLUEEND - intBLUESTART) / intFormHeight
sngBlueCur = intBLUESTART
For intY = 0 To intFormHeight Step intBANDHEIGHT
Line (-1, intY - 1)-(intFormWidth, intY + intBANDHEIGHT), _
RGB(0, 0, sngBlueCur), BF
sngBlueCur = sngBlueCur + sngBlueStep
Next intY
End Sub
Private Sub Form_Activate()
DrawBackGround
End Sub
¡õ µ±ÓÃShellÔËÐбðµÄÈí¼þʱºò£¬ÎÒÏëµÈ¸Ã³ÌÐò½áÊøÔÙ¼ÌÐøÎҵijÌÐòÓï¾ä£¬ÄÜ×öµÃµ½Â𣿡¡
µ±ÓÃShellº¯Êýµ÷ÓÃÍⲿÈí¼þʱ£¬VB×Ü»áÔÚShellÖ´Ðк󣬼ÌÐøÖ´ÐÐÏÂÃæµÄ³ÌÐò´úÂë£
¶øÎÒÃÇÎÞ·¨È·¶¨ÍⲿÈí¼þʲôʱºòµ÷ÓýáÊø¡£ÎÒÃÇ¿ÉÒÔͨ¹ýWindows APIµÄOpenProcess
ºÍCloseHandleº¯ÊýÀ´ÊµÏÖ¶Ô±»µ÷ÓÃÈí¼þµÄ¼ì²â£º
1) ÔÚVBÖÐн¨Ò»¸ö±ê×¼EXE¹¤³Ì£»
2) ÔÚForm1ÖÐÉùÃ÷OpenProcessºÍ CloseHandle ÕâÁ½¸öWindows API º¯Êý£»
Private Declare Function OpenProcess Lib "kernel32" _
(ByVal dwDesiredAccess As Long, ByVal bInheritHandle As Long, _
ByVal dwProcessId As Long) As Long
Private Declare Function CloseHandle Lib "kernel32" _
(ByVal hObject As Long) As Long
3) È»ºó±àдÏÂÃæµÄº¯Êý:
Function IsRunning(ByVal ProgramID) As Boolean ' ´«Èë½ø³Ì±êʶID
Dim hProgram As Long '±»¼ì²âµÄ³ÌÐò½ø³Ì¾ä±ú
hProgram = OpenProcess(0, False, ProgramID)
If Not hProgram = 0 Then
IsRunning = True
Else
IsRunning = False
End If
CloseHandle hProgram
End Function
4) ÔÚForm_Click()ÖмÓÈë´úÂ룺
Sub Form_Click()
Dim X
Me.Caption = "¿ªÊ¼ÔËÐÐ"
X = Shell("NotePad.EXE", 1)
While IsRunning(X)
DoEvents
Wend
Me.Caption = "½áÊøÔËÐÐ"
End Sub
¡õ ÈçºÎ»ñµÃµ±Ç°µÄWindowsĿ¼ºÍSystem×ÓĿ¼£¿
Windows APIº¯ÊýGetWindowsDirectory()£¬ÓÃÓÚ¶ÁÈ¡µ±Ç°WindowsĿ¼¡£
Declare Function GetWindowsDirectory Lib "kernel32" Alias _
"GetWindowsDirectoryA" (ByVal lpBuffer As String, _
ByVal nSize As Long) As Long
Function GetWindowsDir() As String
Dim strBuf As String
strBuf = Space(80) '×î´ó³¤¶È
If GetWindowsDirectory(strBuf, 80) > 0 Then
GetWindowsDir = UCase$(strBuf)
End If
End Function (´ýÐø)
--
¡ù À´Ô´:£®×Ï ¶¡ Ïã bbs.hit.edu.cn£®[FROM: 202.118.228.152]
Powered by KBS BBS 2.0 (http://dev.kcn.cn)
Ò³ÃæÖ´ÐÐʱ¼ä£º2.576ºÁÃë