添加dialog並且於20秒內關閉

 主要透過windows OnTimer機制來關閉

/////////////////////////////////////////////////////////////////////////////
//Po add 0809 dialog add
class Po_Dialog : public CDialogSK
{
public:
Po_Dialog();


// Dialog Data
//{{AFX_DATA(CAboutDlg)
enum { IDD = IDD_DIALOG1 };
UINT m_Timer;
//}}AFX_DATA

// ClassWizard generated virtual function overrides
//{{AFX_VIRTUAL(CAboutDlg)
protected:
virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV support
//}}AFX_VIRTUAL

// Implementation
protected:
//{{AFX_MSG(CAboutDlg)
//}}AFX_MSG
DECLARE_MESSAGE_MAP()

public:
virtual BOOL OnInitDialog();
afx_msg void OnClose();
afx_msg void OnTimer(UINT nIDEvent);
afx_msg HBRUSH CtlColor(CDC* pDC, UINT nCtlColor);
afx_msg HBRUSH OnCtlColor( CDC* pDC, CWnd* pWnd, UINT nCtlColor);
int Show_time();
int Po_Dialog_OpenTime;
void Show_Text();
int iInum;
};

HBRUSH Po_Dialog::OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor)
{
HBRUSH hbr = CDialog::OnCtlColor(pDC, pWnd, nCtlColor);

// TODO: Change any attributes of the DC here
//设置CEdit背景色
HBRUSH hbru = ::CreateSolidBrush(RGB(255,255,0));

// CEdit *pEdit = (CEdit *)GetDlgItem(IDC_EDIT_PROID);
// pWnd = GetDlgItem(IDC_EDIT_PROID);
// pDC = pWnd->GetDC();
if (pWnd->GetDlgCtrlID() == IDC_STATIC )
{
//调整背景颜色
// pDC->SetBkMode(TRANSPARENT);
pWnd = GetDlgItem(IDC_STATIC);
//调整文本颜色
// pDC = pWnd->GetDC();
CRect rect;
pWnd->GetClientRect(&rect);
pDC->FillSolidRect(&rect,RGB(255,250,50));//在指定区域内填充
pDC->SetTextColor(RGB(255,255,255));
// pDC->SetBkColor(RGB(160,150,50));
return hbru;
}
// TODO: Return a different brush if the default is not desired
return hbr;
}

Po_Dialog::Po_Dialog() : CDialogSK(Po_Dialog::IDD)
{
//{{AFX_DATA_INIT(CAboutDlg)
//}}AFX_DATA_INIT
}

void Po_Dialog::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//DDX_Control(pDX, IDC_BUTTON1, OnClose);
//{{AFX_DATA_MAP(CAboutDlg)
//}}AFX_DATA_MAP
}

BEGIN_MESSAGE_MAP(Po_Dialog, CDialog)
//{{AFX_MSG_MAP(CAboutDlg)
ON_WM_TIMER()
ON_BN_CLICKED(IDC_BUTTON1, OnClose)
// No message handlers
//}}AFX_MSG_MAP
END_MESSAGE_MAP()

void Po_Dialog::Show_Text(){
SetWindowText("注意!! 您尚未連上基地台");
CEdit* Po_TextView = (CEdit*)GetDlgItem(IDC_STATIC);
CFont font;
VERIFY(font.CreateFont(
0, // nHeight
0, // nWidth
0, // nEscapement
0, // nOrientation
FW_NORMAL, // nWeight
FALSE, // bItalic
FALSE, // bUnderline
0, // cStrikeOut
ANSI_CHARSET, // nCharSet
OUT_DEFAULT_PRECIS, // nOutPrecision
CLIP_DEFAULT_PRECIS, // nClipPrecision
DEFAULT_QUALITY, // nQuality
DEFAULT_PITCH | FF_SWISS, // nPitchAndFamily
_T("標楷體"))); // lpszFacename
Po_TextView->SetFont(&font);
//Po_TextView->CenterWindow();
//GetDlgItem(IDC_STATIC)->CenterWindow(this);
//Po_TextView->GetDC()->SetTextColor(RGB(0,0,255));
GetDlgItem(IDC_STATIC)->GetDC()->SetTextColor(RGB(0,0,255));


Po_TextView->SetWindowText(_T("請您確認是否有連上網路"));
}

BOOL Po_Dialog::OnInitDialog()
{
CDialog::OnInitDialog();

Po_Dialog_OpenTime = 1;
iInum = 20;

Show_Text();

m_Timer = SetTimer(Po_Dialog_OpenTime, 1000, NULL);

//OnClose();
return TRUE;
}


void Po_Dialog::OnClose(){
KillTimer(m_Timer);
OnOK();
}

int Po_Dialog::Show_time(){
CString strPrint = _T("");
strPrint.Format(_T("畫面將於%3.2d秒鐘內關閉"), iInum--);
CClientDC dc(this);
dc.TextOut(0,0, strPrint);

return iInum;
}

void Po_Dialog::OnTimer(UINT nIDEvent) {

switch(nIDEvent){
case 1:

if(Show_time() <= 0){
EndDialog(IDD_DIALOG1);
}
break;
default:

break;
}

//Po_Dialog::OnTimer(nIDEvent);
}

 

 

arrow
arrow
    文章標籤
    dialog afx idc
    全站熱搜
    創作者介紹
    創作者 ooieueioo 的頭像
    ooieueioo

    ooieueioo的部落格

    ooieueioo 發表在 痞客邦 留言(0) 人氣()