在 https://tieba.baidu.com/p/2099210288 链接教程里的,我复制过来了然后的错误我不知道怎么改
#include<windowsx.h>
#include<Windows.h>
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<cstring>
#include<string>
#include<time.h>
#include<conio.h>
#include<easyx.h>
#include<EasyUI.h>
#include<graphics.h>
#include<locale.h>
#include<wchar.h>
#include<imm.h>
using namespace std;
string str; //输入数据
void scanf_book_ht(HWND hwnd, string& str)
{
while (1) {
HIMC himc = ImmGetContext(hwnd);
static bool flag = false;
DWORD dwsize = ImmGetCompositionStringW(himc, GCS_COMPSTR, NULL, 0);
if (himc) {
if (dwsize > 0) {
if (flag == false) flag = true;
}
}
else if (dwsize == 0 && flag) {
int iSize; //IME结果字符串的大小
LPSTR pszMultiByte = NULL;//IME结果字符串指针
int ChineseSimpleAcp = 936;//宽字节转换时中文的编码
WCHAR* lpWideStr = NULL;//宽字节字符数组
dwsize = ImmGetCompositionStringW(himc, GCS_RESULTSTR, NULL, 0);//获取IME结果字符串的大小
if (dwsize > 0) //如果IME结果字符串不为空,且没有错误
{
dwsize += sizeof(WCHAR);//大小要加上NULL结束符
//为获取IME结果字符串分配空间
if (lpWideStr)
{
delete[]lpWideStr;
lpWideStr = NULL;
}
lpWideStr = new WCHAR[dwsize];
memset(lpWideStr, 0, dwsize); //清空结果空间
ImmGetCompositionStringW(himc, GCS_RESULTSTR, lpWideStr, dwsize);//获取IME结果字符串,这里获取的是宽字节
iSize = WideCharToMultiByte(ChineseSimpleAcp, 0, lpWideStr, -1, NULL, 0, NULL, NULL);//计算将IME结果字符串转换为ASCII标准字节后的大小
//为转换分配空间
if (pszMultiByte)
{
delete[] pszMultiByte;
pszMultiByte = NULL;
}
pszMultiByte = new char[iSize + 1];
WideCharToMultiByte(ChineseSimpleAcp, 0, lpWideStr, -1, pszMultiByte, iSize, NULL, NULL);//宽字节转换
pszMultiByte[iSize] = '\0';
str += pszMultiByte;//添加到string中
//释放空间
if (lpWideStr)
{
delete[]lpWideStr;
lpWideStr = NULL;
}
if (pszMultiByte)
{
delete[] pszMultiByte;
pszMultiByte = NULL;
}
}
flag = false;
}
ImmReleaseContext(hwnd, himc);//释放HIMC
}
}
//输入框
/*void scanf_book*/int main(void)
{
HWND hwnd = GetHWnd();
memset(hwnd, 0, sizeof(hwnd));
while (true)
{
if (_kbhit()) //如果是ASCII输入
{
char c = _getch();
if (c == '\b')
{
if (str.length() > 0)
{
if (str.at(str.length() - 1) & 0x8000)
str.erase(str.end() - 1);
str.erase(str.end() - 1);
}
}
else if (c == 27) {}
else {
str += c;
}
}
else //除此之外,检测是否有IME输入,如果有,则将输入结果添加到string中
{
scanf_book_ht(hwnd, str);
}
if (str.length() > 100) str = "";
outtextxy(360, 570, str.c_str());
}
}
严重性 代码 说明 项目 文件 行 禁止显示状态
错误 LNK1120 3 个无法解析的外部命令 单词本 VS程序\单词本\Debug\单词本.exe 1
错误 LNK2019 无法解析的外部符号 ImmGetCompositionStringW@16,该符号在函数 "void cdecl scanf_book_ht(struct HWND *,class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > &)" (?scanf_book_ht@@YAXPAUHWND_@@AAV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@@Z) 中被引用 单词本 VS程序\单词本\单词本.obj 1
错误 LNK2019 无法解析的外部符号 ImmGetContext@4,该符号在函数 "void cdecl scanf_book_ht(struct HWND *,class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > &)" (?scanf_book_ht@@YAXPAUHWND_@@AAV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@@Z) 中被引用 单词本 VS程序\单词本\单词本.obj 1
错误 LNK2019 无法解析的外部符号 ImmReleaseContext@8,该符号在函数 "void cdecl scanf_book_ht(struct HWND *,class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > &)" (?scanf_book_ht@@YAXPAUHWND_@@AAV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@@Z) 中被引用 单词本 VS程序\单词本\单词本.obj 1