Thng bo: Vi?c t?o ra m?t h?p tho?i Modeless v?i MFC th vi?n

D?ch tiu ? D?ch tiu ?
ID c?a bi: 103788 - Xem s?n ph?m m bi ny p d?ng vo.
Bi vi?t ny ch?ng t? lm th? no ? t?o ra m?t h?p tho?i modeless s? d?ng m?t ngu?n ti nguyn m?u h?p tho?i b?ng cch s? d?ng MFC.

? xy d?ng m?t h?p tho?i CModeless, theo cc b?c sau nn theo sau:

  1. T?o m?t h?p tho?i l?p b?t ngu?n t? CDialog v ghi cc Create() thnh vin ch?c nng c?a CDialog. V d?, b?n c th? c m? tng t? nh sau:
          class CModeless: public CDialog
                     CModeless(){ }
                     BOOL Create(UINT nID, CWnd * pWnd)
                          { return CDialog::Create(nID,pWnd);}
    Lu ?: B?n c th? cho ClassWizard t?o h?p tho?i l?p v sau ch? c?n thm cc ch?c nng Create().
  2. Vi?t m? ? xy d?ng m?t ?i t?ng c?a h?p tho?i l?p v t?o c?a s? h?p tho?i. V d?, n?u b?n c m?t tr?nh n m? m nn hi?n th? h?p tho?i, b?n c th? c m? tng t? v?i sau y:
          void CMainFrame::OnModeless()
                pdlg = new CModeless;
    ni CMainFrame::pdlg ?c ?nh ngh?a l:
    CModeless * pdlg;
    Lu ?: i?u quan tr?ng l ? phn b? ?i t?ng trn heap thay v? ngn x?p n?u b?n mu?n ngn ch?n h?p tho?i modeless ang b? ph h?y khi ch?c nng ? thot.
  3. B?n ph?i g?i CWnd::DestroyWindow() ? OnCancel, ho?c b?t c? khi no cc h?p tho?i modeless c?n ph?i ?c tiu hu?.
          void CModeless::OnCancel()
  4. Ghi ln CWnd::PostNcDestroy() trong l?p h?c c?a b?n h?p tho?i ? xa cc h?p tho?i h?p ?i t?ng:
       virtual void CModeless::PostNcDestroy() {delete this;}
    PostNcDestroy() l m?t ch?c nng thnh vin ?o c?a l?p CWnd l g?i l ch?c nng OnNcDestroy().
M?t h?p tho?i modeless l?p th?ng s? ghi ln OnOK() v OnCancel() thnh vin ch?c nng ? g?i cho DestroyWindow() v khng nn g?i cho cc l?p c s? CDialog::OnOK() v CDialog::OnCancel() cc ch?c nng. CDialog::OnOK() v CDialog::OnCancel() ch?c nng g?i EndDialog(). EndDialog() nn ?c g?i l ch? khi s? d?ng h?p tho?i phng th?c h?p.

N?u b?n ang s? d?ng h?p tho?i Data Exchange (DDX) v h?p tho?i xc nh?n d? li?u (DDV), b?n ang OnOK() handler cho l?p h?c h?p tho?i c?a b?n c th? gi?ng v?i cc sau:
   void CModeless::OnOK()
           if (!UpdateData(TRUE))
               TRACE0("UpdateData failed during dialog termination\n");
               // The UpdateData routine will set focus to correct item
Bung t?t c? | Thu g?n t?t c?

Thu?c tnh

ID c?a bi: 103788 - L?n xem xt sau cng: 17 Thang Tam 2011 - Xem xt l?i: 2.0
p d?ng
  • Microsoft Foundation Class Library 4.2, khi ?c dng v?i:
    • Microsoft Visual C++ 1.0 Professional Edition
    • Microsoft Visual C++ 1.52 Professional Edition
    • Microsoft Visual C++ 2.1
    • Microsoft Visual C++ 4.0 Standard Edition
T? kha:
kbdlg kbinfo kbuidesign kbmt KB103788 KbMtvi
My d?ch
QUAN TRONG: Bi vi?t ny ?c d?ch b?ng ph?n m?m d?ch my c?a Microsoft ch? khng ph?i do con ng?i d?ch. Microsoft cung c?p cc bi vi?t do con ng?i d?ch v c? cc bi vi?t do my d?ch ? b?n c th? truy c?p vo t?t c? cc bi vi?t trong C s? Ki?n th?c c?a chng ti b?ng ngn ng? c?a b?n. Tuy nhin, bi vi?t do my d?ch khng ph?i lc no c?ng hon h?o. Lo?i bi vi?t ny c th? ch?a cc sai st v? t? v?ng, c php ho?c ng? php, gi?ng nh m?t ng?i n?c ngoi c th? m?c sai st khi ni ngn ng? c?a b?n. Microsoft khng ch?u trch nhi?m v? b?t k? s? thi?u chnh xc, sai st ho?c thi?t h?i no do vi?c d?ch sai n?i dung ho?c do ho?t ?ng s? d?ng c?a khch hng gy ra. Microsoft c?ng th?ng xuyn c?p nh?t ph?n m?m d?ch my ny.
Nh?p chu?t vo y ? xem b?n ti?ng Anh c?a bi vi?t ny:103788
Khc t Ni dung trong C s Kin thc Khng con c h tr
Bi vi?t ny ni v? cc s?n ph?m m Microsoft khng c?n h? tr? n?a. Do , bi vi?t ny ?c cung c?p "nguyn b?n" v s? khng ?c c?p nh?t.

Cung cp Phan hi


Contact us for more help

Contact us for more help
Connect with Answer Desk for expert help.
Get more support from