如何用API编写汉字输入方法安装程序?(100)(100分)

  • 主题发起人 主题发起人 songguolong
  • 开始时间 开始时间
S

songguolong

Unregistered / Unconfirmed
GUEST, unregistred user!
本人想用DELPHI编制一个输入方法安装程序,不知道要用到哪些<br>API函数,如何用法,望各位不吝赐教!谢谢!<br>
 
输入法的安装主要是在系统注册表中建立一些信息,用TRegistry就可以。<br>同时,还要有些复制文件的操作等,用FileCopy.
 
Jimchael Tsee所提建议非常重要,我一直在模仿己有的汉字输入方法在注册表<br>中的登记信息通过手工修改注册表的办法来安装自己的输入方法,成功后将用<br>DELPHI做成安装程序。<br>所做内容如下:<br>1:把编译好的《大众码》的DZM.IME文件考贝到/Windows/System/目录中<br>2:在注册表的<br>HKEY_USERS/.Default/software/Microsoft/Windows/CurrentVersion/大众<br>中注册:<br>&nbsp; &nbsp; (默认) (未设置键值)<br>&nbsp; &nbsp; &lt;ENTER&gt; &nbsp;(1)<br>&nbsp; &nbsp; &lt;SPACE&gt; &nbsp;(0)<br>&nbsp; &nbsp; 编码查询 &nbsp;0xe0210804<br>&nbsp; &nbsp; ... ... ...<br>3:在注册表的<br>HKEY_LOCAL_MACHINE/SYSTEM/CurrentControlSet/Control/Keyboard Layouts/E0210804<br>中注册:<br>&nbsp; &nbsp; (默认) (未设置键值)<br>&nbsp; &nbsp; IME file "DZM.IME"<br>&nbsp; &nbsp; Layout file "kbdus.kbd"<br>&nbsp; &nbsp; Layout text "大众"<br><br>但此项实验屡屡失败,望高手能具体指导。<br><br><br>
 
这是自由拼音的一个注册程序, c写的.<br><br>#include &amp;lt;windows.h&gt;<br>#include &amp;lt;tchar.h&gt;<br>#include &amp;lt;stdio.h&gt;<br><br>#define CONVERSION_SET 0x6101<br>#define LAYOUTTEXT &nbsp; &nbsp;_T("自由拼音输入法")<br>#define LAYOUTFILE &nbsp; &nbsp;_T("kbdus.kbd")<br>#define LAYOUTFILENT &nbsp;_T("kbdus.dll")<br>#define IMEFILE &nbsp; &nbsp; &nbsp; _T("freepy.ime")<br><br>#define MAX_SIZE 200<br>#define MAX_SUBKEY 250<br><br>void main()<br>{<br> HKEY hKey,hChildKey;<br> DWORD dwIndex;<br> DWORD dwName,dwMaxName = 0;<br> TCHAR szNameArr[MAX_SUBKEY][MAX_SIZE],szName[MAX_SIZE];<br> DWORD dwLen;<br> TCHAR szLayoutText[MAX_SIZE];<br> DWORD dwData;<br> FILETIME ft;<br> LONG lRet;<br> TCHAR szRegName[MAX_SIZE];<br> DWORD dwDisposition;<br> DWORD dwConversionSet;<br> WORD wCount = 0;<br> int i;<br> OSVERSIONINFO osVerInfo;<br><br> dwIndex = 0;<br> dwLen = MAX_SIZE;<br> dwData = MAX_SIZE * sizeof(TCHAR);<br> dwConversionSet = CONVERSION_SET;<br><br> if ( RegOpenKeyEx(HKEY_LOCAL_MACHINE,<br> _T("Software"),<br> 0,<br> KEY_READ,<br> &amp;hKey) != ERROR_SUCCESS ){<br> _ftprintf(stderr,_T("Software open error/n"));<br> exit(1);<br> }<br><br> if( RegCreateKeyEx( hKey,<br> _T("freepy"),<br> 0,<br> NULL,<br> REG_OPTION_NON_VOLATILE ,<br> KEY_ALL_ACCESS ,<br> NULL,<br> &amp;hChildKey,<br> &amp;dwDisposition ) != ERROR_SUCCESS) {<br> RegCloseKey(hKey);<br> _ftprintf(stderr,_T("freepy create error/n"));<br> exit(1);<br> }<br><br> RegSetValueEx(hChildKey,<br> _T("ConversionSet"),<br> 0,<br> REG_DWORD,<br> (LPBYTE)&amp;dwConversionSet,<br> sizeof(DWORD));<br><br> RegCloseKey(hChildKey);<br> RegCloseKey(hKey);<br><br> if ( RegOpenKeyEx(HKEY_LOCAL_MACHINE,<br> _T("System//CurrentControlSet//Control//Keyboard Layouts"),<br> 0,<br> KEY_READ,<br> &amp;hKey) != ERROR_SUCCESS ){<br> _ftprintf(stderr,_T("Keyboard Layouts open error/n"));<br> exit(1);<br> }<br><br> RegQueryInfoKey (hKey,NULL, NULL,NULL,<br> &amp;dwIndex,<br> NULL,NULL,NULL, NULL,NULL,NULL, NULL);<br><br> while( (int)dwIndex &gt;= 0 ) {<br> dwLen = MAX_SIZE;<br> if((lRet = RegEnumKeyEx(hKey,<br> dwIndex,<br> szName,<br> &amp;dwLen,<br> NULL,<br> NULL,<br> NULL,<br> &amp;ft)) == ERROR_SUCCESS || lRet == ERROR_MORE_DATA ) {<br> _tcscpy(szNameArr[wCount++],szName);<br> }<br> dwIndex--;<br> }<br><br> for(i=0;i&lt;wCount;i++) {<br> if ( RegOpenKeyEx(hKey,<br> szNameArr,<br> 0,<br> KEY_ALL_ACCESS ,<br> &amp;hChildKey) == ERROR_SUCCESS ){<br> if( RegQueryValueEx( hChildKey,<br> _T("layout text"),<br> NULL,<br> NULL,<br> (LPBYTE)szLayoutText,<br> &amp;dwData) == ERROR_SUCCESS ){<br> if(!_tcsicmp(szLayoutText,LAYOUTTEXT)) {<br> goto my_next;<br> }<br> _stscanf(szNameArr,_T("%lx"),&amp;dwName);<br> if( dwMaxName &amp;lt; dwName ) dwMaxName = dwName;<br> }<br> RegCloseKey(hChildKey);<br> }<br> }<br><br> _stprintf(szRegName,"%lx",dwMaxName + 0x10000);<br> CharUpper(szRegName);<br><br> if( RegCreateKeyEx( hKey,<br> szRegName,<br> 0,<br> NULL,<br> REG_OPTION_NON_VOLATILE ,<br> KEY_ALL_ACCESS ,<br> NULL,<br> &amp;hChildKey,<br> &amp;dwDisposition ) != ERROR_SUCCESS) {<br> RegCloseKey(hKey);<br> _ftprintf(stderr,_T("%s create error/n"),szRegName);<br> exit(1);<br> }<br><br>my_next:<br> RegSetValueEx(hChildKey,<br> _T("IME file"),<br> 0,<br> REG_SZ,<br> (LPBYTE)IMEFILE,<br> _tcslen(IMEFILE)*sizeof(TCHAR));<br><br> osVerInfo.dwOSVersionInfoSize = sizeof(OSVERSIONINFO);<br> if(GetVersionEx(&amp;osVerInfo)) {<br> RegSetValueEx(hChildKey,<br> _T("layout file"),<br> 0,<br> REG_SZ,<br> (osVerInfo.dwPlatformId == VER_PLATFORM_WIN32_NT) ?<br> ((LPBYTE)LAYOUTFILENT):((LPBYTE)LAYOUTFILE),<br> _tcslen(LAYOUTFILENT)*sizeof(TCHAR));<br> }<br> else {<br> _ftprintf(stdout,_T("get version error/n"));<br> RegSetValueEx(hChildKey,<br> _T("layout file"),<br> 0,<br> REG_SZ,<br> (LPBYTE)LAYOUTFILE,<br> _tcslen(LAYOUTFILE)*sizeof(TCHAR));<br> }<br><br> RegSetValueEx(hChildKey,<br> _T("layout text"),<br> 0,<br> REG_SZ,<br> (LPBYTE)LAYOUTTEXT,<br> _tcslen(LAYOUTTEXT)*sizeof(TCHAR));<br><br> RegCloseKey(hChildKey);<br> RegCloseKey(hKey);<br><br> _ftprintf(stdout,_T("ok/n"));<br> return;<br>}<br>
 
到深度历险看看。
 
cytown:<br>你好!<br>所提供程序很好,只是不知道为什么要执行<br>if( RegCreateKeyEx( hKey,<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; ("freepy"),<br> 0,<br> NULL,<br> REG_OPTION_NON_VOLATILE , KEY_ALL_ACCESS ,<br> NULL,<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &amp;hChildKey,<br> &amp;dwDisposition ) != ERROR_SUCCESS) {<br> &nbsp; &nbsp;RegCloseKey(hKey);<br> &nbsp; &nbsp;_ftprintf(stderr,_T("freepy create error/n")); &nbsp; &nbsp;exit(1); }<br> RegSetValueEx(hChildKey,<br> ("ConversionSet"),<br> 0,<br> REG_DWORD,<br> (LPBYTE)&amp;dwConversionSet,<br> sizeof(DWORD));<br>一段;另外,能详细说明一下程序的执行过程吗(包括输入方法的编泽准备)?
 
我倒!!$$$%^^^&amp;$^$%*!$!@<br>这是关键的部分呀!!!<br>if (注册表中创建freepy键没有成功)<br>&nbsp; &nbsp;显示"创建错误"并退出<br>创建子键: conversionset<br><br>
 
谢谢cytown,给你加分了!<br>
 
后退
顶部