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
中,错误就会消失。
相关文章:
- dx11 渲染到纹理仅显示透明颜色
- PPM 颜色显示错误
- 彩色增强::日志显示偏移的颜色
- 如何使用OpenCV同时显示"深度"和"颜色"视频图像
- PCL :PCL可视化工具在同一视口中以不同的颜色显示多点云(XYZ)
- 颜色设置在碎片着色器中,未显示GLSL 1.30
- 使多个形状以不同的位置、大小和颜色显示
- 在一个 QTableWidget 单元格中显示不同颜色的字符串
- 读取 TGA 显示空值而不是颜色数据
- 当QFilesystemModel显示驱动器时,是否可以在QTreeView中更改文件夹颜色
- 我怎样才能在 CRichEditCtrl 中更改突出显示颜色
- c++builder-显示没有标题的字节数组颜色信息
- 读取PPM文件并使用Opengl和c++进行显示.颜色不正确
- C++函数系统(命令)的输出在Linux终端中不显示颜色
- cv::imshow 在不同的线程上不显示 cv::mat 颜色
- 为什么 clang 在 Scons 下不显示颜色输出?
- 为什么显示的颜色不是VTK中预期的颜色
- 通过调整视频适配器反转显示颜色
- wxStaticBitmap不使用样式wxTRANSPARENT_WINDOW来反映父背景渐变,而不是显示父背景颜色
- 更改QWebView中的高亮显示颜色