Handling the Windows "No Disk" MessageBox

V

Vagabond Software

I have a Windows application that reads images from a CD or DVD. If the
media is removed from the drive and the user selected an image to in the
DataGrid, then Windows will display a MessageBox informing the user that no
media exists. This MessageBox also prompts the user to Cancel, Retry, or
Continue.

I don't know anything about this MessageBox except that my application
crashes a horrible death if the user selects Cancel or Continue. I would
like to be able to handle a Cancel selection if possible.

Does anyone know what this MessageBox is that Windows (XP) displays
automatically? If so, do you know how to read the DialogResult from it?

The crash comes when my application proceeds with trying a call that will
absolutely NOT work without the media. Here is my stack trace from the
resulting crash:

<type>System.ArgumentException</type>
<message>The Win32 handle you passed to Icon is invalid or of the
wrong type.</message>
<caller>.ctor</caller>
<stack> at System.Drawing.Icon..ctor(IntPtr handle)
at System.Drawing.Icon.FromHandle(IntPtr handle)
at DCDLibrary.IconTool.GetLargeIcon(String filename) in C:\Documents and
Settings\clfenley\My Documents\Visual Studio
Projects\InspectionViewer\DCDImaging\IconTool.vb:line 138
at InspectionViewer.ViewerMain.GetPlans(String resultsId) in C:\Documents
and Settings\clfenley\My Documents\Visual Studio
Projects\InspectionViewer\InspectionViewer\ViewerMain.vb:line 864
at InspectionViewer.ViewerMain.GetImages(String resultsId) in
C:\Documents and Settings\clfenley\My Documents\Visual Studio
Projects\InspectionViewer\InspectionViewer\ViewerMain.vb:line 758
at InspectionViewer.ViewerMain.ShowDetailsObjects(String resultsId) in
C:\Documents and Settings\clfenley\My Documents\Visual Studio
Projects\InspectionViewer\InspectionViewer\ViewerMain.vb:line 1161
at InspectionViewer.ViewerMain.DataGrid_CurrentCellChanged(Object sender,
EventArgs e) in C:\Documents and Settings\clfenley\My Documents\Visual
Studio Projects\InspectionViewer\InspectionViewer\ViewerMain.vb:line 464
at System.Windows.Forms.DataGrid.OnCurrentCellChanged(EventArgs e)
at System.Windows.Forms.DataGrid.set_CurrentCell(DataGridCell value)
at System.Windows.Forms.DataGrid.OnMouseDown(MouseEventArgs e)
at System.Windows.Forms.Control.WmMouseDown(Message&amp; m, MouseButtons
button, Int32 clicks)
at System.Windows.Forms.Control.WndProc(Message&amp; m)
at System.Windows.Forms.ControlNativeWindow.OnMessage(Message&amp; m)
at System.Windows.Forms.ControlNativeWindow.WndProc(Message&amp; m)
at System.Windows.Forms.NativeWindow.DebuggableCallback(IntPtr hWnd,
Int32 msg, IntPtr wparam, IntPtr lparam)
at System.Windows.Forms.UnsafeNativeMethods.DispatchMessageW(MSG&amp;
msg)
at
System.Windows.Forms.ComponentManager.System.Windows.Forms.UnsafeNativeMethods+IMsoComponentManager.FPushMessageLoop(Int32
dwComponentID, Int32 reason, Int32 pvLoopData)
at System.Windows.Forms.ThreadContext.RunMessageLoopInner(Int32 reason,
ApplicationContext context)
at System.Windows.Forms.ThreadContext.RunMessageLoop(Int32 reason,
ApplicationContext context)
at System.Windows.Forms.Application.Run(Form mainForm)
at InspectionViewer.AppState.Main() in C:\Documents and
Settings\clfenley\My Documents\Visual Studio
Projects\InspectionViewer\InspectionViewer\AppState.vb:line 86</stack>

Regards,

Carl
 
G

Gabriel Lozano-Morán

In your DCDLibrary.IconTool.GetLargeIcon(String filename) make sure that the
file exists or that you have a valid handle != IntPtr.Zero before call the
FromHandle() operation.

Gabriel Lozano-Morán
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top