MFC - 获取动态创建的矩形的 id

MFC - Get id of dynamically created rectangle

作为学习 MFC 的一部分,我遇到了这样一种情况,我在对话框的 OnPaint() 中动态创建了一个矩形 class 类似这样的事情。

CPaintDC dc(this);
dc.Rectangle(10,10,208,92);

我想从另一个函数中获取这个矩形的设备 ID。 另一个函数是同一对话框中的 BtClick 事件函数 class.

void ThreadDialog::OnBnClickedButton3()
{
    CWnd* pWnd = FromHandle(dlg.m_hWnd);
    CDC* pDC = pWnd->GetDC  ();
  /* Here i wanted to get the device context of the rectangle drawn in OnPaint() */

}

所以首先我需要动态创建的矩形的控件 ID 这样之后我就可以获取该矩形的设备上下文。

请教如何操作。

CDC::Rectangle() 不创建任何东西,它只是在该 DC 上绘制一个矩形。 没有与该绘图关联的 ID 或设备上下文。