DLL.CPP
上传用户:hyb6888
上传日期:2016-01-24
资源大小:5186k
文件大小:10k
- // dll.cpp : Defines the entry point for the DLL application.
- //
- #include "stdafx.h"
- #include "windows.h"
- #include "string.h"
- #include "stdio.h"
- #include "stdafx.h"
- #include "CMyWnd.h"
- #include "inputHwnd.h"
- #include "ConHwnd.h"
- #include "string.h"
- HINSTANCE savehInstDLL;
- #include "DllManager.h"
- DllManager ChLib;
- #define MYLIBAPI extern "C" __declspec(dllexport)
- MYLIBAPI int SetShowString(long *fcmywnd,char*MindleStr,char*InputStr);
- MYLIBAPI long GetSoftKbdWnd(long *fcmywnd);
- int MyMoveWin(CMyWnd *cmywnd,HWND hWnd ,long x,long y);
- BOOL GenerateMessage(HIMC hIMC, LPDWORD lpdwTransKey,LPGENEMSG lpGeneMsg);
- BOOL WINAPI DllMain (
- HINSTANCE hInstDLL,
- DWORD dwFunction,
- LPVOID lpNot)
- {
- switch(dwFunction)
- {
- case DLL_PROCESS_ATTACH:
-
- //MessageBox(0,0,0,0);
- savehInstDLL = hInstDLL;
- ChLib.hInstance=hInstDLL;
- break;
- case DLL_PROCESS_DETACH: //当系统结束时释放资源
- //MessageBox(0,"DLL_PROCESS_DETACH",0,0);
- break;
- }
- return TRUE;
- }
- //键盘过滤,0为不过滤
- MYLIBAPI BOOL myImeProcessKey(long *fcmywnd,char *SendCH,char*Control,HIMC hIMC,UINT vKey,LPARAM lKeyData,CONST LPBYTE lpbKeyState)
- {
- CMyWnd *cmywnd;
- BOOL fRet = FALSE;
- try
- {
- if(*fcmywnd==0)
- {
- //MessageBox(0,"GetWinHWND致命错误fcmywnd所指对象已释放",0,0);
- return 0;
- }
- cmywnd=(CMyWnd *)*fcmywnd;
- fRet =cmywnd->myImeProcessKey(SendCH,Control,hIMC,vKey,lKeyData, lpbKeyState);
- } catch (...) {
- MessageBox(0,"SetWinPosition","有错误发生",0);
- }
-
- return fRet;
- }
- ///////////////////////////////////////////////////////////
- MYLIBAPI long myCreate(char* szClassName, char* szTitle, HWND hWndParent,DWORD himc)
- {
- CMyWnd *cmywnd=NULL;
- char ss[100];
- sprintf(ss,"%d",himc);
- //MessageBox(0,"myCreate",ss,0);
- cmywnd=new CMyWnd(himc);
- cmywnd->Create (szClassName, szTitle, savehInstDLL, hWndParent, WS_POPUP);
- return (long)cmywnd;
- }
- ///////////////////////////////////////////////////////
- //在VB中可通过传值得到
- MYLIBAPI int CloseWin(long *fcmywnd)
- {
- char tt[100]="dd";
- CMyWnd *cmywnd;
- try
- {
- if(*fcmywnd==0)
- {
- //MessageBox(0,"CloseWin致命错误fcmywnd所指对象已释放",0,0);
- return 0;
- }
- cmywnd=(CMyWnd *)*fcmywnd;
- //sprintf(tt,"%d",fcmywnd);
- //MessageBox(0,"CloseWin",tt,0);
- delete cmywnd; //此处不释放资源就不会出现致使错误。
- cmywnd=0;
- } catch (...) {
- MessageBox(0,"Error","CloseWin有错误发生",0);
- }
- //如果子类窗口不自行消毁自己的窗口,
- //当主程序退出时子窗口窗口依然在运行,会引起系统崩溃
- return 0;
- }
- MYLIBAPI long GetWinHWND(long *fcmywnd)
- {
- CMyWnd *cmywnd;
- if(*fcmywnd==0)
- {
- //MessageBox(0,"GetWinHWND致命错误fcmywnd所指对象已释放",0,0);
- return 0;
- }
- cmywnd=(CMyWnd *)*fcmywnd;
- return (long)cmywnd->m_hWnd;
- }
- MYLIBAPI long GetSoftKbdWnd(long *fcmywnd)
- {
- CMyWnd *cmywnd;
- if(*fcmywnd==0)
- {
- //MessageBox(0,"GetWinHWND致命错误fcmywnd所指对象已释放",0,0);
- return 0;
- }
- cmywnd=(CMyWnd *)*fcmywnd;
- return (long)cmywnd->ConWind->keyboard->CIMEhSoftKbdWnd;
- }
- //设置主窗口位置
- MYLIBAPI int SetWinPosition(long *fcmywnd, HWND hWnd ,long *x ,long *y)
- {
- CMyWnd *cmywnd;
- try
- {
- if(*fcmywnd==0)
- {
- //MessageBox(0,"SetWinPosition致命错误fcmywnd所指对象已释放",0,0);
- return 1;
- }
- cmywnd=(CMyWnd *)*fcmywnd;
- MyMoveWin(cmywnd, hWnd ,*x,*y);
- } catch (...) {
- MessageBox(0,"SetWinPosition","有错误发生",0);
- }
-
- return 0;
- }
- MYLIBAPI int SetinputPos(long *fcmywnd,long *x ,long *y)
- {
- CMyWnd *cmywnd;
- if(*fcmywnd==0)
- {
- //MessageBox(0,"SetinputPos致命错误fcmywnd所指对象已释放",0,0);
- return 1;
- }
- cmywnd=(CMyWnd *)*fcmywnd;
- SetWindowPos(cmywnd->inputWind->m_hWnd, 0, *x,*y,0, 0, 21); //SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOZORDER //16/1/4
- return 0;
- }
- MYLIBAPI int SetConPosition(long *fcmywnd,long *x ,long *y)
- {
- CMyWnd *cmywnd;
- if(*fcmywnd==0)
- {
- //MessageBox(0,"SetConPosition致命错误fcmywnd所指对象已释放",0,0);
- return 1;
- }
- cmywnd=(CMyWnd *)*fcmywnd;
- SetWindowPos(cmywnd->ConWind->m_hWnd, 0, *x,*y,0, 0, 21); //SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOZORDER //16/1/4
- return 0;
- }
- MYLIBAPI int HideWin(long *fcmywnd)
- {
- CMyWnd *cmywnd;
- if(*fcmywnd==0)
- {
- //MessageBox(0,"HideWin致命错误fcmywnd所指对象已释放",0,0);
- return 1;
- }
- cmywnd=(CMyWnd *)*fcmywnd;
- ShowWindow(cmywnd->m_hWnd, SW_HIDE);
- ShowWindow(cmywnd->inputWind->m_hWnd, SW_HIDE);
- //SetShowString(fcmywnd,"","");
- return 0;
- }
- MYLIBAPI int HideAllWin(long *fcmywnd)
- {
- CMyWnd *cmywnd;
- if(*fcmywnd==0)
- {
- //MessageBox(0,"HideWin致命错误fcmywnd所指对象已释放",0,0);
- return 1;
- }
- cmywnd=(CMyWnd *)*fcmywnd;
- cmywnd->stopflash=1;
- ShowWindow(cmywnd->m_hWnd, SW_HIDE);
- ShowWindow(cmywnd->inputWind->m_hWnd, SW_HIDE);
- ShowWindow(cmywnd->ConWind->m_hWnd, SW_HIDE);
- ShowWindow(cmywnd->myQQWind->m_hWnd, SW_HIDE);
- ShowWindow(cmywnd->ConWind->keyboard->CIMEhSoftKbdWnd, SW_HIDE);
- //SetShowString(fcmywnd,"","");
- return 0;
- }
- MYLIBAPI int UpdateWinShow(long *fcmywnd,DWORD himc)
- {
- CMyWnd *cmywnd;
- // char ss[11];
- try{
- if(*fcmywnd==0)
- {
- //MessageBox(0,"UpdateWinShow致命错误fcmywnd所指对象已释放",0,0);
- return 1;
- }
- cmywnd=(CMyWnd *)*fcmywnd;
- cmywnd->stopflash=0;
- cmywnd->myPaintTxt(0,actSetstr);
- cmywnd->inputWind->myPaintTxt(0,actSetstr);
- cmywnd->ConWind->myPaintTxt(0);
- ShowWindow(cmywnd->ConWind->m_hWnd, SW_SHOWNOACTIVATE);
- if(cmywnd->inputWind->showtxt[0])
- {
- ShowWindow(cmywnd->inputWind->m_hWnd, SW_SHOWNOACTIVATE);
- ShowWindow(cmywnd->m_hWnd, SW_SHOWNOACTIVATE);
- }
- cmywnd->ConWind->keyboard->Curhimc= himc;
- if(cmywnd->ConWind->keyboard->showflage==1)
- {
- if(cmywnd->ConWind->keyboard->CIMEhSoftKbdWnd!=NULL)
- {
- ImmShowSoftKeyboard(cmywnd->ConWind->keyboard->CIMEhSoftKbdWnd,SW_SHOWNOACTIVATE);
- }
- }
- } catch (...) {
- MessageBox(0,"UpdateWinShow","有错误发生",0);
- }
- return 0;
- }
- MYLIBAPI int SetShowString(long *fcmywnd,char*MindleStr,char*InputStr)
- {
- static int nullflag=0;
- CMyWnd *cmywnd;
- try
- {
- if(*fcmywnd==0)
- {
- //MessageBox(0,"SetShowString致命错误fcmywnd所指对象已释放",0,0);
- return 1;
- }
- cmywnd=(CMyWnd *)*fcmywnd;
- cmywnd->stopflash=0;
- cmywnd->settxt(MindleStr);
- {
- int i,len;
- if(InputStr!=NULL)
- {
- len=strlen(InputStr);
- for(i=0;i<len;i++)
- cmywnd->inputWind->showtxt[i]=InputStr[i];
- cmywnd->inputWind->showtxt[i]=0;
- }
- else
- cmywnd->inputWind->showtxt[0]=0;
- }
- /*
- if(InputStr!=NULL)
- strcpy(cmywnd->inputWind->showtxt,InputStr);
- else
- cmywnd->inputWind->showtxt[0]=0;
- */
- cmywnd->myPaintTxt(0,actSetstr);
- cmywnd->inputWind->myPaintTxt(0,actSetstr);
- if(cmywnd->inputWind->showtxt[0]==0)
- nullflag++;
- else
- nullflag=0;
- if(nullflag>1)
- {
- ShowWindow(cmywnd->m_hWnd,SW_HIDE);
- if(nullflag>2)
- ShowWindow(cmywnd->inputWind->m_hWnd,SW_HIDE);
- }
- else
- {
- ShowWindow(cmywnd->m_hWnd,SW_SHOWNOACTIVATE);
- ShowWindow(cmywnd->inputWind->m_hWnd,SW_SHOWNOACTIVATE);
- }
- } catch (...) {
- MessageBox(0,"SetShowString","有错误发生",0);
- }
- return 0;
- }
- MYLIBAPI int SetWinSize(long *fcmywnd,long *Width ,long *Height)
- {
- CMyWnd *cmywnd;
- RECT drc;
- if(*fcmywnd==0)
- {
- //MessageBox(0,"SetWinSize致命错误fcmywnd所指对象已释放",0,0);
- return 1;
- }
- cmywnd=(CMyWnd *)*fcmywnd;
- GetWindowRect(cmywnd->m_hWnd,&drc);
- MoveWindow(cmywnd->m_hWnd,drc.left,drc.top,*Width,*Height,TRUE);
- return 0;
- }
- //////////////////////////////////////////////////////////////////////////////
- // 内部函数
- // 需要类CMyWnd支持
- int MyMoveWin(CMyWnd *cmywnd,HWND hWnd ,long x,long y)
- {
- RECT LoWinRect,ParentWinRect,screenrc;
- long h,w,temy;
- static int savy;;
- int trace;
- //char ss[100];
- //sprintf(ss,"%d",cmywnd->m_hWnd);
- //MessageBox(0,"Main create",ss,0);
- temy=y;
-
- SystemParametersInfo(SPI_GETWORKAREA,0, &screenrc,0);
- GetWindowRect(cmywnd->m_hWnd,&LoWinRect);
- if(IsWindow(hWnd))
- {
- GetWindowRect(hWnd,&ParentWinRect);
- }
- else
- {
- ParentWinRect.right=0;
- ParentWinRect.left=0;
- ParentWinRect.top=0;
- ParentWinRect.bottom=0;
- }
- w=LoWinRect.right-LoWinRect.left;
- h=LoWinRect.bottom-LoWinRect.top;
- if((x>10000 && y>10000)||(x<=0 && y<=0))
- return 0;
- x=x+ParentWinRect.left;
- y=y+ParentWinRect.top+cmywnd->inputWind->ControlHeight;
- //如果座标远离窗口时才移动。
- trace=(int)(cmywnd->myResM.traceflage[0]-'0');
- if(trace<9)
- {
- int t,con;
- trace=trace*20;
- t=LoWinRect.left-x;
- if(t> trace || t<-trace|| savy!=temy )
- {
- savy=temy;
- con=cmywnd->inputWind->ControlHeight;
- if(x<screenrc.left )
- x=screenrc.left;
- if( x>screenrc.right-w)
- x=screenrc.right-w;
- if( y<screenrc.top )
- y=screenrc.top;
- if(y>screenrc.bottom-h-con )
- {
- //y=screenrc.bottom-h;
- y=y-con-h-40;
- MoveWindow(cmywnd->m_hWnd,x,y,w,h,TRUE);
- y=y+h;
- x=x+20;
- MoveWindow(cmywnd->inputWind->m_hWnd,x,y,w,con,TRUE);
- }
- else
- {
- y=y+10;
- MoveWindow(cmywnd->inputWind->m_hWnd,x,y,w,con,TRUE);
- y=y+con;
- MoveWindow(cmywnd->m_hWnd,x,y,w,h,TRUE);
- }
- // SetWindowPos(cmywnd->ConWind->m_hWnd, 0, x,y,0, 0, 21); //SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOZORDER //16/1/4
- }
- }
- return 0;
- }
- /////////////////////////////////////////////////////////////
- //下面为函数部分
- //用于向系统发送消息
- BOOL GenerateMessage(HIMC hIMC, LPDWORD lpdwTransKey,LPGENEMSG lpGeneMsg)
- {
- LPINPUTCONTEXT lpIMC;
- if( (lpIMC = ImmLockIMC(hIMC)) == NULL )
- return FALSE;
-
- if (IsWindow(lpIMC->hWnd))
- {
- LPDWORD lpdw;
- if (!(lpIMC->hMsgBuf = ImmReSizeIMCC(lpIMC->hMsgBuf,
- sizeof(DWORD) * (lpIMC->dwNumMsgBuf +1) * 3)))
- return FALSE;
-
- if (!(lpdw = (LPDWORD)ImmLockIMCC(lpIMC->hMsgBuf)))
- return FALSE;
-
- lpdw += (lpIMC->dwNumMsgBuf) * 3;
- *((LPGENEMSG)lpdw) = *lpGeneMsg;
- ImmUnlockIMCC(lpIMC->hMsgBuf);
- lpIMC->dwNumMsgBuf++;
- ImmGenerateMessage(hIMC);
- }
- ImmUnlockIMC(hIMC);
- return TRUE;
- }