lang_tu

New Member

Download miễn phí Ebook Nghiên cứu Windows API





7. BrowseCallbackProc
- Khai báo :
Public Function BrowseCallbackProc (ByVal hwnd As Long, ByVal uMsg As Long, ByVal
lParam As Long, ByVal lpData As Long) As Long
‘ Đoạn mã xác định ứng dụng đặt tại đây
End Function
- Các tham số:
• hwnd: handle của cửa duyệt thưmục của hộp thoại Folder đang gọi hàm này.
Handle này dùng đểgiửcác thông điệp cho hộp thoại.
• uMsg: một trong các cờdưới đây xác định các sựkiện
ƒ BFFM_INITIALIZED: hộp thoại hoàn tất khởi tạo, lParam = 0
ƒ BFFM_SELCHANGED: người dùng đã thay đổi lựa chọn hiện thời, lParam là
một PIDL đến lựa chọn hiện thời.
ƒ BFFM_VALIDATEFAILED: từIntenet Explorer 4.0 trở đi : thông báo rằng
người dùng nhập một đường dẫn sai vào hộp soạn thảo. lParam là một con
trỏtrỏtới một chuỗi (kết thúc bằng ký tựNULL) chứa tên đường dẫn sai này.
• lParam: phụthuộc vào giá trịuMsg .
• lpData: giá trịdo ứng dụng định nghĩa được trong cấu trúc BROWSEINFO dùng
đểtạo hộp thoại.



Để tải bản Đầy Đủ của tài liệu, xin Trả lời bài viết này, Mods sẽ gửi Link download cho bạn sớm nhất qua hòm tin nhắn.
Ai cần download tài liệu gì mà không tìm thấy ở đây, thì đăng yêu cầu down tại đây nhé:
Nhận download tài liệu miễn phí

Tóm tắt nội dung tài liệu:

) As Long
- Các tham số
• hWnd : Cán (handles) của cửa sổ làm căn cứ xác định toạ độ.
• lpPoint : Là biến cấu trúc kiểu POINTAPI chứa toạ độ cửa sổ chuyển đổi. Nếu
hàm thực hiện thành công thì nó sẽ copy toạ độ của màn hình mới vào trong cấu
trúc này.
- Mô tả : Chuyển toạ độ theo cửa sổ sang toạ độ theo màn hình.
- Các hàm liên quan : ScreenToClient
- Các ví dụ minh hoạ :
+ Ví dụ 1 : Move Cursor
'This project needs 2 Buttons
Private Type POINTAPI
x As Long
y As Long
End Type
Private Declare Function ClientToScreen Lib "user32" (ByVal hwnd As Long, lpPoint As
Nghiên cứu Windows API
Nguyễn Nam Trung Trang 35
POINTAPI) As Long
Private Declare Function SetCursorPos Lib "user32" (ByVal x As Long, ByVal y As Long) As Long
Private Declare Function GetDeviceCaps Lib "gdi32" (ByVal hdc As Long, ByVal nIndex As Long)
As Long
Dim P As POINTAPI
Private Sub Form_Load()
'KPD-Team 1998
'URL:
'E-Mail: [email protected]
Command1.Caption = "Screen Middle"
Command2.Caption = "Form Middle"
'API uses pixels
Me.ScaleMode = vbPixels
End Sub
Private Sub Command1_Click()
'Get information about the screen's width
P.x = GetDeviceCaps(Form1.hdc, 8) / 2
'Get information about the screen's height
P.y = GetDeviceCaps(Form1.hdc, 10) / 2
'Set the mouse cursor to the middle of the screen
ret& = SetCursorPos(P.x, P.y)
End Sub
Private Sub Command2_Click()
P.x = 0
P.y = 0
'Get information about the form's left and top
ret& = ClientToScreen&(Form1.hwnd, P)
P.x = P.x + Me.ScaleWidth / 2
P.y = P.y + Me.ScaleHeight / 2
'Set the cursor to the middle of the form
ret& = SetCursorPos&(P.x, P.y)
End Sub
+ Ví dụ 2 : ClipCursor
Private Type RECT
left As Long
top As Long
right As Long
bottom As Long
End Type
Private Type POINT
x As Long
y As Long
End Type
Private Declare Sub ClipCursor Lib "user32" (lpRect As Any)
Private Declare Sub GetClientRect Lib "user32" (ByVal hWnd As Long, lpRect As RECT)
Private Declare Sub ClientToScreen Lib "user32" (ByVal hWnd As Long, lpPoint As POINT)
Nghiên cứu Windows API
Nguyễn Nam Trung Trang 36
Private Declare Sub OffsetRect Lib "user32" (lpRect As RECT, ByVal x As Long, ByVal y As Long)
Private Sub Form_Load()
'KPD-Team 1999
'URL:
'E-Mail: [email protected]
Command1.Caption = "Limit Cursor Movement"
Command2.Caption = "Release Limit"
End Sub
Private Sub Command1_Click()
'Limits the Cursor movement to within the form.
Dim client As RECT
Dim upperleft As POINT
'Get information about our wndow
GetClientRect Me.hWnd, client
upperleft.x = client.left
upperleft.y = client.top
'Convert window coördinates to screen coördinates
ClientToScreen Me.hWnd, upperleft
'move our rectangle
OffsetRect client, upperleft.x, upperleft.y
'limit the cursor movement
ClipCursor client
End Sub
Private Sub Command2_Click()
'Releases the cursor limits
ClipCursor ByVal 0&
End Sub
Private Sub Form_Unload(Cancel As Integer)
'Releases the cursor limits
ClipCursor ByVal 0&
End Sub
+ Ví dụ 3 : Window Placement
Private Const SW_MINIMIZE = 6
Private Type POINTAPI
x As Long
y As Long
End Type
Private Type RECT
Left As Long
Top As Long
Right As Long
Bottom As Long
End Type
Private Type WINDOWPLACEMENT
Length As Long
Nghiên cứu Windows API
Nguyễn Nam Trung Trang 37
flags As Long
showCmd As Long
ptMinPosition As POINTAPI
ptMaxPosition As POINTAPI
rcNormalPosition As RECT
End Type
Private Declare Function ClientToScreen Lib "user32" (ByVal hwnd As Long, lpPoint As
POINTAPI) As Long
Private Declare Function GetWindowPlacement Lib "user32" (ByVal hwnd As Long, lpwndpl As
WINDOWPLACEMENT) As Long
Private Declare Function SetWindowPlacement Lib "user32" (ByVal hwnd As Long, lpwndpl As
WINDOWPLACEMENT) As Long
Dim Rectan As RECT
Private Sub Form_Load()
'Tip submitted by pyp99 ([email protected])
Dim WinEst As WINDOWPLACEMENT
Dim rtn As Long
WinEst.Length = Len(WinEst)
'get the current window placement
rtn = GetWindowPlacement(Me.hwnd, WinEst)
Rectan = WinEst.rcNormalPosition
End Sub
Private Sub Command1_Click()
Dim WinEst As WINDOWPLACEMENT
Dim Punto As POINTAPI
Dim rtn As Long
'set the new min/max positions
Punto.x = 100
Punto.y = 100
'initialize the structure
WinEst.Length = Len(WinEst)
WinEst.showCmd = SW_MINIMIZE
WinEst.ptMinPosition = Punto
WinEst.ptMaxPosition = Punto
WinEst.rcNormalPosition = Rectan
'set the new window placement (minimized)
rtn = SetWindowPlacement(Me.hwnd, WinEst)
End Sub
12. CloseWindow
- Thư viện : user32.dll
- Hệ điều hành : Windows NT 3.1 or later; Windows 95 or later
- Khai báo :
Declare Function CloseWindow Lib "user32" Alias "CloseWindow" (ByVal hwnd As Long)
As Long
- Các tham số
• hWnd : Cán ( handles ) của cửa sổ cần thu nhỏ.
- Mô tả : Thu nhỏ cửa sổ .
Nghiên cứu Windows API
Nguyễn Nam Trung Trang 38
- Các hàm liên quan : ShowWindow
- Các ví dụ minh hoạ : CloseWindow
Private Declare Function CloseWindow Lib "user32" (ByVal hwnd As Long) As Long
Private Sub Form_Load()
'KPD-Team 2000
'URL:
'E-Mail: [email protected]
'Minimize this Window
CloseWindow Me.hwnd
End Sub
13. CommDlgExtendedError
- Thư viện : comdlg32.dll
- Hệ điều hành : Windows NT 3.1 or later; Windows 95 or later
- Khai báo :
Public Declare Function CommDlgExtendedError Lib "comdlg32.dll" Alias
"CommDlgExtendedError" () As Long
- Mô tả : Hàm CommDlgExtendedError trả về mã lỗi từ chức năng cuối cùng của một
hộp thoại common dialog nào đó. Hàm không trả về mã lổi cho bất kỳ hàm API nào
khác ( trong trường hợp này, dùng GetLastError để thay thế ). Giá trị trả về của hàm
không được xác định nếu chức năng được gọi sau cùng của hộp thoại common dialog
thành công. Nếu có một lỗi xảy ra với chức năng này, giá trị trả về chính xác là một
trong những cờ lỗi của hộp thoại common dialog sau đây :
CDERR_DIALOGFAILURE = &HFFFF
Không thể mở hộp thoại.
CDERR_FINDRESFAILURE = &H6
Thất bại khi muốn tìm tqì nguyên cần thiết.
CDERR_GENERALCODES = &H0
Lỗi liên quan đến một thuộc tính tổng quát của hộp thoại common.
CDERR_INITIALIZATION = &H2
Thất bại trong suốt quá trình khởi tạo (thường là bộ nhớ không đủ).
CDERR_LOADRESFAILURE = &H7
Thất bại khi nạp tài nguyên yêu cầu.
CDERR_LOADSTRFAILURE = &H5
Thất bại khi nạp chuỗi yêu cầu.
CDERR_LOCKRESFAILURE = &H8
Thất bại khi khoá tài nguyên yêu cầu.
CDERR_MEMALLOCFAILURE = &H9
Thất bại khi xác định khối bộ nhớ.
CDERR_MEMLOCKFAILURE = &HA
Thất bại khi khoá bộ nhớ yêu cầu.
CDERR_NOHINSTANCE = &H4
Không đượng cung cấp một handles hợp lệ ( nếu handles được yêu cầu ).
CDERR_NOHOOK = &HB
Không được cung cấp một handles tới hàm hook hợp lệ ( nếu handles
được yêu cầu ).
CDERR_NOTEMPLATE = &H3
Không được cung cấp màu ban đầu hợp lệ ( nếu màu được yêu cầu ).
Nghiên cứu Windows API
Nguyễn Nam Trung Trang 39
CDERR_REGISTERMSGFAIL = &HC
Không thể đăng ký một thông điệp cửa sổ thành công.
CDERR_STRUCTSIZE = &H1
Được cung cấp một kích thước cấu trúc không hợp lệ.
CFERR_CHOOSEFONTCODES = &H2000
Lỗi liên quan đến hộp thoại Choose Font.
CFERR_MAXLESSTHANMIN = &H2002
Được cung cấp giá trị kích thước font lớn nhất nhỏ hơn kích thước font
nhỏ nhất đã được cung cấp.
CFERR_NOFONTS = &H2001
Không thể tìm thấy các font đang tồn tại.
FNERR_BUFFERTOOSMALL = &H3003
Được cung cấp một bộ đệm tên tập tin quá nhỏ.
FNERR_FILENAMECODES = &H3000
Lỗi liên quan đến hộp thoại Open File hay Save File.
FNERR_INVALIDFILENAME = &H3002
Được cung cấp hay nhận một tên tập tin không hợp lệ.
FNERR_SUBCLASSFAILURE = &H3001
Không đủ bộ nhớ để phân lớp hộp danh sách.
FRERR_BUFFERLENGTHZERO = &H4001
Được cung cấp một bộ đệm không hợp lệ.
FRERR_FINDREPLACECODES = &H4000
Lỗi liên quan đến hộp thoại Find hay Replace.
PDERR_CREATEICFAILURE = &H100A
Không thẩ tạo một ngữ cảnh thông tin.
PDERR_DEFAULTDIFFERENT = &H100C
...
 
Top