0

First, this function is called many times. It should be noted that wString[] does contain the character constant '\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);
}

At the end, a WM_PAINT message is sent while nLines should be non-zero since log contains multiples '\n'. My WndProc receives the message and processes it.

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

After which OnRender is called with a (supposedly) non-zero int as an lParam.

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();
}

For some reason, in the OnRender function, nLogLines' value is 0. What is wrong?

Mickael Bergeron Néron
  • 1,472
  • 1
  • 18
  • 31
  • 2
    it's not a good idea to send or post a WM_PAINT. invalidate whatever part of your window that needs repainting. then WM_PAINT is *generated* when you next access the message queue. – Cheers and hth. - Alf Mar 14 '13 at 00:24
  • I used a WCHAR* now and nLines does gain the value it was supposed to. However, I indead have another problem which may have to do with the message WM_PAINT being sent. I will use invalidateRect instead. Thanks. – Mickael Bergeron Néron Mar 14 '13 at 00:33

1 Answers1

2

"What is wrong?"

most probably that the WM_PAINT you're processing did not stem from your SendMessage

general advice: don't send or post WM_PAINT, let the system generate that message (which it does when you retrieve a message from the thread's message queue and a window needs repainting)

Cheers and hth. - Alf
  • 142,714
  • 15
  • 209
  • 331