Solved

Shfileoperation fails and replacing windows messages with custom one

Posted on 2003-12-03
6
271 Views
Last Modified: 2010-04-05
 Hi, can we display my own message when the shfileoperation function fails?
 such as diskette is full or cannot read from a specified device..  because i try using the try..except still it does not work. can you help me please?
0
Comment
Question by:vbeginner
[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
6 Comments
 
LVL 27

Expert Comment

by:kretzschmar
ID: 9865665
shfileoperation is a function,
which returns a value <> 0,
if the operation fails

which number which failure represents i do not know,
maybe it is needed to use the GetLastError-api

a sceleton could shown like

var
  op_result : Integer;
begin
  op_result := shfileoperation(....);
  if op_result <> 0 then
  begin
     //yourmessage here
     //or
     case op_result of
       .....
     end;
  end;

meikl ;-)
0
 

Author Comment

by:vbeginner
ID: 9879184
meikl, a problem with shfileoperation is that when it displays a message box and the user is prompted to select retry or quit and it selects quit it returns zero..
0
 
LVL 34

Expert Comment

by:Slick812
ID: 9935018
hello vbeginner, not to sure about what to do here for your request, The SHFileOperation will show the error messages for disk full and others. . . here is some code for a SHFileOperation, I get the Result of thethis function in Res1, as you know if Res1 is Zero then operation was sucessful (at least to the OS, which may NOT be the same opinion for you, since it may not have done anything).  This Res1 will be a certain value for certain failures. .  I did not find any documentation about these result values, but the two values I used in one of my app were
117
and
1026

there may or may not be other values, and this value may or may not be consistant between different windows versions. . . I do not have time now to research this. . .
If the user aborts, (presses the Cancel button, instead of the Retry button), I am not sure that there is a way to any info about what the "Problem" may have been for the Error message. . .

procedure TForm1.sbut_ShellOpClick(Sender: TObject);
var
shFileOpRec : TSHFileOpStruct;
Res1: Integer;
ErrorStr: String;
begin
with shFileOpRec do
  begin
  Wnd    := Handle ;
  wFunc  := FO_COPY;  // what kind of operation
  pFrom  := 'E:\Bmp1.bmp' ;     // from
  pTo    := 'A:\' ;       // to

  fFlags :=  FOF_FILESONLY or FOF_ALLOWUNDO or FOF_SIMPLEPROGRESS {or FOF_NOCONFIRMATION} or FOF_NOERRORUI;
{the  FOF_NOERRORUI will supress all of the error messages and User Choose (Retry, Cancel)}
  // FOF_NOCONFIRMATION or FOF_RENAMEONCOLLISION;

  hNameMappings         := nil; //  Pointer;
  lpszProgressTitle     := 'Progress Title';
  end;
Res1 := SHFileOperation(shFileOpRec);
if Res1 <> 0 then
  begin
  if Res1 = 117 then
  ErrorStr := 'ERROR - Not Enough Disk Space on Drive to Copy file'
  else
  if Res1 = 1026 then
  ErrorStr := 'ERROR - From File Does NOT exist, Copy Failed'
  else
  ErrorStr := 'Unknown ERROR';
  if GetLastError <> 0 then
  ErrorStr := ErrorStr + #10 + SysErrorMessage(GetLastError);
  ShowMessage(ErrorStr);
  end else
if shFileOpRec.fAnyOperationsAborted = true then
  begin
  ShowMessage('Operation was Aborted');
  end;

end;
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!

 
LVL 34

Expert Comment

by:Slick812
ID: 9935035
If you want more control, you might consider using another method than SHFileOperation, you could even check for the free Disk space BEFORE you call the SHFileOperation
0
 
LVL 2

Expert Comment

by:-Karamja-
ID: 12382355
No comment has been added to this question in more than 21 days, so it is now classified as abandoned..
I will leave the following recommendation for this question in the Cleanup topic area:
PAQ - No Refund

Any objections should be posted here in the next 4 days. After that time, the question will be closed.

Karamja (Alan)
EE Cleanup Volunteer
0
 
LVL 1

Accepted Solution

by:
Computer101 earned 0 total points
ID: 12417734
PAQed - no points refunded (of 250)

Computer101
E-E Admin
0

Featured Post

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!

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…
In this tutorial I will show you how to use the Windows Speech API in Delphi. I will only cover basic functions such as text to speech and controlling the speed of the speech. SAPI Installation First you need to install the SAPI type library, th…
There are cases when e.g. an IT administrator wants to have full access and view into selected mailboxes on Exchange server, directly from his own email account in Outlook or Outlook Web Access. This proves useful when for example administrator want…
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.

691 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