www.gusucode.com > VC++高仿迅雷7漂亮界面开源源码-源码程序 > VC++高仿迅雷7漂亮界面开源源码-源码程序/code/LEinGUI/LAYUI_RootFrame_Wrapper.cpp

    #include "stdafx.h"
#include "LAYUI_RootFrame_Wrapper.h"
// Download by http://www.NewXing.com
CLAYUI_RootFrame_Wrapper::CLAYUI_RootFrame_Wrapper()
{
	m_rootframe = NULL;
}

CLAYUI_RootFrame_Wrapper::~CLAYUI_RootFrame_Wrapper()
{
	
}

void CLAYUI_RootFrame_Wrapper::Release(void)
{
	if(m_rootframe)
		CLAYUI_HL_ReleaseRootBFrame(m_rootframe);
}

void CLAYUI_RootFrame_Wrapper::InitRootFrame(CLAYUI_BFRAME *rootframe)
{
	if(m_rootframe)
		CLAYUI_HL_ReleaseRootBFrame(m_rootframe);
	m_rootframe = rootframe;
	CLAYUI_HL_RegisterRootBFrame(rootframe, 0);
}

void CLAYUI_RootFrame_Wrapper::OnKeyDown(CLAYUI_CHAR n_char, UINT n_repcnt, UINT flags)
{
	CLAYUI_HL_SendKeyboardinput(m_rootframe, n_char);
}

void CLAYUI_RootFrame_Wrapper::PreTranslateMessage(CWnd* pwnd, MSG *msg)
{
	if(msg->message == WM_IME_COMPOSITION)
    {
        if(msg->lParam & GCS_RESULTSTR)
        {
            HIMC   hImc;
            DWORD   dwSize;
            char   *Buf;
            hImc = ImmGetContext(pwnd->GetActiveWindow()->GetSafeHwnd());
            dwSize = ImmGetCompositionString(hImc, GCS_RESULTSTR, NULL, 0);
            Buf = new char[dwSize + 1];
			memset(Buf, 0, dwSize + 1);
            ImmGetCompositionString(hImc, GCS_RESULTSTR, (LPVOID)Buf, dwSize);
            ImmReleaseContext(pwnd->GetActiveWindow()->GetSafeHwnd(), hImc);

			int nCharSize = MultiByteToWideChar(CP_ACP, MB_PRECOMPOSED, Buf, dwSize + 1, NULL, 0) ;
			CLAYUI_CHAR* imestr = new CLAYUI_CHAR[nCharSize + 1] ;
			memset(imestr, 0, sizeof(CLAYUI_CHAR) * (nCharSize + 1));
			MultiByteToWideChar(CP_ACP, MB_PRECOMPOSED, Buf, dwSize + 1, imestr, nCharSize) ;
			CLAYUI_HL_SendIMEStr(m_rootframe, imestr);
            delete [] Buf;
			delete [] imestr;
        }
    }
	else if(msg->message == WM_CHAR)
    {
		if(msg->lParam != 1)
		{
			if(msg->wParam >= 33 && msg->wParam <= 126)
			{
				char buf[4];
				buf[0] = msg->wParam;
				buf[1] = 0;
				buf[2] = 0;
				buf[3] = 0;
				CLAYUI_HL_SendIMEStr(m_rootframe, (CLAYUI_CHAR*)buf);
			}
		}
	}
}