2008年1月30日星期三

VC++ 改变Dialog窗口大小及定位,SetWindowPos()

1.引用库函数 #include "easysize.h",见:
codeproject::Easysize

2.函数SetWindowPos
原型为BOOL SetWindowPos(const CWnd * pWndInsertAfter,int x,int y,int cx,int cy,UINT nFlags);
pWndInsertAfter为指向标识窗口类型的CWnd对象的指针。
x,y为窗口左上角的坐标。
cx,cy为窗口的宽与高。
nFlags确定窗口的大小及位置。当为SWP_NOSIZE时,忽略cx,cy。当为SWP_NOMOVE时,忽略x,y。


3.代码:
BEGIN_EASYSIZE_MAP(CUnpackConfirm)
EASYSIZE(IDOK,ES_KEEPSIZE,ES_KEEPSIZE,ES_BORDER,ES_BORDER,0)
EASYSIZE(IDCANCEL,ES_KEEPSIZE,ES_KEEPSIZE,ES_BORDER,ES_BORDER,0)
EASYSIZE(IDC_STATIC_TEXT,IDC_STATIC_TITLE,ES_BORDER,ES_BORDER,ES_BORDER,0)

END_EASYSIZE_MAP

BOOL CUnpackConfirm::OnInitDialog()
{

CDialog::OnInitDialog();


// * set for easysize.h *
INIT_EASYSIZE;

if(!t_ColorStatic) //
t_ColorStatic.SubclassDlgItem(IDC_STATIC_TITLE,this);


if(!s_ColorStatic) //
s_ColorStatic.SubclassDlgItem(IDC_STATIC_TEXT,this);


intialTitleFont();
intialTextFont();

t_ColorStatic.SetWindowText("Sollen jetzt folgende Daten zurückgespielt werden?");

//--get CView pointer
CMDIFrameWnd *pFrame = (CMDIFrameWnd*)AfxGetApp()->m_pMainWnd;
CMDIChildWnd *pChild = (CMDIChildWnd *) pFrame->GetActiveFrame();
CUnpackView *pView = (CUnpackView *) pChild->GetActiveView();
//--

CString text (_T(""));

lHigh = 200;

switch (pView->nGroupFocus)
{
case GROUP_UNPACK:
if (pView->m_pageUnpack.m_pUnpackListCtrl.isApolloChecked)
{
text += "- Apollo.mdb.gz\n";
addHigh(); //lHigh += 10;

......

setText(text);

UpdateData(false);
Invalidate();

//MFC: CWnd::SetWindowPos
CRect Rect1;
pFrame->GetWindowRect(&Rect1); //get size and position of mainframe

//CRect Rect2;
//GetDlgItem(IDC_STATIC_TEXT)->GetWindowRect(&Rect2); // ???????
//Rect2.bottom = lHigh + Rect2.bottom;


long x, y;
x = Rect1.left + (Rect1.Width() - 420)/2;
y = Rect1.top + (Rect1.Height() - lHigh)/2;

CUnpackConfirm::SetWindowPos(NULL,
x , //left
y, //top
420, //width
lHigh, // hight.
SWP_SHOWWINDOW);


UPDATE_EASYSIZE;

UpdateData();
Invalidate();

return TRUE; // return TRUE unless you set the focus to a control
// EXCEPTION: OCX Property Pages should return FALSE

}

没有评论: