类似 MSN 带转义字符的信息发送框的制作(下)
2006-07-23 11:24:47 来源:WEB开发网BOOL CIconContainer::Create(POINT pt,CButton* pParentButton,CArray *pBitmapArray)
{
if(pBitmapArray->GetSize()<=0)return FALSE;
m_pParentButton=pParentButton;
///根据每张图片的大小创建IconContainer
m_nCol=int(sqrt(pBitmapArray->GetSize()))+1; //计算列数
BITMAP bm;
pBitmapArray->GetAt(0)->GetBitmap(&bm); //以图片列表中的第0号图片的大小为
基准
m_nCellWidth=bm。bmWidth+4; //内部单元的宽度
m_nCellHeight=bm。bmHeight+4; //内部单元的高度
CRect rect;
rect。left=pt。x,rect。top=pt。y;
rect。right=pt。x+m_nCellWidth*m_nCol; //容器的宽度
if(pBitmapArray->GetSize()%m_nCol==0) //计算行数
{
m_nRow=pBitmapArray->GetSize()/m_nCol;
}
else
{
m_nRow=pBitmapArray->GetSize()/m_nCol+1;
}
rect。bottom=pt。y+m_nCellHeight*m_nRow+2+46; ///容器的高度=(行数+2)*单元宽度
//pParentButton->GetParent()->ScreenToClient(&rect);
///创建容器
//CWnd::Create(NULL, NULL, WS_VISIBLE | WS_CHILD,
//rect,pParentButton->GetParent(),IDC_ICONCONTAINER, NULL);
CWnd::CreateEx(WS_EX_LEFT,AfxRegisterWndClass(0),NULL,WS_VISIBLE|WS_POPUP,rect,NULL,NULL );
///创建图片张数+2个按钮
for(int i=0;i<m_nRow;i++)
{
for(int j=0;j<m_nCol&& i*m_nCol+j<pBitmapArray->GetSize();j++)
{
///计算按钮的位置
CRect innerrect;
innerrect。left=j*m_nCellWidth;
innerrect。top=i*m_nCellHeight;
innerrect。right=innerrect。left+m_nCellWidth;
innerrect。bottom=innerrect。top+m_nCellHeight;
innerrect。DeflateRect(2,2);
///新建按钮
CInnerButton *pInnerButton;
pInnerButton=new CInnerButton;
pInnerButton->Create(NULL,WS_CHILD |WS_VISIBLE,
innerrect,this,IDC_INNERBUTTON+i*m_nCol+j);
///设置按钮的图标
pInnerButton->SetBitmap(pBitmapArray->GetAt(i*m_nCol+j));
pInnerButton->ShowWindow(SW_SHOW);
///记录该按钮的指针
m_InnerButtonArray。Add(pInnerButton);
}
}
////创建两个扩展功能按钮
this->GetClientRect(&rect);
CInnerButton *pInnerButton;
pInnerButton=new CInnerButton;
rect。left=2;
rect。right-=2;
rect。top=m_nRow*m_nCellHeight+3;
rect。bottom=rect。top+20; //按钮的高度为22
pInnerButton->Create(NULL,WS_CHILD |WS_VISIBLE,
rect,this,IDC_INNERBUTTON-1);
pInnerButton->SetFont(m_pParentButton->GetParent()->GetFont());
pInnerButton->SetWindowText("显示更多的图释");
pInnerButton=new CInnerButton;
rect。top=rect。bottom+3;
rect。bottom=rect。top+20;
pInnerButton->Create(NULL,WS_CHILD |WS_VISIBLE,
rect,this,IDC_INNERBUTTON-2);
pInnerButton->SetWindowText("我的自定义图释");
pInnerButton->SetFont(m_pParentButton->GetParent()->GetFont());
return TRUE;
}
当用户单击了其中的一个按钮时,把序号记录下来(可以根据InnerButton的ID,创建的时候ID是递增的)并给父窗体(CIconPicker)发送一个消息,把序号送过去。
更多精彩
赞助商链接