📄 imwnd.cpp
字号:
// IMWnd.cpp: implementation of the CIMWnd class.
//
//////////////////////////////////////////////////////////////////////
#include "stdafx.h"
#include "IMWnd.h"
#include "resource.h"
#include "UserDefinedMessage.h"
#include "Keybd.h"
#include "resource.h"
#include "common.h"
//--------------------------------------------------------------------
//Macro define
#define WINDOW_CLASS TEXT("HWRcognizer_Class")
#define WINDOW_TITLE TEXT("HWRcognizer_Title")
//The taskbar height
#define TASKBAR_HEIGHT_AUTOHIDE 5
#define TASKBAR_HEIGHT 26
#define IMG_IMWND_WIDTH 370
#define IMG_IMWND_HEIGHT 206
//--------------------------------------------------------------------
//Initialize
CIMWnd *CIMWnd::m_pInstance = NULL;
//----------------------------------------------------------------------
//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////
CIMWnd::CIMWnd()
{
m_pIMCallback = NULL;
m_hWnd = NULL;
m_hInst = NULL;
m_hWndSip = NULL;
}
CIMWnd::~CIMWnd()
{
if(m_pInstance != NULL)
{
delete m_pInstance;
m_pInstance = NULL;
}
}
//----------------------------------------------------------------------
//Description:
// Initialize
//----------------------------------------------------------------------
BOOL CIMWnd::Initialize(HINSTANCE hInst, HWND hWndSip)
{
m_hInst = hInst;
m_hWndSip = hWndSip;
UnregisterClass(WINDOW_CLASS,m_hInst);
WNDCLASS wc;
wc.style = CS_VREDRAW | CS_HREDRAW;;
wc.lpfnWndProc = WndProc;
wc.cbClsExtra = 0;
wc.cbWndExtra = 0;
wc.hInstance = hInst;
wc.hIcon = NULL;
wc.hCursor = NULL;
wc.hbrBackground = (HBRUSH)GetStockObject(WHITE_BRUSH);
wc.lpszMenuName = NULL;
wc.lpszClassName = WINDOW_CLASS;
if(RegisterClass(&wc) == 0)
{
WRITELOG("Failed in RegisterClass()");
return FALSE;
}
//Set the window area to suit with the image
RECT rcClientWnd = {0};
GetClientRect (hWndSip, &rcClientWnd);
RECT rcSipWnd = {0};
GetWindowRect(hWndSip,&rcSipWnd);
//It may be the frame for the parent window,so we must hold it.
int iWidth = (rcSipWnd.right - rcSipWnd.left ) - (rcClientWnd.right - rcClientWnd.left) + IMG_IMWND_WIDTH;
int iHeight = (rcSipWnd.bottom - rcSipWnd.top) - (rcClientWnd.bottom - rcClientWnd.top) + IMG_IMWND_HEIGHT;
rcSipWnd.left = SCREEN_WIDTH - iWidth;
rcSipWnd.top = SCREEN_HEIGHT - iHeight - TASKBAR_HEIGHT;
SetWindowPos(hWndSip,hWndSip,rcSipWnd.left,rcSipWnd.top,iWidth,iHeight,NULL);
// Create SIP window.
m_hWnd = CreateWindowEx(0,
WINDOW_CLASS,
WINDOW_TITLE,
WS_CHILD | WS_BORDER ,
rcClientWnd.left,
rcClientWnd.top,
IMG_IMWND_WIDTH,//rcWnd.right - rcWnd.left,
IMG_IMWND_HEIGHT,//rcWnd.bottom - rcWnd.top,
hWndSip,
NULL,
m_hInst,
NULL
);
if(IsWindow(m_hWnd)==FALSE)
{
return FALSE;
}
return TRUE;
}
//----------------------------------------------------------------------
//Description:
// Get the object instance
//----------------------------------------------------------------------
CIMWnd * CIMWnd::GetInstance()
{
if(m_pInstance == NULL)
{
m_pInstance = new CIMWnd();
}
return m_pInstance;
}
//----------------------------------------------------------------------
//Description:
// Window process
//----------------------------------------------------------------------
LRESULT CIMWnd::WndProc(HWND hWnd, UINT wMsg, WPARAM wParam, LPARAM lParam)
{
switch(wMsg)
{
case WM_PAINT:
m_pInstance->OnPaint(hWnd,wMsg,wParam,lParam);
return 0;
case WM_DESTROY:
m_pInstance->OnDestroy(hWnd,wMsg,wParam,lParam);
return 0;
case MYMSG_REGCALLBACK:
m_pInstance->OnRegCallback(hWnd,wMsg,wParam,lParam);
return 0;
case WM_ERASEBKGND:
//Do nothing in order not to flash the window
return 0;
case WM_LBUTTONUP:
m_pInstance->OnLButtonUp(hWnd,wMsg,wParam,lParam);
return 0;
}
return DefWindowProc(hWnd,wMsg,wParam,lParam);
}
//----------------------------------------------------------------------
//Description:
// Destroy the window
//----------------------------------------------------------------------
void CIMWnd::DestroyWindow()
{
::DestroyWindow(m_hWnd);
}
//----------------------------------------------------------------------
//Description:
// Show the window
//----------------------------------------------------------------------
void CIMWnd::ShowWindow(BOOL bShow)
{
if(bShow == TRUE)
{
::ShowWindow(m_hWnd,SW_SHOW);
}
else
{
::ShowWindow(m_hWnd,SW_HIDE);
}
}
//-------------------------------------------------------------------------
//Description:
// On message WM_PAINT
//-------------------------------------------------------------------------
void CIMWnd::OnPaint(HWND hWnd, UINT wMsg, WPARAM wParam, LPARAM lParam)
{
PAINTSTRUCT ps;
HDC hdc = BeginPaint(hWnd,&ps);
//Create a DC that matches the device
HBITMAP hBitmap = CreateCompatibleBitmap(hdc,IMG_IMWND_WIDTH,IMG_IMWND_HEIGHT);
HDC hdcMem = CreateCompatibleDC(hdc);
//Select the bitmap into to the compatible device context
HGDIOBJ hOldSel = SelectObject(hdcMem,hBitmap);
//Create a DC that matches the device
HDC hdcBmp = CreateCompatibleDC(hdc);
//Load the bitmap
HANDLE hBmp= LoadImage(m_hInst,MAKEINTRESOURCE(IDB_IMWND_BIG),IMAGE_BITMAP,0,0,0);
//Select the bitmap into to the compatible device context
HGDIOBJ hOldBmpSel = SelectObject(hdcBmp,hBmp);
//Copy the bitmap image to the memory DC.
BitBlt(hdcMem,0,0,IMG_IMWND_WIDTH,IMG_IMWND_HEIGHT,hdcBmp,0,0,SRCCOPY);
//Draw to the screen
BitBlt(hdc,0,0,IMG_IMWND_WIDTH,IMG_IMWND_HEIGHT,hdcMem,0,0,SRCCOPY);
//Restore original bitmap selection and destroy the memory DC
SelectObject(hdcBmp,hOldBmpSel);
SelectObject(hdcMem,hOldSel);
DeleteObject(hBitmap);
DeleteDC(hdcBmp);
DeleteDC(hdcMem);
EndPaint(hWnd,&ps);
}
//-------------------------------------------------------------------------
//Description:
// On message WM_LBUTTONUP
//-------------------------------------------------------------------------
void CIMWnd::OnLButtonUp(HWND hWnd, UINT wMsg, WPARAM wParam, LPARAM lParam)
{
if(m_pIMCallback != NULL)
{
m_pIMCallback->SendString(TEXT("輸入法測試程序 "),8);
//m_pIMCallback->SendCharEvents(VK_RIGHT,KeyStateDownFlag,1,&wShiftFlags,&wChar);
}
}
//-------------------------------------------------------------------------
//Description:
// On message WM_DESTROY
//-------------------------------------------------------------------------
void CIMWnd::OnDestroy(HWND hWnd, UINT wMsg, WPARAM wParam, LPARAM lParam)
{
DefWindowProc(hWnd,wMsg,wParam,lParam);
}
//----------------------------------------------------------------------------
//Decription:
// Get the handle to the window
//-----------------------------------------------------------------------------
HWND CIMWnd::GetWindow()
{
return m_hWnd;
}
//----------------------------------------------------------------------------
//Decription:
// On message MYMSG_REGCALLBACK
//-----------------------------------------------------------------------------
void CIMWnd::OnRegCallback(HWND hWnd, UINT wMsg, WPARAM wParam, LPARAM lParam)
{
m_pIMCallback = (IIMCallback *)wParam;
}
//----------------------------------------------------------------------------
//Decription:
// On message MSG_USEROPTIONSDLG
//-----------------------------------------------------------------------------
void CIMWnd::ShowUserOptionsDlg(HWND hWndParent,HINSTANCE hInst)
{
MessageBox(NULL,TEXT("控制面板可以調出的輸入法設置"),TEXT("設置"),MB_OK);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -