Shell32 Functions
The Shell32.dll library provides functions for interacting with the Windows Shell. This includes functionality for managing files, folders, shortcuts, and other shell-related operations.
Commonly Used Functions
ShellExecute
Performs an operation on a specified file.
Shell_NotifyIcon
Manages notification icons in the taskbar.
DragAcceptFiles
Registers a window to accept dropped files.
SHBrowseForFolder
Displays a dialog box that allows the user to select a folder.
SHFileOperation
Performs a file operation (copy, move, rename, delete).
SHGetFolderPath
Retrieves the path of a special folder.
SHGetSpecialFolderPath
Retrieves the path of a special folder (deprecated, use SHGetFolderPath).
SHAppInfo
Retrieves information about installed applications.
SHSetCurrentDirectory
Sets the current directory for the process.
SHChangeNotify
Notifies the Shell about changes to the file system.
ShellExecute
Prototype:
HINSTANCE ShellExecute(
HWND hwnd,
LPCTSTR lpOperation,
LPCTSTR lpFile,
LPCTSTR lpParameters,
LPCTSTR lpDirectory,
INT nShowCmd
);
Description:
This function performs an operation on a specified file. It can be used to open a document, print a document, explore a folder, or execute a program.
Parameters:
hwnd: Handle to the owner window of any message boxes that the function displays.lpOperation: A pointer to a null-terminated string that specifies the action to perform. Common values include "open", "print", "explore", "edit".lpFile: A pointer to a null-terminated string that specifies the file or object on which to perform the specified operation.lpParameters: A pointer to a null-terminated string that specifies the parameters to pass to the application.lpDirectory: A pointer to a null-terminated string that specifies the default directory.nShowCmd: The window display state for the application.
Return Value:
If the function succeeds, it returns a value greater than 32. If the function fails, it returns a value that indicates the error.
Shell_NotifyIcon
Prototype:
BOOL Shell_NotifyIcon(
DWORD dwMessage,
PNOTIFYICONDATA pnid
);
Description:
This function is used to add, modify, or delete a notification icon in the taskbar's notification area.
Parameters:
dwMessage: The action to perform (e.g.,NIM_ADD,NIM_MODIFY,NIM_DELETE).pnid: A pointer to aNOTIFYICONDATAstructure that contains information about the icon.
Return Value:
Returns TRUE if successful, FALSE otherwise.
SHBrowseForFolder
Prototype:
LPITEMIDLIST SHBrowseForFolder(
LPBROWSEINFO lpbi
);
Description:
Displays a dialog box that allows the user to select a folder. The function returns the PIDL (Pointer to an Item ID List) of the selected folder.
Parameters:
lpbi: A pointer to aBROWSEINFOstructure that contains information about the dialog box.
Return Value:
Returns a pointer to an item ID list that specifies the path of the folder the user selected. If the user cancels the dialog box, it returns NULL.
SHFileOperation
Prototype:
int SHFileOperation(
PSHFILEOPSTRUCTA pfo
);
Description:
This function performs a file operation such as copying, moving, renaming, or deleting files and directories.
Parameters:
pfo: A pointer to aSHFILEOPSTRUCTstructure that contains all necessary information to perform the requested file operation.
Return Value:
Returns zero if the operation is successful; otherwise, returns a nonzero error value.
SHGetFolderPath
Prototype:
HRESULT SHGetFolderPath(
HWND hwndOwner,
int nFolder,
HANDLE hToken,
DWORD dwFlags,
LPTSTR pszPath
);
Description:
Retrieves the path of a special folder, such as the user's profile directory, the system directory, or the desktop.
Parameters:
hwndOwner: Handle to the owner window.nFolder: A CSIDL value that specifies the special folder.hToken: Access token for the user.dwFlags: Flags that specify the type of path to retrieve.pszPath: Pointer to a buffer that receives the path.
Return Value:
Returns S_OK if successful, or an error code otherwise.
SHChangeNotify
Prototype:
void SHChangeNotify(
LONG wEventId,
UINT uFlags,
LPCVOID dwItem1,
LPCVOID dwItem2
);
Description:
Notifies the Shell about changes to the file system, such as file creation, deletion, or renaming. This allows the Shell to update its views and caches accordingly.
Parameters:
wEventId: A value that specifies the type of change that occurred (e.g.,SHCNE_CREATE,SHCNE_DELETE).uFlags: Flags that indicate how the notification should be processed.dwItem1: Pointer to the first item affected by the change.dwItem2: Pointer to the second item affected by the change.