MFC EnableD2D尝试使用StrokeStyle不起作用
MFC EnableD2DSupport try using StrokeStyle is not working
我有一个MFC应用程序,可以绘制线条、文本、不同颜色的矩形等,没有任何问题。但我想画点和虚线,但我没有找到任何方法!我在互联网上找到了以下例子,结果是最后画了一个空图:所有的窗口,而不仅仅是有罪的DrawLine(),这没有任何错误或坏状态。
以下是我的代码示例:
在构造函数中:
// Enable D2D support for this window:
EnableD2DSupport();
HRESULT hr = D2D1CreateFactory(D2D1_FACTORY_TYPE_SINGLE_THREADED, &m_pD2DFactory);
// Dash array for dashStyle D2D1_DASH_STYLE_CUSTOM
float dashes[] = {1.0f, 2.0f, 2.0f, 3.0f, 2.0f, 2.0f};
// Stroke Style with Dash Style -- Custom
if (SUCCEEDED(hr))
{
hr = m_pD2DFactory->CreateStrokeStyle(
D2D1::StrokeStyleProperties(
D2D1_CAP_STYLE_FLAT,
D2D1_CAP_STYLE_FLAT,
D2D1_CAP_STYLE_ROUND,
D2D1_LINE_JOIN_MITER,
10.0f,
D2D1_DASH_STYLE_DASH_DOT,//D2D1_DASH_STYLE_CUSTOM,
0.0f),
0,//dashes,
0,//ARRAYSIZE(dashes),
&m_strokeStyle
);
}
进入OnDraw2d(WPARAM WPARAM,LPARAM LPARAM):
pRenderTarget->DrawLine(CPoint(rectGraph.left,rect.bottom), CPoint(rectGraph.right,rect.bottom), m_pBlackBrush, 1.0, m_strokeStyle);
但没有StrokeStyle的同一行运行良好:
pRenderTarget->DrawLine(CPoint(rectGraph.left,rect.bottom), CPoint(rectGraph.right,rect.bottom), m_pBlackBrush, 1.0, NULL);
我做错了什么?
MS为什么要让它变得如此困难,这是个谜。截至2020年12月,以下内容在VS2019中对我有效:在CView派生类中声明成员变量
_AFX_D2D_STATE* m_pD2DState = nullptr;
在构造函数中,初始化它
EnableD2DSupport();
m_pD2DState = AfxGetD2DState();
最后-获得工厂并使用它来创建笔划样式的
ID2D1Factory *pFactory = m_pD2DState->GetDirect2dFactory();
pFactory->CreateStrokeStyle(...);
相关文章:
- 我的神经网络不起作用 [XOR 问题]
- 在C++程序中输入的文本文件将不起作用,除非文本被复制和粘贴
- C++映射:具有自定义类的运算符[]不起作用(总是返回0)
- C++为什么尽管我调用了void函数,它却不起作用
- 为什么在保护模式下继承升级不起作用
- 循环在计数器中不起作用
- 在其他文件中创建类时在 c++ 项目中不起作用
- Visual studio代码重构似乎不起作用(例如,重命名符号-f2)
- 为什么二进制搜索在我的测试中不起作用
- 我的代码中有错误吗?使用BGI图形的C++代码对我不起作用
- 为什么 const std::p air<K,V>& 在 std::map 上基于范围的 for 循环不起作用?
- 带有指定长度字符* 参数的 std::regex_search 在 VS2017 中不起作用?
- Bjarne Stroustrup Book - std_lib_facilities.h - 不起作用(未知类型名称)
- 当两个相等的双精度的相对比较不起作用时,我该怎么办?
- 当qt插件在Windows中不起作用时,如何在eclipse cdt中创建qt应用程序
- MFC EnableD2D尝试使用StrokeStyle不起作用
- 当显式转换是必需的并且隐式转换将不起作用时
- 当 COUT 不起作用时,如何检测无限循环?
- 当内部作用域名称不起作用时,为什么编译器不采用命名空间名称?
- Visual Studio 2010 - MS C++ (CL) 编译的可执行文件在 Windows 2000 上不起作