?
Solved

Trapping a windows dlg box.

Posted on 1998-11-19
7
Medium Priority
?
289 Views
Last Modified: 2010-04-04
How do I trap a dlg box that windows displays through my application? For example, if say drive A: is not ready for access and I try to access it windows will display a system modal dlg box telling me there is no disk in the drive. Abort, Retry, Ignore. How do I trap this message, or any simlar dlg, and prevent it from getting displayed?

Thanks
0
Comment
Question by:LostOne
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 3
7 Comments
 
LVL 20

Accepted Solution

by:
Madshi earned 800 total points
ID: 1347388
LostOne,

"SetErrorMode(SEM_FAILCRITICALERRORS or SEM_NOOPENFILEERRORBOX);"

this is what I'm doing in each and every of my programs in the initialization. It prevents most of these windows system modal dialog boxes from being displayed.
Please reject my answer if it doesn't work...

Regards, Madshi.
0
 

Author Comment

by:LostOne
ID: 1347389
Where exactly do you put SetErrorMode(SEM_FAILCRITICALERRORS or SEM_NOOPENFILEERRORBOX)? I stuck it in the frmMain OnCreate event and it doesn't seem to work.

Thanks
0
 
LVL 20

Expert Comment

by:Madshi
ID: 1347390
LostOne,

I put it in the initialization part of a unit that I import into all my projects. But it should work in Form.Create, too. That means if you're calling your CopyFile or whatever functions after creating the form.
That brings me to another question. I thought you want to prevent windows from showing these boxes as a result to YOUR file operations. Is that what you want? Or do you want to trap these boxes SYSTEMWIDE?

Regards, Madshi.
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Author Comment

by:LostOne
ID: 1347391
I'm doing a check to see if a drive is ready for access:

GetDir(0, OldDirectory);
  {$I-}
  ChDir(DriveLetter + ':\');
  {$I+}
  if IoResult <> 0 then
    Result := False
  else
    Result := True;
  ChDir(OldDirectory);

If I check drive A or a cd-rom drive that is not ready I get the system modal dlg box. I want to prevent that from happening. It looks like SetErrorMode should do what I want.. i'm not sure why it doesn't. I'm running NT 4.0 if that makes a difference.

0
 
LVL 20

Expert Comment

by:Madshi
ID: 1347392
On my computer your code works perfectly even without SetErrorMode. But I'm using win95...
Please check the following code. It should work with winNT as well:

function DriveExists(drive: char) : boolean;
var i1  : cardinal;
    wfd : TWin32FindData;
begin
  result:=false;
  i1:=GetFileAttributes(pchar(string(drive+':')));
  if (integer(i1)=-1) or (FILE_ATTRIBUTE_DIRECTORY and i1=0) then exit;
  i1:=FindFirstFile(PChar(drive+':\*.*'),wfd);
  result:=(i1<>INVALID_HANDLE_VALUE) or (GetLastError in [2,18]);
  // 2 = Datei nicht gefunden / 18 = keine weiteren Dateien
  if i1<>INVALID_HANDLE_VALUE then windows.FindClose(i1);
end;

(P.S: If you're not using Delphi 4, you should replace "i1: cardinal" to "i1: integer", cause Delphi 3 (or lower) has no real cardinal type.)
0
 

Author Comment

by:LostOne
ID: 1347393
Yes, that works perfect under NT. Thanks!
0
 
LVL 20

Expert Comment

by:Madshi
ID: 1347394
No problem...   :-)
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Creating an auto free TStringList The TStringList is a basic and frequently used object in Delphi. On many occasions, you may want to create a temporary list, process some items in the list and be done with the list. In such cases, you have to…
In my programming career I have only very rarely run into situations where operator overloading would be of any use in my work.  Normally those situations involved math with either overly large numbers (hundreds of thousands of digits or accuracy re…
Monitoring a network: how to monitor network services and why? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the philosophy behind service monitoring and why a handshake validation is critical in network monitoring. Software utilized …
This is my first video review of Microsoft Bookings, I will be doing a part two with a bit more information, but wanted to get this out to you folks.
Suggested Courses
Course of the Month10 days, 19 hours left to enroll

770 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question