CIMESoftKbd.cpp
上传用户:hyb6888
上传日期:2016-01-24
资源大小:5186k
文件大小:9k
- #include "stdafx.h"
- #include "stdio.h"
- #include "CIMESoftKbd.h"
- CHAR SKLayoutName[NumsSK][11] = {
- "P C 键盘", "希腊字母",
- "俄文字母", "注音符号",
- "拼 音", "日文平假名",
- "日文片假名","标点符号",
- "数字序号", "数学符号",
- "单位符号", "制 表 符",
- "特殊符号",
- };
- CHAR SKLayout[NumsSK][48*2+1] = {
- " 0123456789abcdefghijklmnopqrstuvwxyz;=,-./`[\]'",
- " κχυμγνξοθπρ ωψι αδλεηφβτζσ ",
- " лъшнвопржстуьызиагмдёщбчецф э юя й кх",
- " ㄦㄉ ㄓ ㄚㄞㄢㄇㄖㄏㄎㄍㄑㄕㄘㄛㄨㄜㄠㄩㄙㄟㄣㄆㄐㄋㄔㄧㄒㄊ ㄗㄈㄤ ㄝ ㄡㄥㄅ ",
- " ē ǔěǎè īǒíǐìǘǖò āàé óùáúōū ǚ ǜü ê ",
- " ぃぅぇぉかきくけこなもむぬすねのはつひふへゅゃってさせにそちめしみたまほ ょんゎをぁと ゐゑ",
- " ケィゥヴェォカヵキクナモムヌスネノハツヒフヘュャッテサセニソチメシミタマホコョヶヮヲァトンヰヱ",
- " ˉ,、;:?!…—·〔(【〈“〉《》∶「」『[)"'‘”〕々‖】’〗~〖』¨]ˇ{}。`〃|.",
- " ⅪⅡⅢⅣⅤⅥⅦⅧⅨⅩ㈠⑸⑶㈢⒊㈣㈤㈥⒏㈦㈧㈨⑺⑹⒐⒑⒈⒋㈡⒌⒎⑷⒉⑵⒍⑴㈩ ⑻Ⅻ⑼⑽Ⅰ ",
- " ≡≠=≤≥<>≮≯∧⊙∠∑-∏∪∩∫∈ ∵∽≌∮∝±×∨÷ ⌒+∥/⊥∴ ∷√ ≈∞ ",
- " ¤°′″$£¥‰%℃百 毫万二亿兆吉七太拍艾 八九○三千四六微一厘五分 ¢ 十 ",
- " ┄┍┎┏┐┑┒┓ ─┬╀┾┮┞┯┰┱┣┲┳ ╂╁ │├┟┭┠┢┿┝┽┡┼ ╃┈ ┌┆ ┊ ",
- " ■^@▲☆※→←◇↑↓〓 ̄_◆□§★△○◎\№&●# ",
- " ",
- };
- CHAR SKLayoutS[NumsSK][48*2+1] = {
- " ) ! @ # $ % ^ & * ( A B C D E F G H I J K L M N O P Q R S T U V W X Y Z : + < _ > ? ~ { | } " ",
- " ΚΧΥΜΓΝΞΟΘΠΡ ΩΨΙ ΑΔΛΕΗΦΒΤΖΣ ",
- " ЛЪШНВОПРЖСТУЬЫЗИАГМДЁЩБЧЕЦФ Э ЮЯ Й КХ",
- " ",
- " ",
- " いうえおがぎぐげごぱろるぷずぺぽぼづびぶべゆや でざぜぴぞぢれじりだらぼ よ わ あど ",
- " ゲイウ エオガ ギグパロルプズペポバヅビブベユヤ デザゼピゾヂレジリダラボゴヨ ワ アド ",
- " ",
- " ①⒂⒀③⒔④⑤⑥⒙⑦⑧⑨⒄⒃⒚⒛⒒⒕②⒖⒘⒁⒓⑿⒗⑾⑩ ⒅ ⒆⒇ ",
- " ",
- " 佰 贰 柒 捌玖零叁仟肆陆 壹 伍 拾 ",
- " ┅┕┖┗┘┙┚┛ ━┴╈╆┶┦┷┸┹┫┺┻ ╊╉ ┃┤┧┵┨┪╇┥╅┩╄ ╋┉ └┇ ┋ ",
- " ",
- " ",
- };
- BYTE VirtKey48Map[48] = {
- 0x20, 0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37, 0x38,
- 0x39, 0x41, 0x42, 0x43, 0x44, 0x45, 0x46, 0x47, 0x48, 0x49,
- 0x4a, 0x4b, 0x4c, 0x4d, 0x4e, 0x4f, 0x50, 0x51, 0x52, 0x53,
- 0x54, 0x55, 0x56, 0x57, 0x58, 0x59, 0x5a, 0xba, 0xbb, 0xbc,
- 0xbd, 0xbe, 0xbf, 0xc0, 0xdb, 0xdc, 0xdd, 0xde
- };
- CIMESoftKbd::CIMESoftKbd()
- {
- CurentKbdNum=0;
- showflage=0;
- mSelID=0;
- CIMEhSoftKbdWnd=NULL;
- Curhimc=NULL;
- savhimc=NULL;
- }
- HWND CIMESoftKbd::initalize(DWORD himc)
- {
- LPINPUTCONTEXT lpIMC;
- savhimc=himc;
- if (!(lpIMC = ImmLockIMC(himc)))//锁存数据
- return 0;
- CIMEhSoftKbdWnd=CreateSoftKbd(lpIMC->hWnd);
- ImmUnlockIMC(himc);
- return CIMEhSoftKbdWnd;
- }
- HWND CIMESoftKbd:: CreateSoftKbd(HWND hUIWnd)
- {
- static int flage=0;
- POINT pt;
- HWND LhSoftKbd;
- RECT FullWin;
- SystemParametersInfo(SPI_GETWORKAREA,0, &FullWin,0);
- pt.y=FullWin.bottom-140;
- pt.x=FullWin.right-360;//使窗口在右下角显示
- //LhSoftKbd=ImmCreateSoftKeyboard(SOFTKEYBOARD_TYPE_C1,hUIWnd,pt.x,pt.y);
- LhSoftKbd=ImmCreateSoftKeyboard(SOFTKEYBOARD_TYPE_C1,0,pt.x,pt.y);//切断与主窗口的联系,防止释放软键盘时出错。
- if(LhSoftKbd!=NULL)
- ImmShowSoftKeyboard(LhSoftKbd,SW_HIDE);//SW_HIDE
- return LhSoftKbd;
- }
- CIMESoftKbd::~CIMESoftKbd( )
- {
- if(CIMEhSoftKbdWnd!=NULL){
- LPINPUTCONTEXT lpIMC;
- if (!(lpIMC = ImmLockIMC(Curhimc)))//锁存数据
- {
- return ;
- }
- // char ss[100];sprintf(ss,"dd:%d ,%d",CIMEhSoftKbdWnd,lpIMC);
- //MessageBox(0,ss,0,0);
- //ImmShowSoftKeyboard(CIMEhSoftKbdWnd,SW_SHOW);//SW_HIDE
- ImmDestroySoftKeyboard(CIMEhSoftKbdWnd);
- ImmUnlockIMC(Curhimc);
- }
- //MessageBox(0,ss,0,0);
- //CIMEhSoftKbdWnd=NULL;
- }
- /* SetSoftKbdData() */
- /**********************************************************************/
- void CIMESoftKbd::SetSoftKbdData(int NUM)
- {
- int i;
- LPSOFTKBDDATA lpSoftKbdData;
- HGLOBAL hsSoftKbdData;
- char ss[500];
- if(CIMEhSoftKbdWnd==NULL)
- return;
- CurentKbdNum=NUM;
- hsSoftKbdData = GlobalAlloc(GHND, sizeof(SOFTKBDDATA) * 2);
- if (!hsSoftKbdData)
- return;
- lpSoftKbdData = (LPSOFTKBDDATA)GlobalLock(hsSoftKbdData);
- if (!lpSoftKbdData)
- return;
- lpSoftKbdData->uCount = 2;
- for (i = 0; i < 48; i++) {
- BYTE bVirtKey;
- bVirtKey = VirtKey48Map[i];
- if (!bVirtKey)
- continue;
- {
- WORD CHIByte, CLOByte;
- CHIByte = SKLayout[NUM][i*2] & 0x00ff;
- CLOByte = SKLayout[NUM][i*2 + 1] & 0x00ff;
- lpSoftKbdData->wCode[0][bVirtKey] = (CHIByte << 8) | CLOByte;
-
- CHIByte = SKLayoutS[NUM][i*2] & 0x00ff;
- CLOByte = SKLayoutS[NUM][i*2 + 1] & 0x00ff;
- lpSoftKbdData->wCode[1][bVirtKey] = (CHIByte << 8) | CLOByte;
- }
- }
- SendMessage(CIMEhSoftKbdWnd, WM_IME_CONTROL, IMC_SETSOFTKBDDATA, (LPARAM)lpSoftKbdData);
- sprintf(ss,"%s%s",SKLayout[NUM],SKLayoutS[NUM]);
- SetWindowText(CIMEhSoftKbdWnd,ss);
- GlobalUnlock(hsSoftKbdData);
- GlobalFree(hsSoftKbdData);
- return;
- }
- void CIMESoftKbd::ShowSoftKbd()
- {
- char wintxt[500]="";
- try{
- if(CIMEhSoftKbdWnd==NULL)
- {
- LPINPUTCONTEXT lpIMC;
- if (!(lpIMC = ImmLockIMC(Curhimc)))//锁存数据
- {
- sprintf(wintxt,"%d",Curhimc);
- MessageBox(0,"CIMEhSoftKbdWnd=NULL",wintxt,0);
- return ;
- }
- CIMEhSoftKbdWnd=CreateSoftKbd(lpIMC->hWnd);
- ImmUnlockIMC(Curhimc);
- }
- if(CIMEhSoftKbdWnd==NULL)
- return;
- if(!IsWindow(CIMEhSoftKbdWnd))
- {
- char ss[100];
- sprintf(ss,"%x ",*CIMEhSoftKbdWnd);
- MessageBox(0,"CIMEhSoftKbdWnd NoWind",ss,0);
- return;
- }
- GetWindowText(CIMEhSoftKbdWnd,wintxt,10);
- if(wintxt[0]==0)
- {
- showflage=1;
- SetSoftKbdData(CurentKbdNum);
- ImmShowSoftKeyboard(CIMEhSoftKbdWnd,SW_SHOWNOACTIVATE);
- }
- else
- {
- showflage=0;
- ImmShowSoftKeyboard(CIMEhSoftKbdWnd,SW_HIDE);
- SetWindowText(CIMEhSoftKbdWnd,"");
- }
- } catch (...) {
- MessageBox(0,"CIMEhSoftKbdWnd","有错误发生",0);
- }
- }
- void CIMESoftKbd::ShowNextSoftKbd()
- {
- if(CIMEhSoftKbdWnd==NULL)
- return;
- CurentKbdNum++;
- if(showflage==1)
- {
- SetSoftKbdData(CurentKbdNum);
- ImmShowSoftKeyboard(CIMEhSoftKbdWnd,SW_SHOWNOACTIVATE);
- }
- }
- long CIMESoftKbd::SelID()
- {
- return mSelID;
- }
- //返回所选菜单项
- long CIMESoftKbd::Popup()
- {
- long iMenu, nMenus,result;
- POINT p ;
- //char ss[100];
- char buffer [256]="";
- long flag=0;
- HMENU hMenu;
- GetCursorPos(&p);
- hMenu = CreatePopupMenu();
- nMenus = 13;
- for(iMenu = 0 ;iMenu<nMenus;iMenu++)
- {
- flag=0;
- if(CurentKbdNum==iMenu)
- flag|=MF_CHECKED;
- if(iMenu==7)
- flag|=MF_ENABLED|MF_MENUBREAK|MF_MENUBARBREAK;
- else
- flag|=MF_ENABLED;
-
- AppendMenu (hMenu, flag, iMenu+1, SKLayoutName[iMenu]);
- if(iMenu!=6)
- AppendMenu (hMenu, MF_SEPARATOR, iMenu, "");
- }
- iMenu = TrackPopupMenu(hMenu, TPM_RIGHTBUTTON + TPM_LEFTALIGN + TPM_NONOTIFY + TPM_RETURNCMD, p.x, p.y, 0, GetForegroundWindow(), 0);
- //得到菜单的选择字符串
- result = GetMenuString(hMenu, (iMenu - 1), buffer, strlen(buffer), MF_BYPOSITION);
-
- DestroyMenu(hMenu);
- if(iMenu>0)
- {
- ImmShowSoftKeyboard(CIMEhSoftKbdWnd,SW_HIDE);
- SetSoftKbdData(13);
- SetSoftKbdData(iMenu-1);
- ImmShowSoftKeyboard(CIMEhSoftKbdWnd,SW_SHOWNOACTIVATE);
- }
- mSelID = iMenu;
- return mSelID;
- }