Shell

Shell Library

디버그정 2008. 9. 13. 08:37
 
Shell Library Shell Library *
*  *Index  *Topic Contents
*Previous Topic: Shell Extensions
*Next Topic: Shell Links

Shell Library


A shell is an application that enables users to group, start, and otherwise control other applications. This overview describes features of the shell for the Microsoft® Windows® operating system.

arrowy.gifAbout the Shell Library

arrowy.gifShell Library Reference

About the Shell Library

The following features are supported by the dynamic-link library Shell.dll:

  • The drag-and-drop feature.
  • Associations used to find and start applications.
  • Extraction of icons from executable files.

Using the Drag-and-Drop Feature

When an application implements the drag-and-drop feature, a user can select one or more files in File Manager, drag them to an open application, and drop them there. The application in which the files were dropped receives a message it can use to retrieve the file names and the coordinates of the point at which the files were dropped.

An application that can accept dropped files from File Manager calls the DragAcceptFiles function for one or more of its windows. When the user releases the mouse button to drop a file or files in the window specified in the call to DragAcceptFiles, File Manager sends the application a WM_DROPFILES message. (File Manager does not send the WM_DROPFILES message to an application unless the application calls DragAcceptFiles.) WM_DROPFILES contains a handle to a structure that the application can query to retrieve the name of the dropped file and the coordinates of the cursor when the file was dropped. The application can use the DragQueryFile function to retrieve a count of the files that were dropped and their names. The DragQueryPoint function returns the window coordinates of the cursor when the user released the mouse button.

To free the memory allocated by the system for the WM_DROPFILES message, an application calls the DragFinish function when it is finished.

For example, an application can call the DragAcceptFiles function when it starts and call a drag-and-drop function when it receives a WM_DROPFILES message, as shown in the following example.

case WM_CREATE: 
    DragAcceptFiles(hwnd, TRUE); 
    break; 
 
case WM_DROPFILES: 
    DragFunc(hwnd, wParam); /* application-defined function */ 
    break; 
 
case WM_DESTROY: 
    DragAcceptFiles(hwnd, FALSE); 
    break; 

The following example uses the DragQueryPoint function to determine where to begin to write text. The first call to the DragQueryFile function determines the number of dropped files. The loop writes the name of each file, beginning at the point returned by DragQueryPoint.

POINT pt; 
WORD cFiles, a; 
char lpszFile[80]; 
 
DragQueryPoint((HANDLE) wParam, &pt); 
 
cFiles = DragQueryFile((HANDLE) wParam, 0xFFFF, (LPSTR) NULL, 0); 
for(a = 0; a < cFiles; pt.y += 20, a++) { 
    DragQueryFile((HANDLE) wParam, a, lpszFile, sizeof(lpszFile)); 
    TextOut(hdc, pt.x, pt.y, lpszFile, lstrlen(lpszFile)); 
} 
 
DragFinish((HANDLE) wParam); 

Using Associations to Find and Start Applications

File Manager includes an Associate dialog box that makes it possible for users to associate a file name extension with a specific application. File Manager stores these associations in the registry (under HKEY_CURRENT_USER\Software\Description\Microsoft\Windows\CurrentVersion\Extensions). If a file has a file name extension that is associated with an application, that application starts automatically whenever the user double-clicks that file in File Manager.

Using the FindExecutable and ShellExecute functions, applications can take advantage of such associations to find and start applications or open and print files.

An application can use the FindExecutable function to retrieve the name and handle to the executable file that is associated with a specified file name. The ShellExecute function either opens or prints a specified file, depending on the value of its lpOperation parameter. To open a document file, the function relies on the association of the file name extension.

You can use ShellExecute to open or explore a folder. To open a folder, use either of the following calls:

ShellExecute(handle, NULL, "path_to_folder", NULL, NULL, SW_SHOWNORMAL);

or

ShellExecute(handle, "open", "path_to_folder", NULL, NULL, SW_SHOWNORMAL);

To explore a folder, use the following call:

ShellExecute(handle, "explore", "path_to_folder", NULL, NULL, SW_SHOWNORMAL);

If the lpOperation parameter is NULL, the function opens the file specified by its lpFile parameter. If lpOperation is "open", the function will open the file in a new window. If lpOperation is "explore", the function will browse to the folder using an existing Explorer window, if one is open. If an Explorer window is not open, a new one will be created.

Extracting Icons from Executable Files

An application can use the ExtractIcon function to retrieve the handle to an icon from a specified executable file, dynamic-link library, or icon file. The following example uses the DragQueryPoint function to retrieve the coordinates of the point where a file was dropped, the DragQueryFile function to retrieve the file name of a dropped file, and the ExtractIcon function to retrieve the handle to the first icon in the file, if any.

POINT pt; 
WORD cFiles; 
HDC hdc; 
char lpszFile[80]; 
HANDLE hCurrentInst, hicon; 
 
DragQueryPoint((HANDLE) wParam, &pt); 
 
cFiles = DragQueryFile((HANDLE) wParam, 0xFFFF, NULL, NULL); 
 
if(cFiles > 1) { 
    TextOut(hdc, pt.x, pt.y, 
        "Please drop only one icon file.", 31); 
    return FALSE; 
} 
else { 
    DragQueryFile((HANDLE) wParam, 0, lpszFile, sizeof(lpszFile)); 
    hCurrentInst = (HINSTANCE) GetWindowLong(hwnd, GWL_HINSTANCE); 
    hicon = ExtractIcon(hCurrentInst, lpszFile, 0); 
    if (hicon == NULL) 
        TextOut(hdc, pt.x, pt.y, "No icons found.", 15); 
    else if (hicon == (HICON) 1) 
        TextOut(hdc, pt.x, pt.y, 
            "File must be .EXE, .ICO, or .DLL.", 33); 
    else 
        DrawIcon(hdc, pt.x, pt.y, hicon); 
} 
 
DragFinish((HANDLE) wParam); 

Shell Library Reference

The following programming elements are associated with shell features.

Shell Library Functions

The following functions are used to implement shell features.

DragAcceptFiles
DragFinish
DragQueryFile
DragQueryPoint
ExtractAssociatedIcon
ExtractIcon
ExtractIconEx
FindExecutable
ShellAbout
ShellExecute
ShellExecuteEx

Shell Library Messages

The following message is used to implement shell features.

Message Description
WM_DROPFILES Sent to the window that the mouse is over when the user drops an item or items on the window. See the WM_DROPFILES description for more information.

Shell Library Structures

The following structure is used to implement shell features.

SHELLEXECUTEINFO

Up Top of Page
© 1997 Microsoft Corporation. All rights reserved. Terms of Use.