CToolTipCtrl Class Encapsulates the functionality of a "tool tip control," a small pop-up window that displays a single line of text describing the purpose of a tool in an application.可以使用这个!
声明 CStatic* p_MyBut[3]; 创建 CStatic *p_MyBut = new CStatic(); --------------------------------------------你这是什么意思??
给我要动态创建的STATIC控件分配内存
DestroyWindow(p_MyBut[0].m_hWnd); 报错:D:\SCAN\2302\MyStatic.cpp(149) : error C2228: left of '.m_hWnd' must have class/struct/union type D:\SCAN\2302\MyStatic.cpp(149) : error C2660: 'DestroyWindow' : function does not take 1 parameters
声明 CStatic* p_MyBut[3]; 创建 CStatic *p_MyBut = new CStatic(); --------------------------------------你不是声明了p_MyBut[3]嘛,干嘛还要CStatic *p_MyBut = new CStatic();???? 你直接p_MyBut[0] = new CStatic(); 不就行了!!! 你这逻辑乱的...........
你在鼠标单击消息处理函数中销毁窗口?if(IsWindow(m_wndStatic.m_hWnd))
DestroyWindow(m_wndStatic.m_hWnd);
Encapsulates the functionality of a "tool tip control," a small pop-up window that displays a single line of text describing the purpose of a tool in an application.可以使用这个!
你的CStatic是自定义的?即使是自定义的,那也应该是派生于CWnd类吧??
if( p_MyBut[0])
{
p_MyBut->ShowWindow(SW_HIDE);
delete p_MyBut[0];
m_IsDel=TRUE;
m_IsCls=FALSE;;
}
这样调用时出现错误:
error C2227: left of '->ShowWindow' must point to class/struct/union
把你的那个自定义类的声明 和 p_MyBut的声明代码贴出来
class CMyStatic : public CStatic
声明
CStatic* p_MyBut[3];
创建
CStatic *p_MyBut = new CStatic();
p_MyBut->Create( m_Caption, WS_CHILD | WS_VISIBLE | SS_NOTIFY | nStyle, rect, this, nID );
#ifndef DELETE_PTRA
#define DELETE_PTRA(p) if(p){delete[] p;p=NULL;}
#endifif( p_MyBut[0] && IsWindow(p_MyBut[0]->m_hWnd))
{
p_MyBut[0]->ShowWindow(SW_HIDE);
DestroyWindow(p_MyBut[0].m_hWnd);
//delete p_MyBut[0];
//p_MyBut[0]=NULL;
DELETE_PTRA(p_MyBut[0]);
m_IsDel=TRUE;
m_IsCls=FALSE;;
}
CStatic* p_MyBut[3];
创建
CStatic *p_MyBut = new CStatic();
--------------------------------------------你这是什么意思??
报错:D:\SCAN\2302\MyStatic.cpp(149) : error C2228: left of '.m_hWnd' must have class/struct/union type
D:\SCAN\2302\MyStatic.cpp(149) : error C2660: 'DestroyWindow' : function does not take 1 parameters
CStatic* p_MyBut[3];
创建
CStatic *p_MyBut = new CStatic();
--------------------------------------你不是声明了p_MyBut[3]嘛,干嘛还要CStatic *p_MyBut = new CStatic();????
你直接p_MyBut[0] = new CStatic(); 不就行了!!! 你这逻辑乱的...........
DestroyWindow(p_MyBut[0]->m_hWnd);
error C2660: 'DestroyWindow' : function does not take 1 parameters
::DestroyWindow(GetDlgItem(IDC_STATICXXX)->GetSafeHwnd());
{
// TODO: Add your message handler code here and/or call default m_startRect = TRUE; //鼠标左键单击,设置可以开始绘制矩形框
m_startPoint = point; //记录开始点
m_OldPoint = point; //设置老点也为开始点 CStatic::OnLButtonDown(nFlags, point);
}void CMyStatic::OnLButtonUp(UINT nFlags, CPoint point)
{
// TODO: Add your message handler code here and/or call default m_startRect = FALSE; //重置绘制矩形框标志
m_IsDel=FALSE;
CClientDC dc(this);
// m_IsDel=FALSE;
// dc.SetROP2(R2_NOT);
// dc.SelectStockObject(NULL_BRUSH);
// dc.Rectangle(CRect(m_startPoint,m_OldPoint));
if(TRUE==m_IsMove)
{
p_MyBut[0] = NewMyStatic( IDC_STATIC2, CRect(point.x,point.y,point.x+80,point.y+35), BS_DEFPUSHBUTTON );
m_IsMove=FALSE;
}
// delete p_MyBut[0];
}void CMyStatic::OnMouseMove(UINT nFlags, CPoint point)
{
// TODO: Add your message handler code here and/or call default
if(TRUE==m_IsDel)
{
CClientDC dc(this); //获取设备句柄
dc.SetROP2(R2_NOT);
dc.SelectStockObject(NULL_BRUSH); //不使用画刷
if (TRUE == m_startRect) //根据是否有单击判断是否可以画矩形
{
dc.Rectangle(CRect(m_startPoint,m_OldPoint));
dc.Rectangle(CRect(m_startPoint,point));
m_OldPoint = point;
m_IsMove=TRUE;
m_IsCls=TRUE; //消隐最后的一个矩形(其原理跟拖动时矩形框绘制原理相同)
//
}
//
}
CStatic::OnMouseMove(nFlags, point);
}CStatic* CMyStatic::NewMyStatic(int nID,CRect rect,int nStyle)
{
CString m_Caption;
m_Caption.LoadString( nID ); //取按钮标题
// CStatic *p_MyBut = new CStatic();
p_MyBut[0] = new CStatic();
p_MyBut[0]->Create( m_Caption, WS_CHILD | WS_VISIBLE | SS_NOTIFY | nStyle, rect, this, nID );
return p_MyBut[0];}
void CMyStatic::OnMybut1()
{
MessageBox( "CLICKED!" );
CClientDC dc(this); dc.SetROP2(R2_NOT);
dc.SelectStockObject(NULL_BRUSH);
dc.Rectangle(CRect(m_startPoint,m_OldPoint));
if( p_MyBut[0])
{
p_MyBut[0]->ShowWindow(SW_HIDE);
::DestroyWindow(GetDlgItem(IDC_STATIC2)->GetSafeHwnd());
delete p_MyBut[0];
m_IsDel=TRUE;
m_IsCls=FALSE;;
}
//p_MyBut[0]->DestroyWindow();//ShowWindow(SW_HIDE);
}void CMyStatic::OnLButtonDblClk(UINT nFlags, CPoint point)
{
// TODO: Add your message handler code here and/or call default
//p_MyBut[0] = NewMyStatic( IDC_STATIC2, CRect(point.x,point.y,point.x+80,point.y+35), BS_DEFPUSHBUTTON );
CStatic::OnLButtonDblClk(nFlags, point);
}void CMyStatic::OnRButtonDown(UINT nFlags, CPoint point)
{
// TODO: Add your message handler code here and/or call default
if(TRUE==m_IsCls)
{
m_IsCls=FALSE;
if( p_MyBut[0])
{
CClientDC dc(this);
dc.SetROP2(R2_NOT);
dc.SelectStockObject(NULL_BRUSH);
dc.Rectangle(CRect(m_startPoint,m_OldPoint));
// ::DestroyWindow(GetDlgItem(IDC_STATIC2)->GetSafeHwnd());
delete p_MyBut[0];
m_IsDel=TRUE;
}
}
CStatic::OnRButtonDown(nFlags, point);
}
{
CString m_Caption;
m_Caption.LoadString( nID ); //取按钮标题
// CStatic *p_MyBut = new CStatic();
p_MyBut[0] = new CStatic();
p_MyBut[0]->Create( m_Caption, WS_CHILD | WS_VISIBLE | SS_NOTIFY | nStyle, rect, this, nID );
return p_MyBut[0];
}
----------------------------
p_MyBut[0]应该是你的类成员变量吧,如果是,改成:CMyStatic::NewMyStatic(int nID,CRect rect,int nStyle)
{
CString m_Caption;
m_Caption.LoadString( nID ); //取按钮标题
// CStatic *p_MyBut = new CStatic();
if(p_MyBut[0] = new CStatic())
{
p_MyBut[0]->Create( m_Caption, WS_CHILD | WS_VISIBLE | SS_NOTIFY | nStyle, rect, this, nID );
}
}
void CMyStatic::OnMybut1() 函数中:
::DestroyWindow(GetDlgItem(IDC_STATIC2)->GetSafeHwnd());
你这扯哪儿去了??
批一下22楼的,你这纯属误人子弟!!
这一句改回去
void CMyStatic::NewMyStatic(int nID,CRect rect,int nStyle)
(p_MyBut[0])->ShowWindow(SW_HIDE);
p_MyBut 是指针数组。
p_MyBut[0] 是第一个元素,他才是指向 static 的 指针!
// 根本不要 p_MyBut ,如果要 区分 那个 实例 使用 GetDlgCtrlID()
void CMyStatic::OnClick()
{
MessageBox( "CLICKED!" );
// CClientDC dc(this); //dc.SetROP2(R2_NOT);
//dc.SelectStockObject(NULL_BRUSH);
//dc.Rectangle(CRect(m_startPoint,m_OldPoint));
// if( p_MyBut[0])
// {
// p_MyBut[0]->ShowWindow(SW_HIDE);
this->DestroyWindow();
// delete p_MyBut[0];
m_IsDel=TRUE;
m_IsCls=FALSE;; }