FAQ по Visual Basic

Содержание / Разное Поиск | Далее

§ 8.1. Как связать конкретное расширение файлов со своей программой?

Читаем в том же MSDN:

Supporting Context Menu Operations

Your installation program can provide support for Context menu operations, such as Open, Print, and Print To, by setting appropriate registry entries. The Context appears when the user clicks the right mouse button on a document associated with your application.

Enabling "Print" in the registry gives the shell instructions about what to execute when the user selects Print from the Context menu. Usually an application will display a dialog that says "Printing page X of N on LPTX".

Enabling "Print To" in the registry specifies the default action for "drag print."Print To" displays the same dialog box as "Print" when you drag to a specific printer. The "Print To" option is not displayed on the menu, so it does not bring up anything (that is, it cannot be selected).

The following example shows how to set commands for the Context menu for files having the .TXT and .RTF filename extensions:

HKEY_CLASSES_ROOT\.txt = txtfile
HKEY_CLASSES_ROOT\txtfile = Text File
HKEY_CLASSES_ROOT\txtfile\DefaultIcon = c:\chicago\WRITEPAD.EXE,0
HKEY_CLASSES_ROOT\txtfile\shell\open\command = WRITEPAD.EXE %1
HKEY_CLASSES_ROOT\txtfile\shell\print\command = WRITEPAD.EXE /p %1
HKEY_CLASSES_ROOT\txtfile\shell\printto\command = WRITEPAD.EXE /p %1

HKEY_CLASSES_ROOT\.rtf = rtffile
HKEY_CLASSES_ROOT\rtffile = Rich Text File
HKEY_CLASSES_ROOT\rtffile\DefaultIcon = c:\chicago\WRITEPAD.EXE,0
HKEY_CLASSES_ROOT\rtffile\shell\open\command = WRITEPAD.EXE %1
HKEY_CLASSES_ROOT\rtffile\shell\print\command = WRITEPAD.EXE /p %1

Adding the Application to the Start Button

Your installation program can still create a "Program Group" in the Programs folder by using dynamic data exchange (DDE) as used in Windows version 3.1. However, this is no longer the preferred method. Instead, your installation program should add an icon for your primary application to the Start Programs menu. The program can, optionally, prompt the user to choose which program icons to place in the menu, but icons should not be added for every application in your package and an extensive hierarchy of programs and folders should not be created on this menu.

To add an icon to the Start program menu, your installation program should create a link to your application's executable file and place the link in the \WINDOWS\STARTMEN\PROGRAMS directory. (Note that the \WINDOWS directory should actually be the path returned by the GetWindowsDirectory function.) An installation program can create a link by using the IShellLink interface.

Using Filename Extensions

In Windows 95, filename extensions should always describe a file type. Your installation program should not rename old or backup files by changing them to filename extensions such as .001 or .BAK or .XX1. If the file type does not change, the program should give the file a new name. For example, it can use long filenames to change the old version of a filename, such as SAMPLE.DLL, to Copy of SAMPLE.DLL.

The following table lists filename extensions currently used in Windows. Do not use these filename extensions unless your file fits the given type description.

Extension Type description
386 Windows virtual device driver
3GR Screen grabber for MS-DOS®–based applications
GR3 Windows 3.0 screen grabber
ACM Audio compression manager driver
ADF Administration configuration files
ANI Animated mouse cursor
AVI Video clip
AWD Fax viewer document
AWP Fax key viewer
AWS Fax signature viewer
BAK Backed-up file
BAT MS-DOS batch file
BFC Briefcase
BIN Binary data file
BMP Picture (Windows bitmap)
CAB Windows Setup file
CAL Windows Calendar file
CDA CD audio track
CFG Configuration file
CNT Help contents
COM MS-DOS program
CPD Fax cover page
CPE Fax cover page
CPI International code page
CPL Control Panel application
CRD Windows Cardfile document
CSV Command-separated data file
CUR Cursor (pointer)
DAT System data file
DCX Fax viewer document
DLL Application extension (dynamic-link library)
DOC WordPad document
DOS MS-DOS file (also extension for NDIS2 net card and protocol drivers)
DRV Device driver
EXE Application
FND Saved search results
FON Font file
FOT Shortcut to font
GR3 Windows 3.0 screen grabber
GRP Program group file
HLP Help file
HT HyperTerminal file
ICM Image color matching (ICM) profile
ICO Icon
IDF MIDI instrument definition
INF Setup information
INI Configuration settings
KBD Keyboard layout
LGO Windows logo driver
LIB Static-link library
LNK Shortcut
LOG Log file
MCI MCI command set
MDB File viewer extension
MID MIDI sequence
MIF MIDI instrument file
MMF Microsoft Mail message file
MMM Animation
MPD Mini-port driver
MSG Microsoft Exchange mail document
MSN The Microsoft Network home base
MSP Windows Paintbrush picture
NLS Natural language services driver
PAB Microsoft Exchange personal address book
PCX Picture (PCX format)
PDR Port driver
PF ICM profile
PIF Shortcut to MS-DOS–based application
PPD PostScript printer description file
PRT Printer formatted file (result of Print to File option)
PST Microsoft Exchange personal information store
PWL Password list
QIC Backup set for Microsoft Backup
REC Windows Recorder file
REG Application registration file
RLE Picture (RLE format)
RMI MIDI sequence
RTF Document (rich-text format)
SCR Screen saver
SET File set for Microsoft Backup
SHB Shortcut into a document
SHS Scrap
SPD PostScript printer description file
SWP Virtual memory storage
SYS System file
TIF Picture (TIFF format)
TMP Temporary file
TRN Translation file
TSP Windows telephony service provider
TTF TrueType font
TXT Text document
VBX Visual Basic control file
VER Version description file
VXD Virtual device driver
WAV Sound wave
WPC WordPad file converter
WRI Windows Write document
XAB Microsoft Mail address book

Also investigate extensions commonly used by popular applications so you can avoid creating a new extension that might conflict with them, unless you intend to replace or supersede the functionality of those applications.

То есть все сводится к созданию определенных записей в реестре. См. также § 5.22. Как работать с реестром?

Автор:
Master

Предыдущий раздел Следующий раздел

© 2004. При цитировании, пожалуйста, не забудьте поставить ссылку на оригинальную страницу.