当前位置: 首页 > 图文教程 > 开发语言 > VC++ > 类似 MSN 带转义字符的信息发送框的制作(下)
| 类似 MSN 带转义字符的信息发送框的制作(下)
当 CIconPicker 收到 WM_LBUTTONDOWN 消息时先不忙给父窗体发送 WM_COMMAND消息 ,而是创建一个图片列表CIconContainer(容器),然后在容器上面创建和图片数量一样多的按钮,每个按钮显示一张图片。当然,为了 void CIconPicker::OnLButtonDown(UINT nFlags, CPoint point) { if(m_bState) return ; m_bState=TRUE; this->SetState(TRUE); RECT rect; this->GetWindowRect(&rect); POINT pt; pt。x=rect。left;pt。y=rect。bottom; //创建一个图片列表容器 m_pIconContainer=new CIconContainer; ///把图片数组当作参数传过去 if(m_pIconContainer->Create(pt,this,&m_BitmapArray)) { m_pIconContainer->ShowWindow(SW_SHOW); m_pIconContainer->UpdateWindow(); m_pIconContainer->SetFocus(); }}2、为每一张图片在容器内创建一个按钮CInnerButton。我把这个工作交给容器来完成。重载容器(CIconContainer)的Create()函数,如下: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(pBitm |