簡體   English   中英

Win32 DrawText顏色和顯示

[英]Win32 DrawText Colour and Display

我正在嘗試在窗口上顯示一些文本。 我正在將Win32 / OpenGL與c ++一起使用。

我發現了這個問題 ,這是我要嘗試實現的方法,但是很不幸,我在做錯事,因為它不起作用。

這是我的CALLBACK函數:

LRESULT CALLBACK WinProc(HWND hWnd,UINT uMsg, WPARAM wParam, LPARAM lParam){
    LONG    lRet = 0; 
    PAINTSTRUCT    ps;

    switch (uMsg)
    { 
    case WM_SIZE:
        if(!g_bFullScreen)
        {
            SizeOpenGLScreen(LOWORD(lParam),HIWORD(lParam));
            GetClientRect(hWnd, &g_rRect);
        }
        break; 
    case WM_PAINT:
        //BeginPaint(hWnd, &ps);

        //adding code from SO question here
         HDC hdc = BeginPaint(hWnd, &ps);  //line 403

            RECT rec;
            //       SetRect(rect, x ,y ,width, height)
            SetTextColor(hdc, RGB(255,255,255))
            SetRect(&rec,10,10,100,100);
            //       DrawText(HDC, text, text length, drawing area, parameters "DT_XXX")
            DrawText(hdc, TEXT("Text Out String"),strlen("Text Out String"), &rec, DT_TOP|DT_LEFT);

            EndPaint(hWnd, &ps);
            ReleaseDC(hWnd, hdc);

        //EndPaint(hWnd, &ps);
        break;
       case WM_KEYDOWN: //line 418
                    //some key presses

   case WM_CLOSE:
        PostQuitMessage(0);
        break; 

    default://line 510
        lRet = DefWindowProc (hWnd, uMsg, wParam, lParam); 
        break; 
    } 

    return lRet;
}

我似乎正在執行錯誤的操作或忽略了某些操作,因為我看不到它。

它出現以下錯誤: \\main.cpp(403) : see declaration of 'hdc'

如果有人可以提出修改建議或幫助我解決我的問題,那將很棒。 提前致謝。

更新

有錯誤(在上面的代碼中添加了幾行):

main.cpp(418): error C2360: initialization of 'hdc' is skipped by 'case' label
main.cpp(506): error C2360: initialization of 'hdc' is skipped by 'case' label
main.cpp(510): error C2361: initialization of 'hdc' is skipped by 'default' label

您不能在switch語句的中間聲明變量。 它必須在一個塊內,或者必須在switch開始之前聲明。

只需將代碼放在case中的括號{} ,錯誤就會消失。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM