Solved

Trapping a windows dlg box.

Posted on 1998-11-19
7
283 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
  • 4
  • 3
7 Comments
 
LVL 20

Accepted Solution

by:
Madshi earned 200 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

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Have you ever had your Delphi form/application just hanging while waiting for data to load? This is the article to read if you want to learn some things about adding threads for data loading in the background. First, I'll setup a general applica…
Introduction I have seen many questions in this Delphi topic area where queries in threads are needed or suggested. I know bumped into a similar need. This article will address some of the concepts when dealing with a multithreaded delphi database…
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an antispam), the admini…

726 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