::MessageBox in InitInstance

Intrebari legate de programarea cu biblioteci precum MFC, ATL, WTL si GDI+.
Post Reply
User avatar
Ovidiu Cucu
Fondator
Fondator
Posts: 3776
Joined: 11 Jul 2007, 16:10
Judet: Iaşi
Location: Iasi
Contact:

::MessageBox in InitInstance

Post by Ovidiu Cucu » 12 Jul 2007, 22:47

O mica problema. Spun de la unceput: NU e quiz, NU-i stiu raspunsul.

Intr-o mica aplicatie MFC dialog-based chem de doua ori identic si la fel functia WinAPI MessageBox.
Prima data inainte de DoModal al dialogului principal, a doua oara dupa.
Cam asa:

Code: Select all

BOOL CMyApp::InitInstance()
{
   CMyDialog dlg;
   m_pMainWnd = &dlg;

   ::MessageBox(NULL, _T("A"), _T("B"), MB_OK); // merge
   dlg.DoModal();
   ::MessageBox(NULL, _T("A"), _T("B"), MB_OK); // nu mai merge

   return FALSE;
}
Nu ca n-as putea trai fara acel ::MessageBox deci, va rog, fara sfaturi si intrebari din seria "la ce bun?"!
Vreau sa stiu de ce a doua oara nu-mi apare messagebox-ul.

DAU O BERE! [:)]



Dragos Cojocari
Membru++
Membru++
Posts: 789
Joined: 11 Jul 2007, 14:11

Re: ::MessageBox in InitInstance

Post by Dragos Cojocari » 13 Jul 2007, 09:47

E din cauza ca fereastra principala a aplicatiei e distrusa in acel moment. Ca sa testezi asta comenteaza linia:

Code: Select all

m_pMainWnd = &dlg;
Vei vedea ca messagebox-ul va fi afisat.

Acuma cu cauza e putin mai complicat. Sper sa nu vorbesc prostii dar cred ca message queue nu mai e functional ptr app in acel moment.

cardasim
Specialist
Specialist
Posts: 23
Joined: 12 Jul 2007, 13:26
Judet: Iaşi
Location: IASI
Contact:

Re: ::MessageBox in InitInstance

Post by cardasim » 13 Jul 2007, 10:17

Microsoft says
Destruction of the main window causes a WM_QUIT message to be posted to the main application thread indicating to the operating system that the thread is to be terminated. Any window created after this is destroyed immediately after creation resulting in a brief flash.
http://support.microsoft.com/kb/253130

Dragos Cojocari
Membru++
Membru++
Posts: 789
Joined: 11 Jul 2007, 14:11

Re: ::MessageBox in InitInstance

Post by Dragos Cojocari » 13 Jul 2007, 10:33

Excelent link. [ne trebuie un emoticon de :thumbup:] :D

User avatar
cristitm
Membru
Membru
Posts: 68
Joined: 11 Jul 2007, 21:56

Re: ::MessageBox in InitInstance

Post by cristitm » 13 Jul 2007, 11:33

cardasim wrote:Microsoft says
Destruction of the main window causes a WM_QUIT message to be posted to the main application thread indicating to the operating system that the thread is to be terminated. Any window created after this is destroyed immediately after creation resulting in a brief flash.
http://support.microsoft.com/kb/253130
Am patit si eu asta mai demult si n-am reusit sa aflu de ce. Oricum nu era critic, dar ma bucur ca am aflat de ce.
Errare human est!

User avatar
Marius Bancila
Fondator
Fondator
Posts: 2344
Joined: 11 Jul 2007, 11:45
Judet: Timiş
Location: Timisoara
Contact:

Re: ::MessageBox in InitInstance

Post by Marius Bancila » 13 Jul 2007, 13:27

Dragos Cojocari wrote:Excelent link. [ne trebuie un emoticon de :thumbup:] :D
Dorinta ti-a fost implinita. Ai chiar doua: :thumbsup: si :thumbup: .
Marius Bancila
Fondator Codexpert, Microsoft MVP VC++
Site personal | Blog

Dragos Cojocari
Membru++
Membru++
Posts: 789
Joined: 11 Jul 2007, 14:11

Re: ::MessageBox in InitInstance

Post by Dragos Cojocari » 13 Jul 2007, 14:02

Marius Bancila wrote:
Dragos Cojocari wrote:Excelent link. [ne trebuie un emoticon de :thumbup:] :D
Dorinta ti-a fost implinita. Ai chiar doua: :thumbsup: si :thumbup: .
Woot. Excelent. :yahoo:

User avatar
Ovidiu Cucu
Fondator
Fondator
Posts: 3776
Joined: 11 Jul 2007, 16:10
Judet: Iaşi
Location: Iasi
Contact:

Re: ::MessageBox in InitInstance

Post by Ovidiu Cucu » 13 Jul 2007, 14:04

Wow! Problem solved. Mersi!
Tre sa dau cate-o bere la fiecare... :)

[ (somehow) OT ]
Florin, vii azi la Vanatorul? Vezi pe RONUA.
// sa vad si daca mi-au intrat bani pe card, ca sta gol de... stii tu de cand... am uitat si pin-ul... :yahoo:

Post Reply