用DLL为应用程序预留待扩展功能接口
2008-11-13 19:30:32 来源:WEB开发网若要扩展上面应用程序的功能,在不改动上述程序的情况下,只需将功能扩展部分的代码编写成动态链接函数库,编译成.DLL文件,并在PRAC.INI文件中加入下面语句,即可达到扩展功能的目的。在PRAC.INI中加入:
[AddApp]
AddMyapp=c:win95systemextproc.dll
扩展功能的动态链接函数库代码如下:
/*-----EXTPROC_DLL.c-----*/
#include <windows.h>
#include <commdlg.h>
#include "extproc_dll.h"
HMENU hMenu , hExtMenu;
HWND hWndExt = NULL;
int FAR PASCAL LibMain(HANDLE hModule , WORD wDataSeg,
WORD HeapSize , LPSTR lpszCmdLine)
{
if(HeapSize != 0)
UnlockData(0);
return 1;
}
int FAR PASCAL WEP(int SystemExit)
{
switch (SystemExit)
{
case WEP_SYSTEM_EXIT:
return 1;
case WEP_FREE_DLL:
return 1;
default:
return 1;
}
}
/*函数FMExtensionProc()即为扩展功能的处理函数,当过滤函数检索到有来自扩展功能的菜单消息时,就调用该函数进行处理。在此仅以设置打印机、选择字体来说明扩展功能的处理过程,读者可根据自己的需要修改*/
void FAR PASCAL FMExtensionProc(HWND hWndFMExt , WORD wMessage)
{
PRINTDLG pd;
CHOOSEFONT fnt;
LOGFONT lf;
CHOOSECOLOR chclr;
DWORD dwColor;
DWORD dwCustClrs[16];
int i;
switch(wMessage)
{
/*处理FMEVENT_LOAD消息,加载用户扩展功能菜单FMExtMenu*/
case EXTPROC_LOAD:
hExtMenu = LoadMenu(FMExtInst,"FMExtMenu");
hMenu = GetMenu(hWndFMExt);
AppendMenu(hMenu,MF_POPUP,hExtMenu ,"扩展功能(&E)");
SetMenu(hWndFMExt,hMenu);
break;
/*下面是用户可自定义的扩展功能代码*/
case IDM_PRINTERSETUP: //设置打印机
pd.lStructSize = sizeof(PRINTDLG);
pd.hwndOwner = hWndFMExt;
pd.hDevMode = NULL;
pd.hDevNames = NULL;
pd.Flags = PD_RETURNDC|PD_SELECTION|PD_PRINTSETUP;
pd.nCopies = 1;
PrintDlg((LPPRINTDLG)&pd);
break;
case IDM_SELECTFONT: //选择字体
fnt.lStructSize = sizeof(CHOOSEFONT);
fnt.hwndOwner = hWndFMExt;
fnt.hDC = NULL;
fnt.lpLogFont = &lf;
fnt.Flags = CF_SCREENFONTS|CF_EFFECTS;
fnt.rgbColors = RGB(0,255,255);
fnt.lCustData = 0L;
fnt.nFontType = SCREEN_FONTTYPE;
fnt.nSizeMin = 0;
fnt.nSizeMax = 0;
ChooseFont(&fnt);
break;
}
return;
}
/*------------End of EXTPROC_DLL.C------------*/
/*----- EXTPROC_DLL.H -----*/
#define IDM_PRINTERSETUP 101
#define IDM_SELECTFONT 102
#define EXTPROC_LOAD 200
void FAR PASCAL _export FMExtensionProc(HWND,WORD);
/*-----End of EXTPROC_DLL.H -----*/
;资源文件EXTPROC_dll.RC
#include "windows.h"
#include "extproc_dll.h"
FMExtMenu MENU DISCARDABLE
BEGIN
MENUITEM "Printer&Setup" ,IDM_PRINTERSETUP
MENUITEM "Select&Font" ,IDM_SELECTFONT
END
;End of EXTPROC_DLL.RC
;模块定义文件EXTPROC_DLL.DEF
LIBRARY EXTPROC
DESCRIPTION 'File Manager Extension DLL'
EXETYPE WINDOWS
CODE PRELOAD MOVEABLE DISCARDABLE
DATA PRELOAD SINGLE SHARED
HEAPSIZE 1024
EXPORTS
WEP @1 RESIDENTNAME
FMExtensionProc @2
;End of EXTPROC_DLL.DEF
更多精彩
赞助商链接