有如下一个CRect对象:CRect m_rectBtn = CRect(cx/2,0,cx,cy);请给出代码将其内部分成4*4的小CRect。
时间: 2024-06-01 13:12:49 浏览: 20
可以使用以下代码将CRect对象分成4*4的小CRect:
CRect m_subRect[4][4];
int cx = m_rectBtn.Width() / 4;
int cy = m_rectBtn.Height() / 4;
for (int i = 0; i < 4; i++) {
for (int j = 0; j < 4; j++) {
m_subRect[i][j].SetRect(m_rectBtn.left + i * cx, m_rectBtn.top + j * cy, m_rectBtn.left + (i + 1) * cx, m_rectBtn.top + (j + 1) * cy);
}
}
注意:以上代码是基于MFC框架开发的,如果你使用的是其它开发框架,则需要将代码做相应修改。
相关问题
class CResizingDialog : public CDialog { // Construction public: CResizingDialog( UINT nIDTemplate, CWnd* pParentWnd = NULL ); void SetControlInfo(WORD CtrlId,WORD Anchore); BOOL GetRememberSize() { return m_bRememberSize;} void SetRememberSize(BOOL bRemember) { m_bRememberSize = bRemember;} virtual void GetDialogProfileEntry(CString &sEntry); // Dialog Data protected: // Set m_bRememberSize to FALSE if you don't want the dialog box // to remember its size between sessions. BOOL m_bRememberSize; // Set m_bDrawGipper if you don't want a Resizing Gripper BOOL m_bDrawGripper; private: int m_minWidth,m_minHeight; int m_old_cx,m_old_cy; BOOL m_bSizeChanged; CDWordArray m_control_info; UINT m_nIDTemplate; CRect m_GripperRect; protected: // Generated message map functions //{{AFX_MSG(CResizingDialog) virtual BOOL OnInitDialog(); afx_msg void OnSize(UINT nType, int cx, int cy); afx_msg void OnGetMinMaxInfo(MINMAXINFO* pMMI); afx_msg void OnDestroy(); afx_msg int OnCreate(LPCREATESTRUCT lpCreateStruct); afx_msg UINT OnNcHitTest(CPoint point); afx_msg void OnPaint(); //}}AFX_MSG DECLARE_MESSAGE_MAP() };这段代码什么意思
这段代码定义了一个名为CResizingDialog的类,该类是CDialog类的子类。它提供了一些方法来设置对话框中控件的锚定和大小信息,并且可以记住对话框的大小。此外,它还提供了一些消息处理函数,用于处理对话框大小的变化、最小和最大尺寸、窗口销毁等事件,并在窗口周围绘制一个可调整大小的边框。这个类可以用于创建可调整大小的对话框。
void DlgCheck::OnSize(UINT nType, int cx, int cy) { CDialogEx::OnSize(nType, cx, cy); if (nType == SIZE_RESTORED || nType == SIZE_MAXIMIZED) { float fsp[2]; POINT Newp; //获取现在对话框的大小 CRect recta; GetClientRect(&recta); //取客户区大小 Newp.x = recta.right - recta.left; Newp.y = recta.bottom - recta.top; fsp[0] = (float)Newp.x / Old.x; fsp[1] = (float)Newp.y / Old.y; CRect Rect; int woc; CPoint OldTLPoint, TLPoint; //左上角 CPoint OldBRPoint, BRPoint; //右下角 HWND hwndChild = ::GetWindow(m_hWnd, GW_CHILD); //列出所有控件 while (hwndChild) { woc = ::GetDlgCtrlID(hwndChild);//取得ID GetDlgItem(woc)->GetWindowRect(Rect); ScreenToClient(Rect); OldTLPoint = Rect.TopLeft(); TLPoint.x = long(OldTLPoint.x * fsp[0]); TLPoint.y = long(OldTLPoint.y * fsp[1]); OldBRPoint = Rect.BottomRight(); BRPoint.x = long(OldBRPoint.x * fsp[0]); BRPoint.y = long(OldBRPoint.y * fsp[1]); Rect.SetRect(TLPoint, BRPoint); GetDlgItem(woc)->MoveWindow(Rect, TRUE); hwndChild = ::GetWindow(hwndChild, GW_HWNDNEXT); } Old = Newp; } if (this->IsPicDerec) { this->drawDerection();//此处因不明原因无法绘制成功,必须绘制两次,待修复 } if (this->IsPicShow) { cv::Mat res = this->getPic().clone(); if (!this->getBackPic().empty()) { vector<vectorcv::Point> contours; cv::findContours(this->getBackPic(), contours, cv::RETR_EXTERNAL, cv::CHAIN_APPROX_NONE);//查找外层轮廓 cv::drawContours(res, contours, -1, cv::Scalar(255)); } else { res = this->getPic(); } if (res.empty()) { AfxMessageBox("Empty res"); } this->DrawcvMat(res, IDC_Picture); } if (this->IsPicDerec) { this->drawDerection(); } }为什么第一次drawDerection()绘制的图片没有显示?
在上述代码中,第一次调用 `drawDerection()` 后绘制的图片没有显示,可能是因为你没有在 `OnSize()` 函数中正确的设置绘制的位置或者没有调用 `Invalidate()` 函数触发重绘。具体来说,你可以尝试以下几个步骤:
1. 在 `OnSize()` 函数中添加以下代码:
```cpp
void DlgCheck::OnSize(UINT nType, int cx, int cy)
{
CDialogEx::OnSize(nType, cx, cy);
if (nType == SIZE_RESTORED || nType == SIZE_MAXIMIZED) {
// 获取现在对话框的大小
CRect recta;
GetClientRect(&recta);
// 取客户区大小
POINT Newp;
Newp.x = recta.right - recta.left;
Newp.y = recta.bottom - recta.top;
// 触发重绘
Invalidate();
}
}
```
2. 确认 `drawDerection()` 函数中绘制图片的位置是否正确。你可以使用 `CDC::TextOut()` 函数在该位置绘制一些文字进行测试。
3. 确认 `DrawcvMat()` 函数能否正常显示图片。你可以在其他地方调用该函数,并传入相同的图片进行测试。
如果以上方法都无法解决问题,你可以尝试在 `DrawcvMat()` 函数中添加一些调试信息,例如在函数开始时输出一条调试信息,以确认函数能否正常被调用。
相关推荐
![rar](https://img-home.csdnimg.cn/images/20210720083606.png)
![doc](https://img-home.csdnimg.cn/images/20210720083327.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.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)
![](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)