Windows输入法生成器类输入法VC++安装程序源代码
//五笔输入法安装程序
#include
#include
#include
#pragma comment (lib, "imm32")
#define LAYOUTTEXT _T("五笔输入法")
#define IMEFILE _T("wb.ime")
#define INST_TITLE _T("安装输入法")
#define UNINST_TITLE _T("卸载输入法")
#define FILENUM 2
TCHAR sModuleFile[MAX_PATH];
TCHAR sSrcDir[MAX_PATH], sDestDir[MAX_PATH],CurrentTableDir[MAX_PATH]="";
TCHAR FileBeCopyed[FILENUM][MAX_PATH]={"wb.ime","wb.mb"};
//判断操作系统涵数及变量
typedef enum tagWin32SysType{
Windows32s,
WindowsNT3,
Windows95,
Windows98,
WindowsME,
WindowsNT4,
Windows2000,
WindowsXP,
Windows2003
}Win32SysType;
//判断操作系统涵数及变量
Win32SysType IsShellSysType()
{
Win32SysType ShellType;
DWORD winVer;
OSVERSIONINFO *osvi;
winVer=GetVersion();
if(winVer<0x80000000){/*NT */
ShellType=WindowsNT3;
osvi= (OSVERSIONINFO *)malloc(sizeof(OSVERSIONINFO));
if (osvi!=NULL){
memset(osvi,0,sizeof(OSVERSIONINFO));
osvi->dwOSVersionInfoSize=sizeof(OSVERSIONINFO);
GetVersionEx(osvi);
if(osvi->dwMajorVersion==4L)ShellType=WindowsNT4;
else if(osvi->dwMajorVersion==5L&&osvi->dwMinorVersion==0L)ShellType=Windows2000;
else if(osvi->dwMajorVersion==5L&&osvi->dwMinorVersion==1L)ShellType=WindowsXP;
else if(osvi->dwMajorVersion==5L&&osvi->dwMinorVersion==2L)ShellType=Windows2003;
free(osvi);
}
}
else if (LOBYTE(LOWORD(winVer))<4)
ShellType=Windows32s;
else{
ShellType=Windows95;
osvi= (OSVERSIONINFO *)malloc(sizeof(OSVERSIONINFO));
if (osvi!=NULL){
memset(osvi,0,sizeof(OSVERSIONINFO));
osvi->dwOSVersionInfoSize=sizeof(OSVERSIONINFO);
GetVersionEx(osvi);
if(osvi->dwMajorVersion==4L&&osvi->dwMinorVersion==10L)ShellType=Windows98;
else if(osvi->dwMajorVersion==4L&&osvi->dwMinorVersion==90L)ShellType=WindowsME;
free(osvi);
}
}
return ShellType;
}
//将两个字符串结合
void Add(TCHAR a[256],TCHAR b[256],TCHAR *c)
{
lstrcpy(c, a);
lstrcat(c, b);
}
int GetFilePath(TCHAR *FileName, TCHAR *Path)
{
int i;
i = lstrlen(FileName) - 1;
while (FileName != '\\' && i > 1)
i--;
lstrcpy(Path, FileName);
Path = 0;
return 0;
}
BOOL IsFileExist(const TCHAR *file)
{
WIN32_FIND_DATA data;
HANDLE handle;
if(!file)
return FALSE;
handle = FindFirstFile(file, &data);
if(handle == INVALID_HANDLE_VALUE)
return FALSE;
FindClose(handle);
return TRUE;
}
//复制文件的子程序
BOOL YJMCopyFile(TCHAR* FileSRC, TCHAR* FileDest)
{
TCHAR YJMMess1[256],YJMMess2[256],YJMMess3[256];
Add(FileDest,_T("已经存在,您要覆盖它吗?\n"),YJMMess1);
Add(FileSRC,_T("复制失败。\n输入法安装失败!"),YJMMess2);
Add(FileSRC,_T("复制失败。\n输入法安装失败!"),YJMMess3);
if(IsFileExist(FileDest)) {
if (MessageBox(NULL, YJMMess1, INST_TITLE,
MB_YESNO | MB_ICONQUESTION | MB_DEFBUTTON1) == IDYES) {
if (CopyFile(FileSRC, FileDest, FALSE) == 0) {
MessageBox(NULL,YJMMess2,INST_TITLE,MB_OK | MB_ICONSTOP);
return(FALSE);
}
}
}
else if (CopyFile(FileSRC, FileDest, FALSE) == 0) {
MessageBox(NULL,YJMMess3,INST_TITLE,MB_OK | MB_ICONSTOP);
return(FALSE);
}
return TRUE;
}
BOOL CopyIMEFile(HINSTANCE hInstance, TCHAR* sImeFile)
{
TCHAR sSrc[MAX_PATH], sDest[MAX_PATH];
int i;
//取得本文件执行路径。若用GetCurrentDirectory(400, sSrcDir)则可能是在别的目录执行。
GetModuleFileName(hInstance, sModuleFile, sizeof(sModuleFile) - 1);
GetFilePath(sModuleFile, sSrcDir);
lstrcat(sSrcDir, "\\");
//取得windows系统目录
GetSystemDirectory(sDestDir, sizeof(sDestDir) - 1);
lstrcat(sDestDir, "\\");
for(i=0;iAdd(sSrcDir,FileBeCopyed,sSrc);
Add(sDestDir,FileBeCopyed,sDest);
if(!YJMCopyFile(sSrc,sDest)) return(FALSE);
}
Add(sDestDir,IMEFILE,sDest);
lstrcpy(sImeFile, sDest);
return TRUE;
}
BOOL DeleteIMEFile(HINSTANCE hInstance, TCHAR* sImeFile)
{
TCHAR sDest[MAX_PATH];
int i;
//取得windows系统目录
GetSystemDirectory(sDestDir, sizeof(sDestDir) - 1);
lstrcat(sDestDir, "\\");
for(i=0;iAdd(sDestDir,FileBeCopyed,sDest);
if(!DeleteFile(sDest)) return(FALSE);
}
Add(sDestDir,IMEFILE,sDest);
lstrcpy(sImeFile, sDest);
return TRUE;//
}
int APIENTRY
WinMain(HINSTANCE hInstance,
HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow)
{
HKL hklCurrent;
TCHAR sImeFile[MAX_PATH],YJMMessage[256];
Add(_T("您要安装“"),LAYOUTTEXT,YJMMessage);
Add(YJMMessage,_T("”吗?\n"),YJMMessage);
if (MessageBox(NULL, YJMMessage, INST_TITLE,MB_YESNO | MB_ICONQUESTION | MB_DEFBUTTON1) != IDYES) {
MessageBox(NULL, _T("退出安装"),INST_TITLE, MB_OK | MB_ICONWARNING);
//
Add(_T("您要卸载“"),LAYOUTTEXT,YJMMessage);
Add(YJMMessage,_T("”吗?\n"),YJMMessage);
if (MessageBox(NULL, YJMMessage, UNINST_TITLE, MB_YESNO | MB_ICONQUESTION | MB_DEFBUTTON1) == IDYES) {
//删除输入法程序
if(!DeleteIMEFile(hInstance, sImeFile)) return FALSE;
//ImmUninstallIMEFile();
Add(LAYOUTTEXT,_T("卸载成功!"),YJMMessage);
MessageBox(NULL,YJMMessage,INST_TITLE,MB_OK | MB_ICONINFORMATION);
return(TRUE);
}
else{
MessageBox(NULL, _T("退出卸载"),UNINST_TITLE, MB_OK | MB_ICONWARNING);
return(FALSE);
}
}
Win32SysType SysType = IsShellSysType();
//Windows95,Windows98,WindowsME
if(SysType == Windows95 || SysType == Windows98 || SysType ==WindowsME){
CopyFile("wb_98.ime","wb.ime",TRUE);
}
//WindowsNT4,Windows2000,WindowsXP,Windows2003
else if(SysType == WindowsNT4 || SysType == Windows2000 || SysType == WindowsXP ||SysType == Windows2003){
CopyFile("wb_XP.ime","wb.ime",TRUE);
}
else{
CopyFile("wb_XP.ime","wb.ime",TRUE);
if (MessageBox(NULL, _T("是WinNT4,2000,XP,2003系列吗?\n是否继续安装?"),
INST_TITLE,MB_YESNO | MB_ICONQUESTION | MB_DEFBUTTON1) != IDYES){
MessageBox(NULL, _T("退出安装"),INST_TITLE, MB_OK | MB_ICONWARNING);
return(FALSE);
}
}
//复制文件并返回目标输入法程序的路径及名称,用于注册
if(!CopyIMEFile(hInstance, sImeFile)){
DeleteFile("wb.ime");
return FALSE;
}
//输入法注册(就在这里)
hklCurrent = ImmInstallIME(sImeFile, LAYOUTTEXT);
//确认安装状况,若不成功应当删除文件。
Add(LAYOUTTEXT,_T(" 安装成功!"),YJMMessage);
MessageBox(NULL,YJMMessage,INST_TITLE,MB_OK | MB_ICONINFORMATION);
DeleteFile("wb.ime");
return(TRUE);
}
(在大熊猫输入法安装程序基础上改写)
有些重复了,重新整理了下分别发在skydrive网盘上了。
①windows IME 输入法编程[只两篇文档:IME输入法编程.txt和输入法编程指南(根据msdn翻译).txt]:
②大熊猫输入法源码:
③输入法源码_路路通(包括路路通公布的SrfInstaller、路路通示例源码、输入法编程入门标准程序):
④双通输入法源码:
⑤自由拼音输入法31:
双通输入法源码本地下载:
|
文件: | 双通输入法源码.zip |
大小: | 1563KB |
下载: | 下载 |
|
开放源码的“大熊猫输入法”开发测试进行中--使用大熊猫输入法,学习输入法编程,体验自主自由的感觉!
大熊猫输入法源码本地下载:
|
文件: | 大熊猫输入法.rar |
大小: | 1884KB |
下载: | 下载 |
|
阅读(1740) | 评论(2) | 转发(0) |