您的位置:首页 > Web前端

多功能输入法前端设计与实现(总)

2008-06-16 23:15 381 查看
目前的输入法可以分为两种,一种是外挂式的,一种是以dll为接口的输入法。这篇笔记讨论的主题主要是围绕外挂式的输入法的前端设计与实现。主要解决的问题:包括位图的导出和转换,右键弹出菜单实现与功能选择,窗口的贴图,属性表的显示实现,窗口移动实现,字体选择和窗体的颜色下面的代码是为一个简单的窗口实现,这窗口主要解决窗口移动,右键菜单,还有一些字体选择和窗口颜色变化
//透明色.cpp:Definestheentrypointfortheapplication.

//

#include"stdafx.h"

#include"resource.h"

#include"config.h"

#include<prsht.h>

#include<commctrl.h>

#include<pshpack1.h>

#include<crtdbg.h>

#include"shellapi.h"

#pragmacomment(lib,"comctl32.lib")

#pragmacomment(lib,"shell32.lib")

#defineMAX_LOADSTRING100

#pragmacomment(lib,"comctl32.lib")

//GlobalVariables:

HINSTANCEhInst;

HWNDhInputWnd;

TCHARszTitle[MAX_LOADSTRING];								//Thetitlebartext

TCHARszWindowClass[MAX_LOADSTRING];								//Thetitlebartext

//Fowarddeclarationsoffunctionsincludedinthiscodemodule:

ATOM				MyRegisterClass(HINSTANCEhInstance);

BOOL				InitInstance(HINSTANCE,int);

LRESULTCALLBACK	WndProc(HWND,UINT,WPARAM,LPARAM);

LRESULTCALLBACK	About(HWND,UINT,WPARAM,LPARAM);

voidStand_TrackPopupMenu(HWNDhWnd,WPARAMwParam,LPARAMlParam);//右键弹出菜单

voidStand_Move(HWNDhWnd,WPARAMwParam,LPARAMlParam);//窗口移动

voidStand_ONLBUTTONDOWN(HWNDhWnd,WPARAMwParam,LPARAMlParam);//按钮按下的时候

voidStand_onBUTONUP(HWNDhWnd,WPARAMwParam,LPARAMlParam);

//////////////////////////////////////////////////////////////////////

intAPIENTRYWinMain(HINSTANCEhInstance,

HINSTANCEhPrevInstance,

LPSTRlpCmdLine,

intnCmdShow)

{

//TODO:Placecodehere.

MSGmsg;

HACCELhAccelTable;

//	//Initializeglobalstrings

LoadString(hInstance,IDS_APP_TITLE,szTitle,MAX_LOADSTRING);

LoadString(hInstance,IDC_MY,szWindowClass,MAX_LOADSTRING);

MyRegisterClass(hInstance);

//Performapplicationinitialization:

if(!InitInstance(hInstance,nCmdShow))

{

returnFALSE;

}

hAccelTable=LoadAccelerators(hInstance,(LPCTSTR)IDC_MY);

//Mainmessageloop:

while(GetMessage(&msg,NULL,0,0))

{

if(!TranslateAccelerator(msg.hwnd,hAccelTable,&msg))

{

TranslateMessage(&msg);

DispatchMessage(&msg);

}

}

returnmsg.wParam;

}

ATOMMyRegisterClass(HINSTANCEhInstance)

{

WNDCLASSEXwcex;

wcex.cbSize=sizeof(WNDCLASSEX);

wcex.style			=CS_HREDRAW|CS_VREDRAW;

wcex.lpfnWndProc	=(WNDPROC)WndProc;

wcex.cbClsExtra		=0;

wcex.cbWndExtra		=0;

wcex.hInstance		=hInstance;

wcex.hIcon			=NULL;

wcex.hCursor		=NULL;

wcex.hbrBackground	=(HBRUSH)(COLOR_WINDOW+1);

wcex.lpszMenuName	=NULL;

wcex.lpszClassName	=szWindowClass;

wcex.hIconSm		=NULL;

returnRegisterClassEx(&wcex);

}

BOOLInitInstance(HINSTANCEhInstance,intnCmdShow)

{

//HWNDhWnd;

//hWnd=hInputWnd;

hInst=hInstance;

hInputWnd=CreateWindow(szWindowClass,

"ds",

WS_POPUP|WS_DISABLED,

500,

500,

300,

42,

NULL,

NULL,

hInst,

NULL);

if(!hInputWnd)

{

returnFALSE;

}

ShowWindow(hInputWnd,nCmdShow);

UpdateWindow(hInputWnd);

returnTRUE;

}

LRESULTCALLBACKWndProc(HWNDhWnd,UINTmessage,WPARAMwParam,LPARAMlParam)

{

intwmId,wmEvent;

PAINTSTRUCTps;

HDChdc;

TCHARszHello[MAX_LOADSTRING];

LoadString(hInst,IDS_HELLO,szHello,MAX_LOADSTRING);

switch(message)

{

caseWM_COMMAND:

{	wmId=LOWORD(wParam);

wmEvent=HIWORD(wParam);

switch(wmId)

{

caseIDM_ABOUT:

DialogBox(hInst,(LPCTSTR)IDD_ABOUTBOX,hWnd,(DLGPROC)About);

break;

caseIDM_EXIT:

DestroyWindow(hWnd);

break;

caseIDM_HELP:

DoPropertySheet(hWnd);

break;

caseIDM_WENDANG:

//MessageBox(NULL,"ds","ds",MB_OK);

ShellExecute(NULL,"open","Help.chm",NULL,NULL,SW_SHOWNORMAL);

break;

default:

returnDefWindowProc(hWnd,message,wParam,lParam);

}

}

break;

caseWM_RBUTTONDOWN:

{

Stand_TrackPopupMenu(hWnd,wParam,lParam);//实现右键菜单

}

break;

caseWM_SETCURSOR:

{

Stand_ONLBUTTONDOWN(hWnd,wParam,lParam);

}

break;

caseWM_LBUTTONUP:

{

Stand_onBUTONUP(hWnd,wParam,lParam);

}

break;

caseWM_MOUSEMOVE:

{

Stand_Move(hWnd,wParam,lParam);

}

break;

caseWM_PAINT:

{

hdc=BeginPaint(hWnd,&ps);

Stand_onPaint(hWnd,hdc);

EndPaint(hWnd,&ps);

}

break;

caseWM_DESTROY:

PostQuitMessage(0);

break;

default:

returnDefWindowProc(hWnd,message,wParam,lParam);

}

return0;

}

LRESULTCALLBACKAbout(HWNDhDlg,UINTmessage,WPARAMwParam,LPARAMlParam)

{

switch(message)

{

caseWM_INITDIALOG:

returnTRUE;

caseWM_COMMAND:

if(LOWORD(wParam)==IDOK||LOWORD(wParam)==IDCANCEL)

{

EndDialog(hDlg,LOWORD(wParam));

returnTRUE;

}

break;

}

returnFALSE;

}

//////////////////////////////////////////////////////////////////////////

//右键菜单实现

voidStand_TrackPopupMenu(HWNDhWnd,WPARAMwParam,LPARAMlParam)

{

HMENUhMenu;

HMENUhsubmenu;

intcmd;

hMenu=LoadMenu(hInst,MAKEINTRESOURCE(IDR_MENU1));

hsubmenu=GetSubMenu(hMenu,0);

POINTpt;

pt.x=LOWORD(lParam);//

pt.y=HIWORD(lParam);//

ClientToScreen(hWnd,&pt);

cmd=TrackPopupMenu(hsubmenu,TPM_RIGHTBUTTON,pt.x,pt.y,0,hWnd,NULL);

switch(cmd)

{

caseIDM_EXIT:

DestroyWindow(hWnd);

break;

caseIDM_ABOUT:

DialogBox(hInst,(LPCTSTR)IDD_ABOUTBOX,hWnd,(DLGPROC)About);

break;

caseIDM_HELP:

DoPropertySheet(hWnd);

break;

caseIDM_WENDANG:

ShellExecute(hWnd,"open","Help.chm",NULL,NULL,SW_SHOWNORMAL);

break;

}

}

//////////////////////////////////////////////////////////////////////////

//创建一个填涂区//////////////////////////////////////////////////////////

voidStand_onPaint(HWNDhWnd,HDChdc)

{

HPENhPen;//定义一支笔

HBRUSHhBrush;//创建一个画刷

charoutput[32];

hBrush=CreateSolidBrush(SetMyview.WndColor);//创建一个填充填充色TheCreateSolidBrushfunctioncreatesalogicalbrushthathasthespecifiedsolidcolor

SelectObject(hdc,hBrush);

hPen=CreatePen(PS_SOLID,6,RGB(255,255,1));//利用这个函数创建一个RGB是这个的的实线画笔*/

Rectangle(hdc,0,0,300,42);//画一个矩形

SelectObject(hdc,hPen);

SetTextColor(hdc,SetMyview.FontColor);

SelectObject(hdc,SetMyview.hfont);//选择字体种类

sprintf(output,"%s","SuCCess");

TextOut(hdc,10,10,output,strlen(output));//输出一个字先

DeleteObject(hPen);

DeleteObject(hBrush);

}

//更新窗口,要指明那个窗口要更新

voidUpdateInputWnd()

{

ShowWindow(hInputWnd,SW_SHOWNA);

HDChdc=GetDC(hInputWnd);

Stand_onPaint(hInputWnd,hdc);

ReleaseDC(hInputWnd,hdc);

}

//////////////////////////////////////////////////////////////////////////

//窗口移动,捕捉鼠标///////////////////////////////////////////////////////////////

staticBOOLfMove=FALSE;//判断是否移动

staticRECTinRect,drect;

staticSIZE		sz;

staticPOINTpwnd;//

voidStand_ONLBUTTONDOWN(HWNDhWnd,WPARAMwParam,LPARAMlParam)

{

POINTpt;

HDChdc=GetDC(hWnd);

if(HIWORD(lParam)==WM_LBUTTONDOWN)

{

SetCapture(hWnd);	//捕捉鼠标

GetCursorPos(&pt);//获得当前鼠标坐标位置

GetWindowRect(hWnd,&drect);//获得当前窗口矩形

inRect.left=drect.left;

inRect.top=drect.top;

inRect.right=drect.right;

inRect.bottom=drect.bottom;

pwnd.x=pt.x-drect.left;////计算鼠标坐标与矩形左上角x坐标的距离初始化第一个位置

pwnd.y=pt.y-drect.top;////计算鼠标坐标与矩形左上角Y坐标的距离

sz.cx=inRect.right-inRect.left;

sz.cy=inRect.bottom-inRect.top;

fMove=TRUE;

}

elseif(HIWORD(lParam)==WM_RBUTTONDOWN)

{

SetCapture(hWnd);

}

}

//移动

voidStand_onBUTONUP(HWNDhWnd,WPARAMwParam,LPARAMlParam)

{

POINTpt;

ReleaseCapture();

if(fMove)

{

//MessageBox(NULL,"ds","dsd",MB_OK);

GetCursorPos(&pt);

MoveWindow(hWnd,pt.x-pwnd.x,pt.y-pwnd.y,sz.cx,sz.cy,TRUE);//当前位置减去之前的位置,从而得到了移动后的距离位置

}

fMove=FALSE;

}

//计算移动窗口

voidStand_Move(HWNDhWnd,WPARAMwParam,LPARAMlParam)

{

POINTpt;

if(fMove)

{

GetCursorPos(&pt);

drect.left=pt.x-pwnd.x;

drect.top=pt.y-pwnd.y;

drect.right=inRect.left+sz.cx;

drect.bottom=inRect.top+sz.cy;

}

}

[/code]

#include"StdAfx.h" #include"config.h" #include"resource.h" #include"prsht.h" #include<commctrl.h> #include<pshpack1.h> #include<crtdbg.h> #include"Commdlg.h" #pragmacomment(lib,"comctl32.lib") SetViewSetMyview; HINSTANCEhInst1; #pragmacomment(lib,"comctl32.lib") //***************************************************// //弹出对话框 HFONTCreateMyFont() { CHOOSEFONTcf; LOGFONTlf; HFONThfont; cf.lStructSize =sizeof(CHOOSEFONT); cf.hwndOwner =(HWND)NULL; cf.hDC =(HDC)NULL; cf.lpLogFont =&lf; cf.iPointSize =0; cf.Flags =CF_SCREENFONTS; cf.rgbColors =RGB(0,0,0); cf.lCustData =0L; cf.lpfnHook =(LPCFHOOKPROC)NULL; cf.lpTemplateName=(LPSTR)NULL; cf.hInstance =(HINSTANCE)NULL; cf.lpszStyle =(LPSTR)NULL; cf.nFontType =SCREEN_FONTTYPE; cf.nSizeMin =0; cf.nSizeMax =0; if(ChooseFont(&cf)) { hfont=CreateFontIndirect(cf.lpLogFont); return(hfont); } else { return(HFONT)NULL; } } //选择字体颜色,返回选择后的颜色值,这个颜色值给窗口和字体 COLORREFChooseMyColor(HWNDhWnd) { CHOOSECOLOR cc; COLORREF acrCustClr[16]; DWORD rgbCurrent; rgbCurrent=RGB(255,255,255); ZeroMemory(&cc,sizeof(cc)); cc.lStructSize=sizeof(cc); cc.hwndOwner=hWnd; cc.lpCustColors=(LPDWORD)acrCustClr; cc.rgbResult=rgbCurrent; cc.Flags=CC_FULLOPEN|CC_RGBINIT; if(ChooseColor(&cc)==TRUE) { rgbCurrent=cc.rgbResult; } returnrgbCurrent; } //设置一个范围,这个是范围是用于 voidInitSlider(HWNDhWnd,UINTuValue) { SendMessage(hWnd,TBM_SETRANGE,(WPARAM)TRUE,(LPARAM)MAKELONG(0,100)); //初始化范围 SendMessage(hWnd,TBM_SETPAGESIZE,(WPARAM)TRUE,(LPARAM)5); SendMessage(hWnd,TBM_SETPOS,(WPARAM)TRUE,(LPARAM)100); } BOOLWINAPIFirst(HWNDhWnd,UINTmessage,WPARAMwParam,LPARAMlParam) { switch(message) { caseWM_CLOSE: DestroyWindow(hWnd); break; caseWM_INITDIALOG: { HWNDhSlider=GetDlgItem(hWnd,IDC_SLIDER1); InitSlider(hSlider,100); SetDlgItemText(hWnd,IDC_EDIT1,"100"); } break; caseWM_COMMAND: { switch(LOWORD(wParam)) { caseIDC_BUTTON1: { SetMyview.hfont=CreateMyFont();//弹出字体对话框调用系统那个 UpdateInputWnd(); } break; caseIDC_BUTTON2: { SetMyview.FontColor=ChooseMyColor(hWnd); UpdateInputWnd(); } break; caseIDC_BUTTON3: { SetMyview.WndColor=ChooseMyColor(hWnd); UpdateInputWnd(); } break; } } break; caseWM_NOTIFY: { switch(((LPNMHDR)lParam)->code) { caseNM_RELEASEDCAPTURE: { staticcharchNumBuff[20]; LONGlResult=SendMessage(((LPNMHDR)lParam)->hwndFrom,TBM_GETPOS,(WPARAM)0,(LPARAM)0); sprintf(chNumBuff,"%ld",lResult); SetDlgItemText(hWnd,IDC_EDIT1,chNumBuff); ShowWindow(hInputWnd,SW_SHOWNA); //TranspanentWindow((int)lResult); } break; } } default: returnDefWindowProc(hWnd,message,wParam,lParam); } return0; } ////////////////////////////////////////////////////////////////////////////////// BOOLWINAPISecond(HWNDhWnd,UINTmessage,WPARAMwParam,LPARAMlParam) { switch(message) { caseWM_CLOSE: DestroyWindow(hWnd); break; default: returnDefWindowProc(hWnd,message,wParam,lParam); } return0; } intDoPropertySheet(HWNDhWnd) { PROPSHEETPAGEpsp[2]; PROPSHEETHEADERpsh; intnRect=-1; psp[0].dwSize=sizeof(PROPSHEETPAGE); psp[0].dwFlags=PSP_USEICONID|PSP_USETITLE; psp[0].hInstance=hInst1; psp[0].pszTemplate=MAKEINTRESOURCE(IDD_DIALOG1); psp[0].pszIcon=NULL; psp[0].pfnDlgProc=(DLGPROC)First; psp[0].pszTitle="常规"; psp[0].lParam=0; psp[0].pfnCallback=NULL; psp[1].dwSize=sizeof(PROPSHEETPAGE); psp[1].dwFlags=PSP_USEICONID|PSP_USETITLE; psp[1].hInstance=hInst1; psp[1].pszTemplate=MAKEINTRESOURCE(IDD_DIALOG2);// psp[1].pszIcon=NULL; psp[1].pfnDlgProc=(DLGPROC)Second; psp[1].pszTitle="热键"; psp[1].lParam=0; psp[1].pfnCallback=NULL; psh.dwSize=sizeof(PROPSHEETHEADER); psh.dwFlags=PSH_USEICONID|PSH_PROPSHEETPAGE|PSH_USEPAGELANG; psh.hwndParent=hWnd; psh.hInstance=hInst1; psh.pszIcon=NULL; psh.pszCaption=(LPSTR)"输入法后台设置"; psh.nPages=sizeof(psp)/sizeof(PROPSHEETPAGE); psh.nStartPage=0; psh.ppsp=(LPCPROPSHEETPAGE)&psp; psh.pfnCallback=NULL; nRect=PropertySheet(&psh); returnnRect; }配置文件:Config.cpp#include"StdAfx.h" #include"config.h" #include"resource.h" #include"prsht.h" #include<commctrl.h> #include<pshpack1.h> #include<crtdbg.h> #include"Commdlg.h" #pragmacomment(lib,"comctl32.lib")SetViewSetMyview; HINSTANCEhInst1; #pragmacomment(lib,"comctl32.lib")//***************************************************////弹出对话框 HFONTCreateMyFont() { CHOOSEFONTcf; LOGFONTlf; HFONThfont; cf.lStructSize=sizeof(CHOOSEFONT); cf.hwndOwner=(HWND)NULL; cf.hDC=(HDC)NULL; cf.lpLogFont=&lf; cf.iPointSize=0; cf.Flags=CF_SCREENFONTS; cf.rgbColors=RGB(0,0,0); cf.lCustData=0L; cf.lpfnHook=(LPCFHOOKPROC)NULL; cf.lpTemplateName=(LPSTR)NULL; cf.hInstance=(HINSTANCE)NULL; cf.lpszStyle=(LPSTR)NULL; cf.nFontType=SCREEN_FONTTYPE; cf.nSizeMin=0; cf.nSizeMax=0; if(ChooseFont(&cf)) { hfont=CreateFontIndirect(cf.lpLogFont); return(hfont); } else { return(HFONT)NULL; } }//选择字体颜色,返回选择后的颜色值,这个颜色值给窗口和字体 COLORREFChooseMyColor(HWNDhWnd) { CHOOSECOLORcc; COLORREFacrCustClr[16]; DWORDrgbCurrent; rgbCurrent=RGB(255,255,255); ZeroMemory(&cc,sizeof(cc)); cc.lStructSize=sizeof(cc); cc.hwndOwner=hWnd; cc.lpCustColors=(LPDWORD)acrCustClr; cc.rgbResult=rgbCurrent; cc.Flags=CC_FULLOPEN|CC_RGBINIT; if(ChooseColor(&cc)==TRUE) { rgbCurrent=cc.rgbResult; } returnrgbCurrent; }//设置一个范围,这个是范围是用于 voidInitSlider(HWNDhWnd,UINTuValue) { SendMessage(hWnd,TBM_SETRANGE,(WPARAM)TRUE,(LPARAM)MAKELONG(0,100));//初始化范围 SendMessage(hWnd,TBM_SETPAGESIZE,(WPARAM)TRUE,(LPARAM)5); SendMessage(hWnd,TBM_SETPOS,(WPARAM)TRUE,(LPARAM)100); }BOOLWINAPIFirst(HWNDhWnd,UINTmessage,WPARAMwParam,LPARAMlParam)
{
switch(message)
{caseWM_CLOSE:
DestroyWindow(hWnd);
break;caseWM_INITDIALOG:
{
HWNDhSlider=GetDlgItem(hWnd,IDC_SLIDER1);
InitSlider(hSlider,100);
SetDlgItemText(hWnd,IDC_EDIT1,"100");}
break;caseWM_COMMAND:
{
switch(LOWORD(wParam))
{caseIDC_BUTTON1:
{
SetMyview.hfont=CreateMyFont();//弹出字体对话框调用系统那个
UpdateInputWnd();
}break;caseIDC_BUTTON2:
{
SetMyview.FontColor=ChooseMyColor(hWnd);
UpdateInputWnd();
}
break;caseIDC_BUTTON3:
{
SetMyview.WndColor=ChooseMyColor(hWnd);
UpdateInputWnd();
}
break;
}}
break;
caseWM_NOTIFY:
{
switch(((LPNMHDR)lParam)->code)
{
caseNM_RELEASEDCAPTURE:
{
staticcharchNumBuff[20];
LONGlResult=SendMessage(((LPNMHDR)lParam)->hwndFrom,TBM_GETPOS,(WPARAM)0,(LPARAM)0);
sprintf(chNumBuff,"%ld",lResult);
SetDlgItemText(hWnd,IDC_EDIT1,chNumBuff);
ShowWindow(hInputWnd,SW_SHOWNA);
//TranspanentWindow((int)lResult);
}
break;
}
}default:
returnDefWindowProc(hWnd,message,wParam,lParam);
}
return0;}//////////////////////////////////////////////////////////////////////////////////
BOOLWINAPISecond(HWNDhWnd,UINTmessage,WPARAMwParam,LPARAMlParam)
{
switch(message)
{caseWM_CLOSE:
DestroyWindow(hWnd);
break;default:
returnDefWindowProc(hWnd,message,wParam,lParam);
}
return0;}intDoPropertySheet(HWNDhWnd)
{PROPSHEETPAGEpsp[2];
PROPSHEETHEADERpsh;
intnRect=-1;
psp[0].dwSize=sizeof(PROPSHEETPAGE);
psp[0].dwFlags=PSP_USEICONID|PSP_USETITLE;
psp[0].hInstance=hInst1;
psp[0].pszTemplate=MAKEINTRESOURCE(IDD_DIALOG1);
psp[0].pszIcon=NULL;
psp[0].pfnDlgProc=(DLGPROC)First;
psp[0].pszTitle="常规";
psp[0].lParam=0;
psp[0].pfnCallback=NULL;psp[1].dwSize=sizeof(PROPSHEETPAGE);
psp[1].dwFlags=PSP_USEICONID|PSP_USETITLE;
psp[1].hInstance=hInst1;
psp[1].pszTemplate=MAKEINTRESOURCE(IDD_DIALOG2);//
psp[1].pszIcon=NULL;
psp[1].pfnDlgProc=(DLGPROC)Second;
psp[1].pszTitle="热键";
psp[1].lParam=0;
psp[1].pfnCallback=NULL;psh.dwSize=sizeof(PROPSHEETHEADER);
psh.dwFlags=PSH_USEICONID|PSH_PROPSHEETPAGE|PSH_USEPAGELANG;
psh.hwndParent=hWnd;
psh.hInstance=hInst1;
psh.pszIcon=NULL;
psh.pszCaption=(LPSTR)"输入法后台设置";
psh.nPages=sizeof(psp)/sizeof(PROPSHEETPAGE);
psh.nStartPage=0;
psh.ppsp=(LPCPROPSHEETPAGE)&psp;
psh.pfnCallback=NULL;
nRect=PropertySheet(&psh);
returnnRect;
}config.h#pragmaonce#defineWIN32_LEAN_AND_MEAN#include"StdAfx.h"
#include"prsht.h"
#include<commctrl.h>
#include<pshpack1.h>
#include<crtdbg.h>#pragmacomment(lib,"comctl32.lib")HFONTCreateMyFont();//创建我的字体
intDoPropertySheet(HWNDhWnd);
BOOLWINAPIFirst(HWNDhWnd,UINTmessage,WPARAMwParam,LPARAMlParam);
BOOLWINAPISecond(HWNDhWnd,UINTmessage,WPARAMwParam,LPARAMlParam);//定义个结构体这个结构是用于设置字体的颜色,字体大小,窗口的背景颜色
typedefstruct_tagSetView
{HFONThfont;//选择字体
COLORREFFontColor;//字体颜色
COLORREFWndColor;//窗口颜色
BOOLSetSkin;//设置皮肤
}SetView;externSetViewSetMyview;externHWNDhInputWnd;
externHINSTANCEhInst1;voidUpdateInputWnd();//更新窗口
voidStand_onPaint(HWNDhWnd,HDChdc);//输出窗口的颜色值


内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: