Você está na página 1de 13

Hm API v windows c t t c 41 hm, sau y ti xin trnh by m t s hm (theo th t ABC) cc B n tham kh o. V t c h n nn ch xin trnh by tr c m t vi hm API thi, cc bi sau s ti p t c cc hm khc.

P/S: ti l c d ch (...hc...v Anh vn cng khng t t) nn c o n ti B n b qua v gp ! +------------------------------------------------------------+ Hm AnimateWindow Hm AnimateWindow cho php B n th c hi n cc hi u ng c bi t khi m ho c ng m t c a s hi u ng l : roll, slide, v hi u ng pha tr n (alpha-blended fade). Yu c u: Windows 2000, Windows 98 tr ln. Dec: Declare Function AnimateWindow Lib "user32" (ByVal hwnd As Long, ByVal dwTime As Long, ByVal dwFlags As Long) As Boolean Tham s : ng d ng. C 3 ki u nguyn vn ch c d hi u hn, mong cc

hwnd [in] Handle c a s c n t o hi u ng v vi c g i hi u ng ph i

trong chnh c a s ny.

dwTime [in] Xc nh th i gian th c hi n hi u ng (b ng mili giy). Thng th ng l 200. dwFlags [in] Xc nh ki u hi u ng. Tham s ny c th g m m t hay nhi u gi tr sau: AW_SLIDE S d ng hi u ng slide. M c

nh hi u ng roll s

c s d ng. Gi tr ny s

c b qua n u s d ng AW_CENTER.

AW_ACTIVATE Kch ho t window. Khng dng gi tr ny cng v i AW_HIDE. AW_BLEND S d ng hi u ng fade. Gi tr ny c dng ch khi hwnd l top-level window. AW_HIDE n window. M c

nh l c a s

c show.

AW_CENTER T o window xu t hi n v i hi u ng thu v n t ng m nh nh vo trong n u AW_HIDE c dng ho c m r ng ra ngoi n u khng dng AW_HIDE. AW_HOR_POSITIVE T o hi u ng ho t hnh cho window t tri sang ph i. Gi tr ny c th b qua khi s d ng v i AW_CENTER ho c AW_BLEND. AW_HOR_NEGATIVE Tng t nh AW_HOR_POSITIVE nhng t ph i sang tri. AW_VER_POSITIVE Tng t nh AW_HOR_POSITIVE nhng t trn xu ng d i.

c dng v i hi u ng roll ho c slide v n b

AW_VER_NEGATIVE Tng t nh AW_VER_NEGATIVE nhng t d i ln trn.

Gi tr tr v : N u thnh cng gi tr khc khng (nonzero) s c tr v v ng c l i. Hm s th c hi n khng thnh cng trong cc tr ng h p sau: {/i} C a s s d ng window region; ho c visible v B n ang c g ng show n ln; ho c window hidden v B n ang hide n m t l n n a. c thm thng tin v cc l i hy g i hm GetLastError.{/i} V d v i VB6: Const AW_HOR_POSITIVE = &H1 Const AW_HOR_NEGATIVE = &H2 Const AW_VER_POSITIVE = &H4 Const AW_VER_NEGATIVE = &H8 Const AW_CENTER = &H10 Const AW_HIDE = &H10000 Const AW_ACTIVATE = &H20000 Const AW_SLIDE = &H40000 Const AW_BLEND = &H80000 Private Declare Function AnimateWindow Lib "user32" (ByVal hwnd As Long, ByVal dwTime As Long, ByVal dwFlags As Long) As Boolean Private Sub Form_Load() 'Set the graphic mode to persistent Me.AutoRedraw = True Me.Print "Unload me" End Sub Private Sub Form_Unload(Cancel As Integer) 'Animate the window AnimateWindow Me.hwnd, 200, AW_VER_POSITIVE Or AW_HOR_NEGATIVE Or AW_HIDE 'Unload our form completely Set Form1 = Nothing End Sub

Hm BeginDeferWindowPos Hm BeginDeferWindowPos s c p pht b nh cho m t multiple-window- position structure v l y handle tr v structure . Yu c u: Windows NT 3.1, Windows 95 Dec: Declare Function BeginDeferWindowPos Lib "user32" Alias "BeginDeferWindowPos" (ByVal nNumWindows As Long) As Long Tham s : nNumWindows Xc nh initial number c a windows dng th c c a structure, n u c n.

lu tr tng tin v position. Hm DeferWindowPos lm tng thm kch

Gi tr tr v : N u thnh cng, gi tr tr v s xc nh the multiple-window - position structure. N u khng c p pht, gi tr NULL s c tr v . V d b ng VB6:

ti nguyn h th ng

Const WS_BORDER = &H800000 Const WS_DLGFRAME = &H400000 Const WS_THICKFRAME = &H40000 Const WS_CAPTION = &HC00000 ' WS_BORDER Or WS_DLGFRAME Const HWND_BOTTOM = 1 Const HWND_TOP = 0 Const HWND_TOPMOST = -1 Const HWND_NOTOPMOST = -2 Const SWP_SHOWWINDOW = &H40 Private Type RECT Left As Long Top As Long Right As Long Bottom As Long End Type Private Declare Function AdjustWindowRect Lib "user32" (lpRect As RECT, ByVal dwStyle As Long, ByVal bMenu As Long) As Long Private Declare Function BeginDeferWindowPos Lib "user32" (ByVal nNumWindows As Long) As Long Private Declare Function DeferWindowPos Lib "user32" (ByVal hWinPosInfo As Long, ByVal hwnd As Long, ByVal hWndInsertAfter As Long, ByVal x As Long, ByVal y As Long, ByVal cx As Long, ByVal cy As Long, ByVal wFlags As Long) As Long Private Declare Function EndDeferWindowPos Lib "user32" (ByVal hWinPosInfo As Long) As Long Private Sub Form_Load() Dim R As RECT, hDWP As Long R.Left = 30 R.Top = 30 R.Bottom = 200 R.Right = 120 AdjustWindowRect R, WS_THICKFRAME Or WS_CAPTION, False hDWP = BeginDeferWindowPos(1) DeferWindowPos hDWP, Me.hwnd, HWND_TOP, R.Left, R.Top, R.Right - R.Left, R.Bottom - R.Top, SWP_SHOWWINDOW EndDeferWindowPos hDWP End Sub {/code} --------------------------Hm DeferWindowPos Hm DeferWindowPos c p nh t multiple-window-position structure c xc nh tr c cho m t c a s c ch nh. Hm ny sau s tr v handle c a structure c update. Hm EndDeferWindowPos s d ng cc thng tin trong structure ny thay i ng th i v tr (position) v kch th c (size) c a c a s . Hm BeginDeferWindowPos s t o structure ny. Yu c u: Windows NT 3.1, Windows 95 tr ln. Dec: Declare Function DeferWindowPos Lib "user32" Alias "DeferWindowPos" (ByVal hWinPosInfo As Long, ByVal hwnd As Long, ByVal hWndInsertAfter As Long, ByVal x As Long, ByVal y As Long, ByVal cx As Long, ByVal cy As Long, ByVal wFlags As Long) As Long

Tham s : hWinPosInfo Xc nh m t multiple-window - position structure ch a thng tin v kch th c v v tr c a m t ho c nhi u windows. Structure ny c tr v b i hm BeginDeferWindowPos ho c v a m i g i b ng hm DeferWindowPos. hWnd Xc nh window c lu tr trong structure c update thng tin. hWndInsertAfter Identifies the window that precedes the positioned window in the Z order. Tham s ny ph i l m t handle c a s ho c m t trong cc gi tr sau: HWND_BOTTOM t window xu ng y (bottom) c a Z order. N u tham s hWnd xc nh m t window m t v tr v c thay th vo v tr bottom c a t t c cc windows khc. HWND_NOTOPMOST t window trn t t c cc non-topmost windows ( i u ny c ngha l ny s khng c tc d ng n u window l m t non-topmost window. HWND_TOP t window vo v tr cao nh t c a Z order. HWND_TOPMOST t window trn t t c non-topmost windows. Window s gi v tr topmost ny c a n ngay c khi n b deactive. Tham s ny s b b qua n u SWP_NOZORDER c thi t l p trong tham s uFlags. x Xc y Xc cx Xc cy Xc

v tr cao nh t th window s

ng sau t t c cc topmost windows). Gi tr

nh x-coordinate c a gc tri bn trn c a c a s .

nh y-coordinate c a gc tri bn trn c a c a s .

nh b r ng m i c a window, b ng pixels.

nh chi u cao m i c a window, b ng pixels.

uFlags Xc nh m t s k t h p c a cc gi tr sau v s tc

ng

n kch th c v v tr c a window:

SWP_DRAWFRAME V m t frame ( c nh ngha trong ph n m t class c a window) xung quanh window. SWP_FRAMECHANGED G i thng i p WM_NCCALCSIZE n window, ngay c trong tr ng h p khi kch th c c a window khng b thay i. N u tham s ny khng c xc nh, WM_NCCALCSIZE s ch c g i khi kch th c c a window b thay i. SWP_HIDEWINDOW Hides the window. SWP_NOACTIVATE Khng kch ho t (activate) window. N u tham s ny khng c thi t l p, window s c kch ho t v c chuy n ln thnh top c a cc topmost ho c non-topmost group khc (ty thu c v thi t l p c a hWndInsertAfter parameter). SWP_NOCOPYBITS

Discards the entire contents of the client area. N u tham s ny not specified, contents h p l c a cc client area s c lu tr v d c copy vo trong client area sau khi window b thay i kch th c ho c v tr. SWP_NOMOVE Gi l i v tr hi n t i (b qua tham s X v Y). SWP_NOOWNERZORDER Khng thay i v tr c a chnh window trong Z order. SWP_NOREDRAW Khng redraw l i cc thay i. N u tham s ny khng c set, no repainting of any kind occurs. i u ny tc ng n client area, cc nonclient area (bao g m c title bar v scroll bars), v b t k ph n no c a parent window uncovered nh k t qu tc ng khi window c moved. Khi tham s ny c thi t l p, ng d ng ph i c explicitly invalidate ho c redraw any parts of the window and parent window c n c redrawing. SWP_NOREPOSITION Tng t nh SWP_NOOWNERZORDER. SWP_NOSENDCHANGING Ngn ng a window nh n thng i p WM_WINDOWPOSCHANGING. SWP_NOSIZE Lu gi l i kch th c hi n t i (b qua tham s cx v cy). SWP_NOZORDER Lu gi l i Z order hi n t i (b qua tham s hWndInsertAfter). SWP_SHOWWINDOW Displays the window. Gi tr tr v : Gi tr tr v xc nh multiple-window - position structure c cph nh t. Th handle c tr v b ng hm ny c th khc v i th handle g i n n. Th handle m i m hm ny tr v s c dng trong l n g i ti p theo n hm DeferWindowPos ho c hm EndDeferWindowPos. N u ti nguyn h th ng khng cn th c hi n, gi tr tr v s l NULL. V d VB6 Const WS_BORDER = &H800000 Const WS_DLGFRAME = &H400000 Const WS_THICKFRAME = &H40000 Const WS_CAPTION = &HC00000 ' WS_BORDER Or WS_DLGFRAME Const HWND_BOTTOM = 1 Const HWND_TOP = 0 Const HWND_TOPMOST = -1 Const HWND_NOTOPMOST = -2 Const SWP_SHOWWINDOW = &H40 Private Type RECT Left As Long Top As Long Right As Long Bottom As Long End Type Private Declare Function AdjustWindowRect Lib "user32" (lpRect As RECT, ByVal dwStyle As Long, ByVal bMenu As Long) As Long Private Declare Function BeginDeferWindowPos Lib "user32" (ByVal nNumWindows As Long) As Long Private Declare Function DeferWindowPos Lib "user32" (ByVal hWinPosInfo As Long, ByVal hwnd As Long, ByVal hWndInsertAfter As Long, ByVal x As Long, ByVal y As Long, ByVal cx As Long, ByVal cy As Long, ByVal wFlags As Long) As Long Private Declare Function EndDeferWindowPos Lib "user32" (ByVal hWinPosInfo As Long) As Long Private Sub Form_Load() Dim R As RECT, hDWP As Long R.Left = 30 R.Top = 30

R.Bottom = 200 R.Right = 120 AdjustWindowRect R, WS_THICKFRAME Or WS_CAPTION, False hDWP = BeginDeferWindowPos(1) DeferWindowPos hDWP, Me.hwnd, HWND_TOP, R.Left, R.Top, R.Right - R.Left, R.Bottom - R.Top, SWP_SHOWWINDOW EndDeferWindowPos hDWP End Sub Hm CloseWindow

Hm CloseWindow s thu nh nhng khng destroy c a s Yu c u: Windows NT 3.1, Windows 95 tr ln.

c xc

nh.

Dec: Declare Function CloseWindow Lib "user32" Alias "CloseWindow" (ByVal hwnd As Long) As Long Tham s : hWnd handle c a s c n thu nh .

Gi tr tr v : Nonzero: n u thnh cng, v zero n u ng c l i. G i hm GetLastError c thm thng tin l i. V d VB6 Private Declare Function CloseWindow Lib "user32" (ByVal hwnd As Long) As Long Private Sub Form_Load() CloseWindow Me.hwnd End Sub Hm EnableWindow Hm EnableWindow s enables ho c disables cc tc ng c a mouse v keyboard ln window ho c control xc nh. Khi disabled, window s khng nh n b t k tc ng no nh click chu t ho c nh n phm, v khi enabled th ng c l i. Yu c u: Windows NT 3.1; Windows 95 tr ln.

Dec: Declare Function EnableWindow Lib "user32" Alias "EnableWindow" (ByVal hwnd As Long, ByVal fEnable As Long) As Long Tham s : hWnd

Xc

nh window s

c enabled ho c disabled.

bEnable N u tham s ny l TRUE th window s enabled v ng c l i. Gi tr tr v : nonzero n u th c hi n thnh cng, zero: khng. G i hm GetLastError V d VB6
{i}'This project needs two command buttons{/i}

bi t chi ti t l i.

Private Declare Function IsWindowEnabled Lib "user32" (ByVal hwnd As Long) As Long Private Declare Function EnableWindow Lib "user32" (ByVal hwnd As Long, ByVal fEnable As Long) As Long Private Sub Command2_Click() ' Reverse the enabled status of Command1. If the window is ' disabled, enable it; if it is enabled, disable it. Dim wasenabled As Long ' receives enabled/disabled status of Command1 Dim retval As Long ' return value ' Determine if the window Command1 is currently enabled or not. wasenabled = IsWindowEnabled(Command1.hwnd) If wasenabled = 0 Then ' if not enabled, enable it retval = EnableWindow(Command1.hwnd, 1) Else ' if enabled, disable it retval = EnableWindow(Command1.hwnd, 0) End If End Sub ///////////////////////////////

Hm EndDeferWindowPos Hm EndDeferWindowPos function s update ng th i v tr v kch th c c a 1 ho c nhi u window c a chu k n screen-refreshing. Cc hm lin quan: BeginDeferWindowPos, DeferWindowPos Yu c u: Windows NT 3.1; Windows 95 tr ln.

Dec: Declare Function EndDeferWindowPos Lib "user32" Alias "EndDeferWindowPos" (ByVal hWinPosInfo As Long) As Long Tham s : hWinPosInfo Xc nh multiple-window - position structure c ch a thng tin v kch th c v v tr c a 1 ho c nhi u window. C u trc n i t i ny s c tr v b i hm BeginDeferWindowPos ho c b i h u h t cc l nh v a g i n hm DeferWindowPos. Gi tr tr v : nonzero n u th c hi n thnh cng, zero: khng. G i hm GetLastError V d VB6
Const WS_BORDER = &H800000 Const WS_DLGFRAME = &H400000 Const WS_THICKFRAME = &H40000 Const WS_CAPTION = &HC00000 ' WS_BORDER Or WS_DLGFRAME Const HWND_BOTTOM = 1 Const HWND_TOP = 0 Const HWND_TOPMOST = -1 Const HWND_NOTOPMOST = -2 Const SWP_SHOWWINDOW = &H40 Private Type RECT Left As Long Top As Long Right As Long Bottom As Long End Type Private Declare Function AdjustWindowRect Lib "user32" (lpRect As RECT, ByVal dwStyle As Long, ByVal bMenu As Long) As Long Private Declare Function BeginDeferWindowPos Lib "user32" (ByVal nNumWindows As Long) As Long Private Declare Function DeferWindowPos Lib "user32" (ByVal hWinPosInfo As Long, ByVal hwnd As Long, ByVal hWndInsertAfter As Long, ByVal x As Long, ByVal y As Long, ByVal cx As Long, ByVal cy As Long, ByVal wFlags As Long) As Long Private Declare Function EndDeferWindowPos Lib "user32" (ByVal hWinPosInfo As Long) As Long

bi t chi ti t l i.

Private Sub Form_Load() Dim R As RECT, hDWP As Long R.Left = 30 R.Top = 30 R.Bottom = 200 R.Right = 120 AdjustWindowRect R, WS_THICKFRAME Or WS_CAPTION, False hDWP = BeginDeferWindowPos(1) DeferWindowPos hDWP, Me.hwnd, HWND_TOP, R.Left, R.Top, R.Right - R.Left, R.Bottom - R.Top, SWP_SHOWWINDOW EndDeferWindowPos hDWP End Sub ///////////////////////////////

Hm EnumChildWindows Hm EnumChildWindows s li t k cc windows con tr c thu c window cha c xc nh b ng cch g i m t handle n m i window con, in turn, to an application-defined callback function. EnumChildWindows continues until the last child window is enumerated or the callback function returns FALSE. Cc hm lin quan: EnumWindows Yu c u: Windows NT 3.1; Windows 95 tr ln.

Dec: Declare Function EnumChildWindows Lib "user32" Alias "EnumChildWindows" (ByVal hWndParent As Long, ByVal lpEnumFunc As Long, ByVal lParam As Long) As Long Tham s : hWndParent lpEnumFunc lParam Xc

Xc

nh window cha s

c li t k cc window con.

Points to an application-defined callback function. Xem thm hm EnumChildProc. nh gi tr application-defined 32-bit c g i n hm callback.

Gi tr tr v : nonzero n u th c hi n thnh cng, zero: khng. G i hm GetLastError V d VB6

bi t chi ti t l i.

{i}'in a form{/i} Private Sub Form_Load() Me.AutoRedraw = True EnumChildWindows GetDesktopWindow, AddressOf EnumChildProc, ByVal 0& End Sub 'in a module Declare Function GetDesktopWindow Lib "user32" () As Long Declare Function EnumChildWindows Lib "user32" (ByVal hWndParent As Long, ByVal lpEnumFunc As Long, ByVal lParam As Long) As Long Declare Function GetWindowText Lib "user32" Alias "GetWindowTextA" (ByVal hwnd As Long, ByVal lpString As String, ByVal cch As Long) As Long Declare Function GetWindowTextLength Lib "user32" Alias "GetWindowTextLengthA" (ByVal hwnd As Long) As Long Public Function EnumChildProc(ByVal hwnd As Long, ByVal lParam As Long) As Long Dim sSave As String 'Get the windowtext length sSave = Space$(GetWindowTextLength(hwnd) + 1) 'get the window text GetWindowText hwnd, sSave, Len(sSave) 'remove the last Chr$(0) sSave = Left$(sSave, Len(sSave) - 1) If sSave <> "" Then Form1.Print sSave

'continue enumeration EnumChildProc = 1 End Function ///////////////////////////////

Hm FlashWindow Hm FlashWindow dng flash window c ch ra. Cc hm lin quan: FlashWindowEx Yu c u: Windows NT 3.1; Windows 95 tr ln.

Dec: Declare Function FlashWindow Lib "user32" Alias "FlashWindow" (ByVal hwnd As Long, ByVal bInvert As Long) As Long Tham s : hWnd

Xc

nh window s

c flash.

bInvert Tr ng thi c a window: s c flash ho c quay v tr ng thi nguyn th y c a n. Window c flash s c chuy n t tr ng thi ny sang tr ng thi khc n u tham s ny c t TRUE. N u l FALSE, window s c quay v tnh tr ng ban u c a n (active ho c inactive). Gi tr tr v : Gi tr tr v s xc nh tnh tr ng c a window khi tr c g i hm FlashWindow. N u window c active tr c khi g i hm ny, gi tr nonzero s c tr v . V d VB6
'This project needs a timer,Interval 1000 'In general section Private Declare Function FlashWindow Lib "user32" (ByVal hwnd As Long, ByVal bInvert As Long) As Long Const Invert = 1 Private Sub Timer1_Timer() 'Flash the window FlashWindow Me.hwnd, Invert End Sub ///////////////////////////////

Hm FlashWindowEx Hm FlashWindowEx s flash window c ch ra c th . Khi dng hm ny, B n c th th i gian m h th ng s hi n th windows, trong khi hm FlashWindow s ch hi n th window m i m t l n. Cc hm lin quan: FlashWindow Yu c u: Windows 2000; Windows 98 tr ln.

Dec: Declare Function FlashWindowEx Lib "user32" (pfwi As FLASHWINFO) As Boolean Tham s : pfwi [in] Con tr tr Gi tr tr v :

n c u trc FLASHWINFO.

Gi tr tr v s xc nh tnh tr ng c a window khi tr c g i hm FlashWindowEx. N u window caption xc c kch ho t tr c khi g i th hm tr v gi tr nonzero, ng c l i l zero. V d VB6

nh

Const FLASHW_STOP = 0 'Stop flashing. The system restores the window to its original state. Const FLASHW_CAPTION = &H1 'Flash the window caption. Const FLASHW_TRAY = &H2 'Flash the taskbar button. Const FLASHW_ALL = (FLASHW_CAPTION Or FLASHW_TRAY) 'Flash both the window caption and taskbar button. This is equivalent to setting the FLASHW_CAPTION Or FLASHW_TRAY flags. Const FLASHW_TIMER = &H4 'Flash continuously, until the FLASHW_STOP flag is set. Const FLASHW_TIMERNOFG = &HC 'Flash continuously until the window comes to the foreground. Private Type FLASHWINFO cbSize As Long hwnd As Long dwFlags As Long uCount As Long dwTimeout As Long End Type Private Declare Function FlashWindowEx Lib "user32" (pfwi As FLASHWINFO) As Boolean Private Sub Form_Load() Dim FlashInfo As FLASHWINFO 'Specifies the size of the structure. FlashInfo.cbSize = Len(FlashInfo) 'Specifies the flash status FlashInfo.dwFlags = FLASHW_ALL Or FLASHW_TIMER 'Specifies the rate, in milliseconds, at which the window will be flashed. 'If dwTimeout is zero, the function uses the default cursor blink rate. FlashInfo.dwTimeout = 0 'Handle to the window to be flashed. The window can be either opened or minimized. FlashInfo.hwnd = Me.hwnd 'Specifies the number of times to flash the window. FlashInfo.uCount = 0 FlashWindowEx FlashInfo End Sub Private Sub Form_Paint() Me.CurrentX = 0 Me.CurrentY = 0 Me.Print "Click me !" End Sub ///////////////////////////////

Hm GetClassInfo Hm GetClassInfo dng l y thng tin v m t window class. Cc hm lin quan: GetClassInfoEx, GetClassName Yu c u: Windows NT 3.1; Windows 95 tr ln.

Dec: Declare Function GetClassInfo Lib "user32" Alias "GetClassInfoA" (ByVal hInstance As Long, ByVal lpClassName As String, lpWndClass As WNDCLASS) As Long Tham s : hInstance Xc nh application t o nn class. l y thng tin v cc class c nh buttons list boxes), hy thi t l p gi tr c a tham s ny v NULL.

nh ngha b i Windows (v

lpClassName Ch n chu i (k t thc b ng null) c ch a class name v ph i c ng k tr c ho c l m t class c ng k tr c b i hm RegisterClass. Tham s c th l m t integer. N u v y, n ph i l m t global c t o b i hm GlobalAddAtom tr c . Gi tr 16-bt (nh hn 0xC000) ph i t t th p (low-order word) c a lpClassName; cn t nh cao ph i ch a zero.

lpWndClass

Tr

n c u trc WNDCLASS s nh n thng tin v class.

Gi tr tr v : N u hm tm th y v copy c d li u trong class, gi tr nonzero c tr v , ng c l i tr v zero. Xem thm l i b ng hm GetLastError. V d VB6


Private Type WNDCLASS style As Long lpfnwndproc As Long cbClsextra As Long cbWndExtra2 As Long hInstance As Long hIcon As Long hCursor As Long hbrBackground As Long lpszMenuName As String lpszClassName As String End Type Private Declare Function GetSysColor Lib "user32" (ByVal nIndex As Long) As Long Private Declare Function GetClassInfo Lib "user32" Alias "GetClassInfoA" (ByVal hInstance As Long, ByVal lpClassName As String, lpWndClass As WNDCLASS) As Long Private Sub Form_Paint() Dim WC As WNDCLASS 'Get class info GetClassInfo ByVal 0&, "BUTTON", WC 'Clear the form Me.Cls 'Print the retrieved information to the form Me.Print "The button's default background is set to color-number:" + Str$(GetSysColor(WC.hbrBackground)) End Sub ///////////////////////////////

Hm GetClassInfoEx Hm GetClassInfoEx nh n thng tin v window class, bao g m c handle c a small icon tch h p v i window class. Cc hm lin quan: GetClassInfo Yu c u: Windows NT 3.1; Windows 95 tr ln.

Dec: Declare Function GetClassInfoEx Lib "user32" Alias "GetClassInfoExA" (ByVal hInstance As Long, ByVal lpClassName As String, lpWndClass As WNDCLASSEX) As Long Tham s : hinst xc nh application t o class . boxes v y), hy t tham s ny gi tr NULL. lpszClass v y. lpwcx Tr

nh n thng tin v cc class c a Windows (v nh buttons hay list

n string (k t thc b ng null) ch a class name. Tham s ny tng t nh trong hm GetClassInfo

Tr

n WNDCLASSEX structure s nh n infor v class.

Gi tr tr v : Nh hm GetClassInfo v y.

V d VB6
Private Type WNDCLASSEX cbSize As Long style As Long lpfnWndProc As Long cbClsExtra As Long cbWndExtra As Long hInstance As Long hIcon As Long hCursor As Long hbrBackground As Long lpszMenuName As String lpszClassName As String hIconSm As Long End Type Private Declare Function DrawIcon Lib "user32" (ByVal hdc As Long, ByVal x As Long, ByVal y As Long, ByVal hIcon As Long) As Long Private Declare Function GetClassInfoEx Lib "user32" Alias "GetClassInfoExA" (ByVal hInstance As Long, ByVal lpClassName As String, lpWndClass As WNDCLASSEX) As Long Private Sub Form_Paint() Dim WCX As WNDCLASSEX 'Set the structure size WCX.cbSize = Len(WCX) 'Get the class info GetClassInfoEx ByVal 0&, "EDIT", WCX 'Clear the screen Me.Cls Me.Print "This is the default cursor for a textbox:" 'Draw the default cursor on the form DrawIcon Me.hdc, 0, 15, WCX.hCursor End Sub ///////////////////////////////

Hm GetClassName Hm GetClassName nh n v name of the class m window ch ra tr c thu c. Cc hm lin quan: None Yu c u: Windows NT 3.1; Windows 95 tr ln.

Dec: Declare Function GetClassName Lib "user32" Alias "GetClassNameA" (ByVal hwnd As Long, ByVal lpClassName As String, ByVal nMaxCount As Long) As Long Tham s : hWnd

Xc

nh window v gin ti p qua xc nb m

nh class m window tr c thu c.

lpClassName Tr

nh n class name string. m m tham s lpClassName tr n. Class name string c c t

nMaxCount Xc nh chi u di, b ng k t , c a b g n n u n di hn b m. Gi tr tr v : N u thnh cng, gi tr tr v l s k t GetLastError. V d VB6

c copy

nb

m, n u khng tr v zero. Xem thm l i b ng hm

Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long Private Declare Function PostMessage Lib "user32" Alias "PostMessageA" (ByVal hwnd As Long, ByVal

wMsg As Long, ByVal wParam As Long, lParam As Any) As Long Private Declare Function GetClassName Lib "user32" Alias "GetClassNameA" (ByVal hwnd As Long, ByVal lpClassName As String, ByVal nMaxCount As Long) As Long Private Declare Function ShowWindow Lib "user32" (ByVal hwnd As Long, ByVal nCmdShow As Long) As Long Const SW_SHOWNORMAL = 1 Const WM_CLOSE = &H10 Const gcClassnameMSWord = "OpusApp" Const gcClassnameMSExcel = "XLMAIN" Const gcClassnameMSIExplorer = "IEFrame" Const gcClassnameMSVBasic = "wndclass_desked_gsk" Const gcClassnameNotePad = "Notepad" Const gcClassnameMyVBApp = "ThunderForm" Private Sub Form_Load() Dim WinWnd As Long, Ret As String, RetVal As Long, lpClassName As String 'Ask for a Window title Ret = InputBox("Enter the exact window title:" + Chr$(13) + Chr$(10) + "Note: must be an exact match") 'Search the window WinWnd = FindWindow(vbNullString, Ret) If WinWnd = 0 Then MsgBox "Couldn't find the window ...": Exit Sub 'Show the window ShowWindow WinWnd, SW_SHOWNORMAL 'Create a buffer lpClassName = Space(256) 'retrieve the class name RetVal = GetClassName(WinWnd, lpClassName, 256) 'Show the classname MsgBox "Classname: " + Left$(lpClassName, RetVal) 'Post a message to the window to close itself PostMessage WinWnd, WM_CLOSE, 0&, 0& End Sub

Você também pode gostar