Reputation: 3336
I'm trying to display some text on my window. I'm using Win32/OpenGL with c++.
I found this question which is the method I'm trying to implement, unfortunately, I'm doing something wrong as it's not working.
This is my CALLBACK function:
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;
}
I seem to be implementing something wrong or overlooking something because I just can't see it.
It errors with this: \main.cpp(403) : see declaration of 'hdc'
If someone could suggest an edit or help me with where I'm going wrong, that would be great. Thanks in advance.
update
There's are the errors (added lines to code above):
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
Upvotes: 1
Views: 4604
Reputation: 308520
You can't declare a variable in the middle of a switch
statement. It must either be inside a block, or declared before the beginning of the switch
.
Just put the code inside the case
in brackets {}
and the error will go away.
Upvotes: 4