15 мая 2023 года "Исходники.РУ" отмечают своё 23-летие!
Поздравляем всех причастных и неравнодушных с этим событием!
И огромное спасибо всем, кто был и остаётся с нами все эти годы!

Главная Форум Журнал Wiki DRKB Discuz!ML Помощь проекту


AfxMessageBoxEx

Antonio Jorge Marques Pires -- AntonioPires@mail.telepac.pt
Thursday, November 07, 1996

Environment : Visual C++ 4.2-flat, Win 95, MSDN

Hi there,
I have created a extension to AfxMessageBox. It is destroyed after a a
specified time or by user. Please comment.

* Can  I use MFC functionality from any class without CObject derivation?
* How can I create code without timers IDs conflicts?

*************************************************************************=
***



 Antonio Jorge Marques Pires (Physics Eng.)

 Rua Santo Antonio S/N      mailto:AntonioPires@mail.telepac.pt
 Vila Pouca                        Tel.:  (351 39) 947074
 3040 Cernache                  Pager: (351) 094200 (117756)
 PORTUGAL
*************************************************************************=
***





_________________________________________________________________________=
___



#define MessageBoxTimer 200

VOID CALLBACK MessageBoxTimerProc(=20
	HWND hwnd,        // handle of window for timer messages=20
	UINT message,     // WM_TIMER message                   =20
	UINT idTimer,     // timer identifier                    =20
	DWORD dwTime)     // current system time               =20
{=20

	HWND hWndMessageBox =3D ::FindWindow(NULL, AfxGetAppName( ));
	if (hWndMessageBox !=3D NULL) {
		::EndDialog(hWndMessageBox, IDCANCEL);
	}

	//::KillTimer(hwnd, MessageBoxTimer);
}=20

int AfxMessageBoxEx(UINT uiNumberOfSeconds, LPCTSTR lpszText, UINT nType,
UINT nIDHelp) {

	HWND hWndTop;
	CWnd* pWnd =3D CWnd::GetSafeOwner(NULL, &hWndTop);
	if (pWnd =3D=3D NULL) {
		return 0;
	}


	UINT uResult =3D ::SetTimer(pWnd->GetSafeHwnd(), MessageBoxTimer,
uiNumberOfSeconds*1000, (TIMERPROC) MessageBoxTimerProc);

	if (uResult =3D=3D 0) {=20
		AfxMessageBox("N=E3o existem timers dispon=EDveis no sistema!!!",
MB_ICONSTOP);=20

		// same as double-clicking on main window close box
		ASSERT(AfxGetMainWnd() !=3D NULL);
		AfxGetMainWnd()->SendMessage(WM_CLOSE);

		return 0;
	}=20

	int iResult =3D AfxMessageBox(lpszText, nType, nIDHelp);

	::KillTimer(pWnd->GetSafeHwnd(), MessageBoxTimer);

	return iResult;
}
_________________________________________________________________________=
___





David Lowndes -- David.Lowndes@bj.co.uk
Friday, November 08, 1996

[Mini-digest: 2 responses]

> Can  I use MFC functionality from any class without CObject derivation?
<
Yes.

* How can I create code without timers IDs conflicts?
<
Antonio,

Use the window handle as the timer ID value.

-----From: Mike Blaszczak 

At 04:54 11/7/96 -0000, "Antonio Jorge Marques Pires"
 wrote:

>Environment : Visual C++ 4.2-flat, Win 95, MSDN

>I have created a extension to AfxMessageBox. It is destroyed after a a
>specified time or by user. 

>* Can  I use MFC functionality from any class without CObject derivation?
>* How can I create code without timers IDs conflicts?

I can't understand your questions.

> Please comment.

But I will offer that I think it is a very bad idea to write your own function
which begins with "Afx" in its name.  By convention, those names are used by
MFC.  It is possible that your application will some day not work.

.B ekiM
http://www.nwlink.com/~mikeblas/
I'm afraid I've become some sort of speed freak.
These words are my own. I do not speak on behalf of Microsoft.





| Вернуться в корень Архива |