The Windows Shell consists primarily of explorer.exe, the graphical user interface that displays folders, icons, and the desktop. Explorer.exe is written primarily in C++, so to write extension modules is going to require OO programming. However, there are several functions, in <windows.h> that a C program can use to interact with the shell to perform some basic tasks. First, we will describe some of the basic areas of your shell.
explorer.exe, the Windows shell program, has a number of different functions that can be used to cause your program to perform tasks like the shell would. We will run over a few of them here:
The ShellExecute function takes a file and a pathname as arguments, and essentially performs whatever task the shell would perform if the file in question was double-clicked. For instance, calling a ShellExecute on "MyFile.txt" would open notepad, and would display MyFile.txt. Similarly, calling ShellExecute on a hyperlink will automatically open Internet Explorer (or your default browser) and will open the specified URL.
HINSTANCE ShellExecute(HWND hwnd, LPCTSTR lpOperation, LPCTSTR lpFile, LPCTSTR lpParameters, LPCTSTR lpDirectory, INT nShowCmd);
The system tray is the area in the lower-right hand side of the screen that contains the clock and a number of different icons. Icons can be added to the system tray by using a simple API call. The function call to be used is theShell_NotifyIcon function, and we will explain it here.
WINSHELLAPI BOOL WINAPI Shell_NotifyIcon(DWORD dwMessage, PNOTIFYICONDATA pnid);
This function takes 2 arguments. The first argument is a message, and the second argument contains more information on the message. There are 3 messages possible:
NIM_ADD Add a new icon to the system trayNIM_DELETE Delete an icon from the system trayNIM_MODIFY Modify an existing icon in the system tray
We can see that the second argument is a pointer to the NOTIFYICONDATA structure. This structure contains fields as such:
typedef struct _NOTIFYICONDATA { DWORD cbSize; HWND hWnd; UINT uID; UINT uFlags; UINT uCallbackMessage; HICON hIcon; WCHAR szTip[64]; } NOTIFYICONDATA, *PNOTIFYICONDATA;
nid.cbSize = sizeof(NOTIFYICONDATA);