gpt4 book ai didi

c++ - lParam 或 WCHAR[] 有问题

转载 作者:行者123 更新时间:2023-11-28 03:21:06 25 4
gpt4 key购买 nike

首先,这个函数被调用了很多次。需要注意的是 wString[] 确实包含字符常量 '\n'。

void D2DResources::PutToLog(WCHAR wString[])
{
int strLen=wcslen(wString);
int logLen=wcslen(log);

if(strLen+logLen>=MaxLogSize)
wcsncpy(log, log, logLen-strLen);

wcscat (log, wString);

int nLines=0;

for(int x=0; x<wcslen(log); x++)
{
if(log[x]=='\n')
{
nLines++;
if(nLines>5)
{
log[x]='\0';
}
}
}

SendMessage (m_hWnd, WM_PAINT, NULL, (LPARAM)nLines);
}

最后,发送一个 WM_PAINT 消息,同时 nLines 应该是非零的,因为日志包含多个 '\n'。我的 WndProc 接收消息并处理它。

case WM_PAINT:
{
pD2DResources->OnRender((int)lParam);
ValidateRect(hWnd, NULL);
}
break;

之后用一个(假定的)非零整数作为 lParam 调用 OnRender。

void D2DResources::OnRender(int nLogLines)
{
D2D1_SIZE_F screenSize = pCurrentScreen->GetSize();

D2D1_SIZE_F rTSize = pRT->GetSize();

pRT->BeginDraw();

pRT->DrawBitmap(
pCurrentScreen,
D2D1::RectF(0.0f, 0.0f, screenSize.width, screenSize.height)
);

pRT->DrawText(
log,
ARRAYSIZE(log) - 1,
pTextFormat,
D2D1::RectF(0, rTSize.height - ((nLogLines*textSize)+textSize) , rTSize.width, rTSize.height),
pWhiteBrush
);

pRT->EndDraw();
}

由于某些原因,在OnRender 函数中,nLogLines 的值为0。有什么问题吗?

最佳答案

“怎么了?”

很可能您正在处理的 WM_PAINT 并非源自您的 SendMessage

一般建议:不要发送或发布 WM_PAINT,让系统生成该消息(当您从线程的消息队列中检索消息并且窗口需要重新绘制时它会生成)

关于c++ - lParam 或 WCHAR[] 有问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15398954/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com