創(chuàng)建一個(gè)對(duì)話框,作為預(yù)覽窗口的父窗口。打開對(duì)話框?qū)傩源翱冢瑢?duì)話框的ID改為IDD_PANEL_DIALOG,修改對(duì)話框資源的風(fēng)格為Child、邊框?yàn)門hin。為對(duì)話框創(chuàng)建一個(gè)對(duì)話框類CPanel。
(15)向CPanel類中添加成員變量。代碼如下:
CPreView * m_pList; //預(yù)覽窗口
UINT m_Num; //記錄預(yù)覽窗口的數(shù)量
UINT m_UnitNum; //m_Num的開平方
UINT m_Div; //預(yù)覽窗口的間隔
CRect m_PreRC; //所有預(yù)覽窗口的顯示區(qū)域
(16)向CPanel類中添加CreatePreWnd方法,用于創(chuàng)建預(yù)覽窗口。代碼如下:
BOOL CPanel::CreatePreWnd(UINT uNum)
{
if (uNum==0) //判斷是否有預(yù)覽窗口
return FALSE;
m_UnitNum = uNum;
u m_Num = pow(uNum,2);
m_pList = new CPreView[m_Num ];
CRect rc;
GetClientRect(rc); //獲得父窗口的客戶區(qū)域
//預(yù)覽窗口的寬度
int width = (rc.Width()-(uNum+1)*m_Div)/uNum;
//預(yù)覽窗口的高度
int height = (rc.Height()-(uNum+1)*m_Div)/uNum;
//計(jì)算預(yù)覽窗口的位置
for (int i =0; i<m_Num; i++)
{
int row = i / uNum + 1; //計(jì)算預(yù)覽窗口的行位置
int col = i % uNum + 1; //計(jì)算預(yù)覽窗口的列位置
int x = col*m_Div+(col-1)*width; //計(jì)算預(yù)覽窗口的左上角橫坐標(biāo)
int y = row*m_Div+(row-1)*height; //計(jì)算預(yù)覽窗口的左上角縱坐標(biāo)
CRect rect(x,y,x+width,y+height); //設(shè)置預(yù)覽窗口的顯示區(qū)域
//創(chuàng)建預(yù)覽窗口
v m_pList[i].Create("www",WS_CHILD|WS_VISIBLE|SS_BLACKFRAME|SS_NOTIFY,rect,this);
m_pList[i].m_Index = i; //記錄預(yù)覽窗口索引
}
return TRUE;
}