まず、この関数は何度も呼び出されます。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 メッセージが送信されますが、ログには複数の '\n' が含まれているため、nLines はゼロ以外である必要があります。私の WndProc はメッセージを受け取り、それを処理します。
case WM_PAINT:
{
pD2DResources->OnRender((int)lParam);
ValidateRect(hWnd, NULL);
}
break;
その後、(おそらく) ゼロ以外の int を 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 になっています。何が問題なのですか?