?
Solved

Trapping a windows dlg box.

Posted on 1998-11-19
7
Medium Priority
?
292 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 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
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 

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

Prep for the ITIL® Foundation Certification Exam

December’s Course of the Month is now available! Enroll to learn ITIL® Foundation best practices for delivering IT services effectively and efficiently.

Question has a verified solution.

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

Objective: - This article will help user in how to convert their numeric value become words. How to use 1. You can copy this code in your Unit as function 2. than you can perform your function by type this code The Code   (CODE) The Im…
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…
Is your data getting by on basic protection measures? In today’s climate of debilitating malware and ransomware—like WannaCry—that may not be enough. You need to establish more than basics, like a recovery plan that protects both data and endpoints.…
Loops Section Overview
Suggested Courses
Course of the Month15 days, 14 hours left to enroll

850 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