Windows unappromested function revealed (3)

zhaozj2021-02-11  167

WINDOWS unapproved function revealed

'Obtains its directory pidlPublic Function GetPIDLFromFolderID (hOwner As Long, nFolder As SHSpecialFolderIDs) As LongDim pidl As LongIf SHGetSpecialFolderLocation (hOwner, nFolder, pidl) = NOERROR ThenGetPIDLFromFolderID = pidlEnd IfEnd FunctionPublic Function GetDisplayNameFromPIDL (pidl As according to ID a specific folder object Long) As StringDim sfib As SHFILEINFOBYTEIf SHGetFileInfoPidl (pidl, 0, sfib, Len (sfib), SHGFI_PIDL Or SHGFI_DISPLAYNAME) ThenGetDisplayNameFromPIDL = GetStrFromBufferA (StrConv (sfib.szDisplayName, vbUnicode)) End IfEnd FunctionPublic Function GetPathFromPIDL (pidl As Long) As StringDim sPath As String * MAX_PATHIf SHGetPathFromIDList (pidl, sPath) ThenGetPathFromPIDL = GetStrFromBufferA (sPath) End IfEnd FunctionPublic Function GetStrFromBufferA (sz As String) As StringIf InStr (sz, vbNullChar) ThenGetStrFromBufferA = Left $ (sz, InStr (sz, vbNullChar) - 1) ElsegetstrFromBuffera = Szend IFEND Function Adds code in Mshell.ba: 'MShell.baS function contains registration and anti-registration system notification and folder information conversion function Option ExplicitPrivate m_hshNotify As Long' system message Notification Handle Private m_pidlDesktop As Long 'defined system notification message value Public Const WM_SHNOTIFY = & H401Public Type PIDLSTRUCTpidl As LongbWatchSubFolders As LongEnd TypeDeclare Function SHChangeNotifyRegister Lib "shell32" Alias ​​"# 2" _ (ByVal hWnd As Long, _ByVal uFlags As SHCN_ItemFlags, _ByVal dwEventID As SHCN_EventIDs, _BYVAL UMSG As Long, _Byval Citems As long, _lpps as pidlstruct) AS Longtype ShNotifyStructDwitem1 As longdwitem2 as longend typedeclare function shchangenotifydegegister lib "shell32" alias "#

4 "_ (ByVal hNotify As Long) As BooleanDeclare Sub SHChangeNotify Lib" shell32 "_ (ByVal wEventId As SHCN_EventIDs, ByVal uFlags As SHCN_ItemFlags, _ByVal dwItem1 As Long, _ByVal dwItem2 As Long) Public Enum SHCN_EventIDsSHCNE_RENAMEITEM = & H1SHCNE_CREATE = & H2SHCNE_DELETE = & H4SHCNE_MKDIR = & H8SHCNE_RMDIR = & H10SHCNE_MEDIAINSERTED = & H20SHCNE_MEDIAREMOVED = & H40SHCNE_DRIVEREMOVED = & H80SHCNE_DRIVEADD = & H100SHCNE_NETSHARE = ​​& H200SHCNE_NETUNSHARE = ​​& H400SHCNE_ATTRIBUTES = & H800SHCNE_UPDATEDIR = & H1000SHCNE_UPDATEITEM = & H2000SHCNE_SERVERDISCONNECT = & H4000SHCNE_UPDATEIMAGE = & H8000 & SHCNE_DRIVEADDGUI = & H10000SHCNE_RENAMEFOLDER = & H20000SHCNE_FREESPACE = & H40000SHCNE_ASSOCCHANGED = & H8000000SHCNE_DISKEVENTS = & H2381FSHCNE_GLOBALEVENTS = & HC0581E0SHCNE_ALLEVENTS = & H7FFFFFFFSHCNE_INTERRUPT = & H80000000End Enum # If (WIN32_IE> = & H400) ThenPublic Const shcnee_orderchanged = & h2 # end ifpublic enum shcn_itemflagsshcnf_idlist = & h0shcnf_patha = & h1shcnf_printera = & h2shcnf_dword = & h3shcnf_pathw = & H5SHCNF_PRINTERW = & H6SHCNF_TYPE = & HFFSHCNF_FLUSH = & H1000SHCNF_FLUSHNOWAIT = & H2000 # If UNICODE ThenSHCNF_PATH = SHCNF_PATHWSHCNF_PRINTER = SHCNF_PRINTERW # ElseSHCNF_PATH = SHCNF_PATHASHCNF_PRINTER = SHCNF_PRINTERA #

End IfEnd EnumPublic Function SHNotify_Register (hWnd As Long) As BooleanDim ps As PIDLSTRUCTIf (m_hSHNotify = 0) Thenm_pidlDesktop = GetPIDLFromFolderID (0, CSIDL_DESKTOP) If m_pidlDesktop Thenps.pidl = m_pidlDesktopps.bWatchSubFolders = True 'Windows registration monitor, handle will get to save m_hSHNotify in m_hSHNotify = SHChangeNotifyRegister (hWnd, SHCNF_TYPE Or SHCNF_IDLIST, NE_ALLEVENTS Or SHCNE_INTERRUPT, WM_SHNOTIFY, 1, ps) SHNotify_Register = CBool ​​(m_hSHNotify) ElseCall CoTaskMemFree (m_pidlDesktop) End IfEnd IfEnd FunctionPublic Function SHNotify_Unregister () As BooleanIf m_hSHNotify ThenIf SHChange Notify Deregister (m_h SHNotify) Thenm_hSHNotify = 0Call CoTaskMemFree (m_pidlDesktop) m_pidlDesktop = 0SHNotify_Unregister = TrueEnd IfEnd IfEnd FunctionPublic Function SHNotify_GetEventStr (strPath1, strPath2 As String, dwEventID As Long) As StringDim sEvent As StringSelect Case dwEventIDCase SHCNE_RENAMEITEM: sEvent = "rename file" strPath1 " Create a file file name for " strpath2case shcne_create: sevent =": " STRPATH1CASE SHCNE_DELETE: SE vent = "delete file name:" strPath1Case SHCNE_MKDIR: sEvent = "new directory directory name:" strPath1Case SHCNE_RMDIR: sEvent = "delete directory directory name:" strPath1Case SHCNE_MEDIAINSERTED: sEvent = strPath1 "to insert a removable storage medium "Case SHCNE_MEDIAREMOVED: sEvent = strPath1 " in removing the removable storage medium "Case SHCNE_DRIVEREMOVED: sEvent =" remove drive " strPath1Case SHCNE_DRIVEADD: sEvent =" Add drive " strPath1Case SHCNE_NETSHARE: sEvent =" change directory " strPath1 "Shared Properties" Case Shcne_updatedir: Sevent = "Update Directory" StrPath1 Case Shcne_UPDATEM: SEVENT = "Update file name:"

strPath1Case SHCNE_SERVERDISCONNECT: sEvent = "even disconnect from the server" strPath1 "" strPath2Case SHCNE_UPDATEIMAGE: sEvent = "SHCNE_UPDATEIMAGE" Case SHCNE_DRIVEADDGUI: sEvent = "SHCNE_DRIVEADDGUI" Case SHCNE_RENAMEFOLDER: sEvent = "Rename Folder" strPath1 " is " strPath2Case SHCNE_FREESPACE: sEvent =" change disk space "Case SHCNE_ASSOCCHANGED: sEvent =" change the file associated with "End Select SHNotify_GetEventStr = sEventEnd function Add the following code mSub.Bas: 'mSub function comprises a window message handler Option ExplicitPrivate const WM_NCDESTROY = & H82Private const GWL_WNDPROC = (-4) Private const OLDWNDPROC = "OldWndProc" Private Declare Function GetProp Lib "user32" Alias ​​"GetPropA" (ByVal _hWnd As Long, ByVal lpString As String) As LongPrivate Declare Function SetProp Lib "user32" Alias ​​"SetPropA" (ByVal _hWnd As Long, ByVal lpString As String, ByVal hData As Long) As LongPrivate Declare Function RemoveProp Lib "user32" Alias ​​"RemovePropA" (ByVal _hWnd As Long, ByVal lpString As String) As LongPrivate Declare Function SetWindowLong Lib "User32" Alias ​​"SetWindowlonga "_ (ByVal hWnd As Long, ByVal nIndex As Long, ByVal dwNewLong As Long) As LongPrivate Declare Function CallWindowProc Lib" user32 "Alias" CallWindowProcA "_ (ByVal lpPrevWndFunc As Long, ByVal hWnd As Long, ByVal uMsg As Long, _ByVal wParam As Long, ByVal lParam As Long) As LongPublic Function SubClass (hWnd As Long) As BooleanDim lpfnOld As LongDim fSuccess As BooleanIf (GetProp (hWnd, OLDWNDPROC) = 0) ThenlpfnOld = Set Window Long (h Wnd, GWL-WNDPROC, Address Of Wnd proc) if lpfnold damusuccess = setprop (hwnd, oldwndproc, lpfnold) end =

TrueElseIf lpfnOld Then Call UnSubClass (hWnd) MsgBox "Unable to successfully subclass & H" & Hex (hWnd), vbCriticalEnd IfEnd FunctionPublic Function UnSubClass (hWnd As Long) As BooleanDim lpfnOld As LonglpfnOld = GetProp (hWnd, OLDWNDPROC) If lpfnOld ThenIf RemoveProp (hWnd , OLDWNDPROC) ThenUnSubClass = SetWindowLong (hWnd, GWL_WNDPROC, lpfnOld) End IfEnd IfEnd FunctionPublic Function WndProc (ByVal hWnd As Long, pByVal uMsg Ap Long, ByVal wParam As _Long, ByVal lParam As Long) As LongSelect Case uMsgCase WM_SHNOTIFY 'process e system messages Notice function Call Form1.NotificationReceipt (wParamN lParam) Case WM_NCDESTROYCall unSubClass (hWnd) ND sgBox "Unubclassed & H" & Hex (hWnd), vbCritical, "WndProc Error" End SelectWndProc = CallWindowProc (GetProp (hWnd, OLDWNDPROC), hWnd, uMsg, WPARAM, LPARAM) End Function Saves, then runs the program, then you can try to create or delete a file or folder in the Explore, you can see the LL you have been recorded in Form and display it in TextBox . Now analyze the following programs, the above program first calls the SHCHANGENOTIFYREGISTER function to add Form to the system message announcement chain, and use the setWindowlong function to change the message D-based function of the FORMED, when Y is on the system, obtained according to the passing parameters The content of the system advertisement is displayed in the text window. Call the SHCHANGENOTIFYDEREGISTER function logout system message announcement when exiting the program. Next I want to introduce you how to use the Windows Unprecedented Function to invoke some dialogs in the Windows system. These include how to call the system's Runner dialog, "Find File" dialog, change the icon dialog associated with the file, and so on.

First create a new project in VB, then added five CommandButton control to Form1, do not change their properties, and then add the following code in Form1's code window: Option ExplicitPrivate Type BrowseInfohwndOwner As LongpIDLRoot As LongpszDisplayName As LonglpszTitle As LongulFlags As LonglpfnCallback As LonglParam As LongiImage As LongEnd TypeConst BIF_RETURNONLYFSDIRS = 1Const MAX_PATH = 260Private Declare Function SHObjectProperties Lib "Shell32" Alias ​​"# 178" _ (ByVal hwndOwner As Long, _ByVal uFlags As Long, _ByVal lpstrName As String, _ByVal lpstrPar As String) As LongPrivate Declare Sub CoTaskMemFree Lib "ole32.dll" (ByVal hMem As Long) Private Declare Function SHBrowseForFolder Lib "Shell32" (lpbi _As BrowseInfo) As LongPrivate Declare Function SHFindFiles Lib "Shell32" Alias ​​"# 90" _ (ByVal pIDLRoot As Long, _ByVal pidlSavedSearch As Long) As LongPrivate Declare Function GetFileNameFromBrowse Lib "Shell32" Alias ​​"# 63" (_ByVal hwndOwner As Long, _ByVal lpstrFile As String, _ByVal nMaxFile As Long, _ByVal lpstrInitDir As String, _ByVal lpstrDefExt As String, _ByVal lps trFilter As String, _ByVal lpstrTitle As String) As LongPrivate Declare Sub PickIconDlg Lib "Shell32" Alias ​​"# 62" (ByVal hwndOwner As Long, _ByVal lpstrFile As String, ByVal nMaxFile As Long, lpdwIconIndex As Long) Private Declare Function SHRunFileDlg Lib "Shell32 "Alias" # 61 "_ (ByVal hOwner As Long, _ByVal hIcon As Long, _ByVal lpstrDirectory As String, _ByVal szTitle As String, _ByVal szPrompt As String, _ByVal uFlags As Long) As LongPrivate Sub Command1_Click () SHRunFileDlg Form1.hWnd, Form1 . Partle, "C: / Windows", "Running Program", "Enter the program name in the text box" or press Browse button ", 0nd Subprivate Sub Command2_Click () Dim A as Longdim Astr As stringastr =

转载请注明原文地址:https://www.9cbs.com/read-5476.html

New Post(0)