巨简单的问题,怎么捕获窗体宽高? 及其它窗体(dialog)中某控件的位置,宽高。 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 CRect winrect;GetWindowRect(&winrect);int winwidth = winrect.right-winrect.left; // 窗体宽int winhiegh = winrect.bottom-winrect.top; // 窗体高只要得到某控件的CWnd 对象或指针,其操作与上相同;至于位置,可通过ClientToScreenT和ScreenToClient转换。 CRect ClientRect; CRect WindowRect; CRect ToolbarRect; &this->GetWindowRect(&WindowRect); &this->GetWindowRect(&ClientRect); &this->CalcWindowRect(&WindowRect,CWnd::adjustBorder); m_wndToolBar.GetWindowRect(&ToolbarRect);//Height = WindowRect.Height() 我想在基于dialog的程序中开辟一块区域用于画图,不知道这块区域用什么控件比较好? 在Onpaint()和OnReDraw()中使用CDC dc的成员函数直接画就可以了,没有必要专门定一块区域吧。 同lingfeng8888(棱枫)。楼主意思可能是先检查一下该区域有无有控件,有的话先移动一下腾出空间。 CRect rect;GetWindowRect(rect);rect.Height();高度 其实任何一种控件只要是直接或间接从CWindow类继承来的类都可以在其中绘图和写字下面给你举个例子: //m_edit1是与一个文本框控件相关联的变量 CBrush *brush; brush=new CBrush; brush->CreateSolidBrush(0xff0000); CDC *pDC=this->m_edit1.GetDC(); pDC->SelectObject(brush); pDC->Ellipse(20,20,100,50); pDC->DeleteDC(); delete brush;//输出结果在文本框里面绘制一个蓝色的椭圆 //m_edit1是与一个文本框控件相关联的变量 HICON icon1; icon1=LoadIcon(AfxGetApp()->m_hInstrance,(LPCTSTR)IDI_ICON1); CBrush *brush; CPoint oldPoint; brush=new CBrush; brush->CreateSolidBrush(0xff0000); CDC *pDC=this->m_edit1.GetDC(); pDC->SelectObject(brush); pDC->DrawIcon(icon1); //绘制图标 pDC->Ellipse(20,20,100,50);绘制椭圆 pDC->MoveToEx(100,100,oldPoint); pDC->LineTo(200,200); //从100到200的一条直线 pDC->DeleteDC(); delete brush; 如果你要想捕获鼠标事件你必须要使用GetWindowLong(),SetWindowLong()两个函数将编辑子类化,然后才能对该编辑框进行正常的鼠标捕获操作。多看看书,学习VC编程最好还是从Win32编程开始写了两次了给点分吧,兄弟 使用CFile打开txt文件的一点问题 如何查找一个程序什么时候调用dll库 高分求教 急!!关于调试DLL 谁又有“WIN32多线程程序设计”电子版的书。 VERIFY的作用是什么? 如何把数字12345678格式化成字符:12,345,678 111111111111111 shell extension 问题请教! 着急:请VC高手帮忙:怎样建立 ACTIVE DLL (象在VB中那样方便???) 如何添加自定义消息? 我想处理对话框中的一Edit框的keydown事件,该怎么办?( 用sdk )
GetWindowRect(&winrect);
int winwidth = winrect.right-winrect.left; // 窗体宽
int winhiegh = winrect.bottom-winrect.top; // 窗体高只要得到某控件的CWnd 对象或指针,其操作与上相同;至于位置,可通过ClientToScreenT和ScreenToClient转换。
CRect WindowRect;
CRect ToolbarRect; &this->GetWindowRect(&WindowRect);
&this->GetWindowRect(&ClientRect);
&this->CalcWindowRect(&WindowRect,CWnd::adjustBorder);
m_wndToolBar.GetWindowRect(&ToolbarRect);
//Height = WindowRect.Height()
GetWindowRect(rect);
rect.Height();高度
//m_edit1是与一个文本框控件相关联的变量
CBrush *brush;
brush=new CBrush;
brush->CreateSolidBrush(0xff0000);
CDC *pDC=this->m_edit1.GetDC();
pDC->SelectObject(brush);
pDC->Ellipse(20,20,100,50);
pDC->DeleteDC();
delete brush;
//输出结果在文本框里面绘制一个蓝色的椭圆
HICON icon1;
icon1=LoadIcon(AfxGetApp()->m_hInstrance,(LPCTSTR)IDI_ICON1);
CBrush *brush;
CPoint oldPoint;
brush=new CBrush;
brush->CreateSolidBrush(0xff0000);
CDC *pDC=this->m_edit1.GetDC();
pDC->SelectObject(brush);
pDC->DrawIcon(icon1); //绘制图标
pDC->Ellipse(20,20,100,50);绘制椭圆
pDC->MoveToEx(100,100,oldPoint);
pDC->LineTo(200,200); //从100到200的一条直线
pDC->DeleteDC();
delete brush;
如果你要想捕获鼠标事件你必须要使用GetWindowLong(),SetWindowLong()两个函数将编辑子类化,然后才能对该编辑框进行正常的鼠标捕获操作。多看看书,学习VC编程最好还是从Win32编程开始写了两次了给点分吧,兄弟