How to display a MessageBox, which can disappear itself?

  • Thread starter Thread starter larry
  • Start date Start date
L

larry

I want to display a message to user when machine is doing background
job, when the job is finished the message disappear automatically. Do I
have to create a modeless dialogbox to implement it? Is there a easier
way to to that?

Larry
 
larry said:
I want to display a message to user when machine is doing background
job, when the job is finished the message disappear automatically. Do I
have to create a modeless dialogbox to implement it? Is there a easier
way to to that?

If you google for

timed message box

you'll get an incredible number of hits describing pre-made solutions.

Regards,
Will
 
Larry,
First set up a call back function as follows:

LRESULT CALLBACK DlgFn(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam)
{
switch (message)
{
case WM_INITDIALOG:
return TRUE;
break;
case WM_COMMAND:
switch (LOWORD(wParam))
{ case IDOK:
case 2:
EndDialog(DlgBoxHandle, LOWORD(wParam));
DlgBoxHandle = NULL;
DlgItemCtrlHandle = NULL;
return TRUE;
break;
}
break;
}
return FALSE;
}

Second: Set up a message function to create and display the dialog box:

void ShowMessage(int type)
{
if (!DlgBoxHandle)
{
DlgBoxHandle = CreateDialog(hInst, MAKEINTRESOURCE
(IDD_DIALOG_BOX),hWnd,(DLGPROC)DlgFn);
DlgItemCtrlHandle = GetDlgItem(DlgBoxHandle, IDC_TEXT_CTRL);
SetDlgItemText(DlgBoxHandle,IDC_TEXT_CTRL,_T(“Some Sample Textâ€));
}

UpdateWindow(DlgItemCtrlHandle);
ShowWindow(DlgItemCtrlHandle,SW_SHOW);
SetFocus(DlgBoxHandle);
if (DlgBoxHandle && type)
{
DestroyWindow(DlgBoxHandle);
DlgBoxHandle = NULL;
DlgItemCtrlHandle=NULL;
}
}

Third:

Call the function with a parameter of 0 - this will keep the dialog box in
display on top of all other windows until you call it again with
ShowMessage(1) which will destroy the dialog box.
ShowMessage(0);

Some advice: Be very weary of what mvps tell you and especially this one De
Paolo.

regards,
John
 
Hi John,
Thank you very much for your help. I also thank all the people who tried
to help me.

Have a good day



Larry
 
You are welcome. If you need reliable information about Microsoft products
again, a good site is codeguru.com. Many of the authors do not work for
Microsoft and usually tell it like it is.

Glad I was able to help!

John
 
Back
Top