小编eju*_*ser的帖子

win32 - 如何在文本字符串周围绘制一个矩形?

我是Win32的新手并试图在C++中获得基于GDI的代码(出于技术原因不想使用GDI +)

编辑:简化问题:

我需要在窗口中间绘制的文本周围绘制一个矩形. - 如何填充矩形坐标? - 任何人都可以帮助线 - 矩形(x1,y1,x2,y2)? - 如何计算这些(x1,y1)和(x2,y2)值?

谢谢..

        hdc = BeginPaint(hWnd, &ps);
    GetClientRect(hWnd, &rcClient);
    SelectObject(hdc, GetStockObject(DEFAULT_GUI_FONT));
    SetTextColor(hdc, RGB(255, 0, 0));

    DrawText(hdc, wstring(s.begin(),s.end()).c_str(), -1, &rectResult, DT_SINGLELINE | DT_CALCRECT);

    DrawText(hdc, wstring(s.begin(),s.end()).c_str(), -1, &rcClient, DT_SINGLELINE | DT_CENTER | DT_VCENTER);

    // Here I need help - How to I place the rectangle around the Text - which is drawn in the middle of the window?
    // It looks like need to use - rectResult.bottom/top/left/right - but don't know how.. …
Run Code Online (Sandbox Code Playgroud)

winapi gdi

4
推荐指数
1
解决办法
1万
查看次数

c ++使用stringstreams的自定义字符串格式

我正在尝试使用新的 stringstreams 方法将某些 float+int 组合转换为某种格式,但试图看看是否有更好的方法来处理这个问题:

现在使用 //string String = static_cast( &(ostringstream() << Number) )->str(); 一种模式 - 如何将其存储为格式的字符串形式 - “1.10(3)”。精度等于小数。这里的问题是这些值都不是常量。即使解决方案不能是内联函数或字符串流 - 只要它足够通用就可以了。还要注意,最终的计划是使用此字符串转换为 GDI 文本字符串。

提前致谢 - 如果有人可以提供帮助。

这是我当前的示例代码(并正在寻找一种替代的有效方法来完成此操作):

string Convert(float number,int decimals)
{
std::ostringstream buff;
buff<<setprecision(decimals)<<fixed<<number;
return buff.str();
}


float f=1.1;     // this can have any values from 1,1.5 or 1.52
int decimals=2;  //dynamic number - calculated by other means - not a fixed number
int i=3;         // some dynamic number as well - calculated by other means

string s=Convert(f,decimals)+"("+Convert(i,0)+")";  // …
Run Code Online (Sandbox Code Playgroud)

c++ string-formatting

1
推荐指数
1
解决办法
2万
查看次数

标签 统计

c++ ×1

gdi ×1

string-formatting ×1

winapi ×1