Draw::Draw(CWnd* pParent /*=nullptr*/) : CDialogEx(IDD_DRAW, pParent) { } Draw::~Draw() { } void Draw::DoDataExchange(CDataExchange* pDX) { CDialogEx::DoDataExchange(pDX); } void Draw::OnPaint() { //CPaintDC dc(this); // device context for painting //// TODO: 在此处添加消息处理程序代码 //// 不为绘图消息调用 CDialogEx::OnPaint() //CWnd* pWin = GetDlgItem(IDC_STATIC);//获取Picture控件的指针 //CRect rect; //pWin->GetClientRect(rect);//把控件的长宽、坐标等信息保存在rect里 //CDC* pDC = pWin->GetDC();//获取该控件的画布 //CNA_Draw-> DrawPicture(pDC, rect);//画图 CPaintDC dc(this); CWnd* pWnd = GetDlgItem(IDC_STATIC);//获得picture控件指针 CDC* pDC = pWnd->GetDC();//选取画布 CRect rect; pWnd->GetClientRect(rect);//获得picture控件大小 CNA_Draw->DrawPicture(pDC, rect); } BEGIN_MESSAGE_MAP(Draw, CDialogEx) ON_BN_CLICKED(IDOK, &Draw::OnBnClickedOk) END_MESSAGE_MAP() // Draw 消息处理程序 void Draw::OnBnClickedOk() { // TODO: 在此添加控件通知处理程序代 OnPaint(); }
时间: 2023-12-24 21:03:07 浏览: 174
根据你提供的代码,我注意到在`OnPaint()`函数中,你尝试使用了`CWnd`和`CDC`类来获取画布并进行绘图操作。然而,我没有看到你实例化`CNA_Draw`对象或者定义`DrawPicture()`函数的实现。这可能是导致无法画出图像的原因之一。
为了能够正确绘制图像,你需要确保以下几点:
1. 在`Draw`类中实例化一个名为`CNA_Draw`的对象,该对象应该具有绘制图像的功能。
2. 在`Draw`类中实现`DrawPicture()`函数,该函数应该接受一个`CDC*`类型的参数和一个表示绘图区域的`CRect`对象参数。在该函数中,你可以调用绘图函数(如`Rectangle()`、`LineTo()`等)来绘制你想要的图像。
3. 在`OnPaint()`函数中调用`CNA_Draw->DrawPicture(pDC, rect)`来执行绘图操作。
请确保你已经正确地实现了上述步骤,并在`DrawPicture()`函数中编写了能够绘制图像的代码逻辑。如果仍然无法绘制图像,请提供更多相关代码,以便我能够更好地帮助你解决问题。
相关问题
CGame_DLG::CGame_DLG(CWnd* pParent /*=nullptr*/) : CDialogEx(IDD_DIALOG1, pParent) { }
This is the constructor for the CGame_DLG class, which is derived from the CDialogEx class. It takes a single parameter, a pointer to a CWnd object representing the parent window of the dialog (which defaults to nullptr if no parent is specified). The constructor initializes the base class with the resource ID of the dialog template (IDD_DIALOG1), and passes the parent pointer to the base class constructor.
simulate11::simulate11(CWnd* pParent /*=nullptr*/) : CDialogEx("IDD_site", pParent) { } simulate11::~simulate11() { } void simulate11::DoDataExchange(CDataExchange* pDX) { CDialogEx::DoDataExchange(pDX); }
这段代码是一个类`simulate11`的实现,其中包括一个构造函数、一个析构函数和一个`DoDataExchange`函数。这个类是从`CDialogEx`类继承而来的,它用于创建一个对话框界面。
这段代码没有明显的语法错误,但是在其他地方使用`simulate11`类型时,如果没有定义过该类型,就会出现编译错误。一些常见的编译错误包括“未定义类型”、“无法找到符号”等错误,这些错误通常与类型定义有关。
因此,要避免这种错误,你应该在使用`simulate11`类型之前,确保在代码中已经定义了该类型。如果你使用了外部库中的类型,你需要包含正确的头文件,以便编译器能够找到所需的类型定义。
阅读全文
相关推荐
![rar](https://img-home.csdnimg.cn/images/20241231044955.png)
![rar](https://img-home.csdnimg.cn/images/20241231044955.png)
![rar](https://img-home.csdnimg.cn/images/20241231044955.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![zip](https://img-home.csdnimg.cn/images/20241231045053.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)