Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Trapping a windows dlg box.

Posted on 1998-11-19
7
Medium Priority
?
290 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
Technology Partners: 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: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone 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

A lot of questions regard threads in Delphi.   One of the more specific questions is how to show progress of the thread.   Updating a progressbar from inside a thread is a mistake. A solution to this would be to send a synchronized message to the…
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…
In this video, Percona Solution Engineer Dimitri Vanoverbeke discusses why you want to use at least three nodes in a database cluster. To discuss how Percona Consulting can help with your design and architecture needs for your database and infras…
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.…
Suggested Courses

636 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