immenum.cpp

来自「本人买的<<VC++项目开发实例>>源代码配套光盘.」· C++ 代码 · 共 69 行

CPP
69
字号
// IMMEnum.cpp: implementation of the CIMMEnum class.
//
//////////////////////////////////////////////////////////////////////

#include "stdafx.h"
#include "WMVC.h"
#include "IMMEnum.h"

#ifdef _DEBUG
#undef THIS_FILE
static char THIS_FILE[]=__FILE__;
#define new DEBUG_NEW
#endif

//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////
//
//下面的头文件引入了imm的相关定义
//并且在#pragma中加入了它的lib库
//
#include <imm.h>		//for imm method
#pragma comment(lib, "Imm32.lib")

CIMMEnum::CIMMEnum()
{
	m_lpHKL_List = NULL;
	UINT uCount = GetKeyboardLayoutList(0, NULL);
	if (0 != uCount)
	{
		m_lpHKL_List = new HKL[uCount];
		GetKeyboardLayoutList(uCount, m_lpHKL_List);
		TRACE("GetKeyboardLayoutList OK!!\n");
	}
	else
	{
		int nErr = GetLastError();
		TRACE("Error is %d\n", nErr);
	}

	CString strLayoutText;
	for (UINT i = 0; i < uCount; i++)
	{
		ImmGetDescription(m_lpHKL_List[i], strLayoutText.GetBuffer(256), 256);
		strLayoutText.ReleaseBuffer();
		m_strlstIMM.AddTail(strLayoutText);
	}

}

CIMMEnum::~CIMMEnum()
{
	if (m_lpHKL_List != NULL)
	{
		delete []m_lpHKL_List;
	}

}

const CStringList& CIMMEnum::GetIMMs()
{
	return m_strlstIMM;
}

const HKL * CIMMEnum::GetKeyboardLayouts()
{
	return m_lpHKL_List;
}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?