Solved

Trapping a windows dlg box.

Posted on 1998-11-19
7
278 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
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 

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 Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

This article explains how to create forms/units independent of other forms/units object names in a delphi project. Have you ever created a form for user input in a Delphi project and then had the need to have that same form in a other Delphi proj…
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 this tutorial you'll learn about bandwidth monitoring with flows and packet sniffing with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're interested in additional methods for monitoring bandwidt…
You have products, that come in variants and want to set different prices for them? Watch this micro tutorial that describes how to configure prices for Magento super attributes. Assigning simple products to configurable: We assigned simple products…

757 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

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now