【发布时间】:2014-03-20 03:07:45
【问题描述】:
我正在尝试在我的窗口上显示一些文本。我正在使用带有 c++ 的 Win32/OpenGL。
我找到了this question,这是我正在尝试实施的方法,不幸的是,我做错了,因为它不起作用。
这是我的 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
【问题讨论】: