dll.cpp
上传用户:hyb6888
上传日期:2016-01-24
资源大小:5186k
文件大小:9k
- // dll.cpp : Defines the initialization routines for the DLL.
- //
- #include "stdafx.h"
- #include "dll.h"
- #include "windows.h"
- #include "string.h"
- #include "stdio.h"
- #include "CMyWnd.h"
- HINSTANCE savehInstDLL;
- #define MYLIBAPI extern "C" __declspec(dllexport)
- int MyMoveWin(CMyWnd *cmywnd,HWND hWnd ,long x,long y);
- MYLIBAPI int SetShowString(long *fcmywnd,char*MindleStr,char*InputStr);
- #ifdef _DEBUG
- #define new DEBUG_NEW
- #undef THIS_FILE
- static char THIS_FILE[] = __FILE__;
- #endif
- //
- // Note!
- //
- // If this DLL is dynamically linked against the MFC
- // DLLs, any functions exported from this DLL which
- // call into MFC must have the AFX_MANAGE_STATE macro
- // added at the very beginning of the function.
- //
- // For example:
- //
- // extern "C" BOOL PASCAL EXPORT ExportedFunction()
- // {
- // AFX_MANAGE_STATE(AfxGetStaticModuleState());
- // // normal function body here
- // }
- //
- // It is very important that this macro appear in each
- // function, prior to any calls into MFC. This means that
- // it must appear as the first statement within the
- // function, even before any object variable declarations
- // as their constructors may generate calls into the MFC
- // DLL.
- //
- // Please see MFC Technical Notes 33 and 58 for additional
- // details.
- //
- /////////////////////////////////////////////////////////////////////////////
- // CDllApp
- BEGIN_MESSAGE_MAP(CDllApp, CWinApp)
- //{{AFX_MSG_MAP(CDllApp)
- // NOTE - the ClassWizard will add and remove mapping macros here.
- // DO NOT EDIT what you see in these blocks of generated code!
- //}}AFX_MSG_MAP
- END_MESSAGE_MAP()
- /////////////////////////////////////////////////////////////////////////////
- // CDllApp construction
- CDllApp theApp;
- /////////////////////////////////////////////////////////////////////////////
- // The one and only CDllApp object
- CDllApp::CDllApp()
- {
- // TODO: add construction code here,
- // Place all significant initialization in InitInstance
- }
- ///////////////////////////////////////////////////////
- //在VB中可通过传值得到
- MYLIBAPI int CloseWin(long *fcmywnd)
- {
- CMyWnd *cmywnd;
- if(*fcmywnd==0)
- {
- //MessageBox(0,"CloseWin致命错误fcmywnd所指对象已释放",0,0);
- return 0;
- }
- cmywnd=(CMyWnd *)*fcmywnd;
- delete(cmywnd);
- cmywnd=0;
- //MessageBox(0,"CloseWin",0,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 int SetWinPosition(long *fcmywnd, HWND hWnd ,long *x ,long *y)
- {
- CMyWnd *cmywnd;
- if(*fcmywnd==0)
- {
- //MessageBox(0,"SetWinPosition致命错误fcmywnd所指对象已释放",0,0);
- return 1;
- }
- cmywnd=(CMyWnd *)*fcmywnd;
- MyMoveWin(cmywnd, hWnd ,*x,*y);
-
- 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 UpdateWinShow(long *fcmywnd)
- {
- CMyWnd *cmywnd;
- if(*fcmywnd==0)
- {
- //MessageBox(0,"UpdateWinShow致命错误fcmywnd所指对象已释放",0,0);
- return 1;
- }
- //MessageBox(0,"UpdateWinShow",0,0);
- cmywnd=(CMyWnd *)*fcmywnd;
- cmywnd->myPaintTxt(0,actSetstr);
- cmywnd->inputWind->myPaintTxt(0,actSetstr);
- cmywnd->ConWind->myPaintTxt(0);
- //////////////////////////////////////////////////////////
- // InvalidateRect(cmywnd->m_hWnd,NULL,FALSE);
- // InvalidateRect(cmywnd->ConWind->m_hWnd,NULL,FALSE);
- // InvalidateRect(cmywnd->inputWind->m_hWnd,NULL,FALSE);
- return 0;
- }
- MYLIBAPI int UpdateWinShowEx(long *fcmywnd)
- {
- CMyWnd *cmywnd;
- long h,w,x,y;
- RECT LoWinRect;
- if(*fcmywnd==0)
- {
- //MessageBox(0,"UpdateWinShow致命错误fcmywnd所指对象已释放",0,0);
- return 1;
- }
- //MessageBox(0,"UpdateWinShow",0,0);
- cmywnd=(CMyWnd *)*fcmywnd;
- cmywnd->myPaintTxt(0,actSetstr);
- cmywnd->inputWind->myPaintTxt(0,actSetstr);
- cmywnd->ConWind->myPaintTxt(0);
- //////////////////////////////////////////////////////////
- GetWindowRect(cmywnd->m_hWnd,&LoWinRect);
- w=LoWinRect.right-LoWinRect.left;
- h=LoWinRect.bottom-LoWinRect.top;
- x=LoWinRect.left;
- y=LoWinRect.top;
- MoveWindow(cmywnd->m_hWnd,x,y,w+1,h,TRUE);
- MoveWindow(cmywnd->m_hWnd,x,y,w,h,TRUE);
- InvalidateRect(cmywnd->m_hWnd,NULL,FALSE);
- GetWindowRect(cmywnd->ConWind->m_hWnd,&LoWinRect);
- w=LoWinRect.right-LoWinRect.left;
- h=LoWinRect.bottom-LoWinRect.top;
- x=LoWinRect.left;
- y=LoWinRect.top;
- MoveWindow(cmywnd->ConWind->m_hWnd,x,y,w+1,h,TRUE);
- MoveWindow(cmywnd->ConWind->m_hWnd,x,y,w,h,TRUE);
- InvalidateRect(cmywnd->ConWind->m_hWnd,NULL,FALSE);
- GetWindowRect(cmywnd->inputWind->m_hWnd,&LoWinRect);
- w=LoWinRect.right-LoWinRect.left;
- h=LoWinRect.bottom-LoWinRect.top;
- x=LoWinRect.left;
- y=LoWinRect.top;
- MoveWindow(cmywnd->inputWind->m_hWnd,x,y,w+1,h,TRUE);
- MoveWindow(cmywnd->inputWind->m_hWnd,x,y,w,h,TRUE);
- // InvalidateRect(cmywnd->inputWind->m_hWnd,NULL,FALSE);
- return 0;
- }
- MYLIBAPI int SetShowString(long *fcmywnd,char*MindleStr,char*InputStr)
- {
- static int nullflag=0;
- CMyWnd *cmywnd;
- if(*fcmywnd==0)
- {
- //MessageBox(0,"SetShowString致命错误fcmywnd所指对象已释放",0,0);
- return 1;
- }
- cmywnd=(CMyWnd *)*fcmywnd;
- cmywnd->settxt(MindleStr);
- if(InputStr!=NULL)
- strcpy(cmywnd->inputWind->showtxt,InputStr);
- else
- cmywnd->inputWind->showtxt[0]=0;
- cmywnd->myPaintTxt(0,actSetstr);
- cmywnd->inputWind->myPaintTxt(0,actSetstr);
- /*
- if(ss!=NULL)
- {
- len=strlen(ss);
- for(i=0;i<len;i++)
- cmywnd->showtxt[i]=ss[i];
- cmywnd->showtxt[i]=0;
- }
- else
- cmywnd->showtxt[i]=0;
- */
- 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);
- }
- 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;
- }
- ///////////////////////////////////////////////////////////
- MYLIBAPI long myCreate(char* szClassName, char* szTitle, HWND hWndParent)
- {
- CMyWnd *cmywnd=NULL;
- //cmywnd=new CMyWnd;
- //MessageBox(0,"myCreate",0,0);
- //cmywnd->Create (szClassName, szTitle, theApp.m_hInstance, hWndParent, WS_POPUP);
- return (long)cmywnd;
- }
- //////////////////////////////////////////////////////////////////////////////
- //内部函数
- int MyMoveWin(CMyWnd *cmywnd,HWND hWnd ,long x,long y)
- {
- RECT FullWinRect,LoWinRect,ParentWinRect;
- long h,w;
- GetWindowRect(GetDesktopWindow(),&FullWinRect);
- GetWindowRect(cmywnd->m_hWnd,&LoWinRect);
- GetWindowRect(hWnd,&ParentWinRect);
- 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+40;
- //如果座标远离窗口时才移动。
- if(LoWinRect.left-x>60 || LoWinRect.left-x<-60 || LoWinRect.top!=y )
- {
- if(x<FullWinRect.left )
- x=FullWinRect.left;
- if( x>FullWinRect.right-w )
- x=FullWinRect.right-w;
- if( y<FullWinRect.top )
- y=FullWinRect.top;
- if(y>FullWinRect.bottom-h)
- y=FullWinRect.bottom-h;
- MoveWindow(cmywnd->m_hWnd,x,y,w,h,TRUE);
- SetWindowPos(cmywnd->inputWind->m_hWnd, 0, x,y,0, 0, 21); //SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOZORDER //16/1/4
- // SetWindowPos(cmywnd->ConWind->m_hWnd, 0, x,y,0, 0, 21); //SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOZORDER //16/1/4
- }
- return 0;
- }