Windows Programming/Programming Shell Extensions

      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.

      The 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:

      ShellExecute

      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);
      
      hwnd
      The handle to the parent window of the operation
      lpOperation
      The text name of the operation. These are the strings that appear in the menu when you right-click an icon. Some common values are "edit", "run", or "execute".
      lpFile
      the name of the target file
      lpParameters
      If lpFile specifies an executable file, the lpParameters field contains the commandline arguments to the executable, if any
      lpDirectory
      specifies what directory to perform the operation in
      nShowCmd
      ↑Jump back a section

      The System Tray

      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 the Shell_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 tray
      NIM_DELETE Delete an icon from the system tray
      NIM_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;
      
      cbSize
      This should reflect the size of the NOTIFYICON structure. If we have a structure called "nid", we usually assign this member as follows:
      nid.cbSize = sizeof(NOTIFYICONDATA);
      
      hWnd
      This field contains the handle of the parent window. When the notify icon is clicked, a corresponding message will be sent to this window.
      uID
      This is a numerical identifier for the icon in question. A program can have up to 12 different icons at once.
      uCallbackMessage
      This is the message that will be sent to your window. This message should be WM_USER or greater. The WPARAM field of the message will contain the uID of the icon in question.
      uFlags
      This member tells the shell which fields are valid fields. If a field does not contain any information, or if you don't want to use a particular field to set or modify a value, do not list them in the uFlags member. The possible values are NIF_ICON, NIF_MESSAGE, and NIF_TIP.
      hIcon
      a handle to the icon to be displayed in the system tray. must be a 16x16 icon.
      szTip
      A short string that contains a "tooltip" for the icon. When the mouse is hovered over the icon, the tooltip will be displayed. leave this blank, if you do not want to have a tool tip displayed.
      ↑Jump back a section

      The Recycle Bin

      ↑Jump back a section
      Last modified on 22 June 2010, at 01:58