ImageEn for Delphi and C++ Builder ImageEn for Delphi and C++ Builder

 

ImageEn Forum
Profile    Join    Active Topics    Forum FAQ    Search this forumSearch
 All Forums
 ImageEn Library for Delphi, C++ and .Net
 ImageEn and IEvolution Support Forum
 Scanner's dialog is hidden by app

Note: You must be registered in order to post a reply.
To register, click here. Registration is FREE!

View 
UserName:
Password:
Format  Bold Italicized Underline  Align Left Centered Align Right  Horizontal Rule  Insert Hyperlink   Browse for an image to attach to your post Browse for a zip to attach to your post Insert Code  Insert Quote Insert List
   
Message 

 

Emoji
Smile [:)] Big Smile [:D] Cool [8D] Blush [:I]
Tongue [:P] Evil [):] Wink [;)] Black Eye [B)]
Frown [:(] Shocked [:0] Angry [:(!] Sleepy [|)]
Kisses [:X] Approve [^] Disapprove [V] Question [?]

 
Check here to subscribe to this topic.
   

T O P I C    R E V I E W
Homer Posted - Dec 21 2021 : 19:53:09
Is there a way to make sure the scanner's dialog does not open behind the main form of my app?
11   L A T E S T    R E P L I E S    (Newest First)
anbangs Posted - Sep 06 2022 : 03:15:29
I have similar problems, but I have found not a way to solve them :(
https://www.imageen.com/ieforum/topic.asp?whichpage=1&TOPIC_ID=5477#19104
xequte Posted - Jan 01 2022 : 14:07:24
See: https://www.imageen.com/ieforum/topic.asp?whichpage=1&TOPIC_ID=5209

Nigel
Xequte Software
www.imageen.com
Homer Posted - Dec 30 2021 : 14:21:46
Please ignore the sample code above. It is poorly written and very inefficient. It has been completely rewritten. The original problem still exists. As I mentioned before, there are two scanner UIs that open. I have not determined that they are: 1) the HP scanner's software, 2) Windows Fax/Scan software. I have not yet found out why the HP's software doesn't open each time, and sometimes it is the Windows scan UI.
Homer Posted - Dec 29 2021 : 23:02:07
More info: There seems to be two different dialogs for my scanner. One is very simple but the other has a very different layout with many more options. I need to track down what causes one to be opened over the other. The simple one is the one that get's hidden, or stuck in the 0,0 corner. I don't think this has anything to do with ImageEn. I'll let you know what I find.
Homer Posted - Dec 29 2021 : 15:57:01
There are four procedures involved. I'm still working on this, so please excuse how untity this code is.


procedure TfrmMain.BtnABSAcquireClick(Sender: TObject);
// This uses the very simple ABS Twain interface dialog box.
Var
  frmABSInterface : TfrmABSInterface;
  sColorVal, sDPIvalue : String;
  iColorVal : Integer;
  iDPIvalue : Integer;
  iDocTypeValue : integer;
begin
   ClearThumbs;
    try
      Screen.Cursor := crHourglass;
      { by David Cornelius to disable the multi-image views}
      iemvPageThumbs.Visible := False;
      { Initialize }
      sColorVal := '0';
      sDPIValue := '0';
      iDocTypeValue := iDefaultImageFormat;
      CanUpdateImage := True;
      if dxBarBtnSmooth.Down then dxBarBtnSmooth.Click;
      ImageEnView1.Cursor := crHourglass;
      {Create MyDialog} 
      frmABSInterface := TfrmABSInterface.Create2(nil, Addr(sColorVal), Addr(sDPIValue), Addr(iDocTypeValue));
      Application.ProcessMessages;
    except
       {silent exception}
    end;
    Application.ProcessMessages;
    try
      If frmAbsInterface.showModal = mrOK Then
      Begin
        Try
          iColorVal := StrToInt(sColorVal);
          iDPIValue := StrToInt(sDPIValue);
          iDocTypeValue := iDocTypeValue;  // ????? Why this code ?????
          Screen.Cursor := crDefault;
          DoABSscan(iColorVal,iDPIvalue,iDocTypeValue);
          Application.ProcessMessages;
        except
          MessageBox(Application.Handle,'Unable to acquire image. Either the scanner is '+
               'not functioning* or is not compatible with ABS Document Manager. '#13#13#13+
               '*  It may turned off, or asleep.',
               'Error',MB_OK);
          exit;
        end;
      end;
    finally
      Try
        FreeAndNil(frmABSInterface);
        cxgrdGrid1DBTableView1.NavigatorButtons[12].Click;
      finally
        Application.ProcessMessages;
        if Screen.Cursor <> crDefault then Screen.Cursor := crDefault;
        ImageEnView1.Cursor := crDefault;
      end;
    end;
end;



procedure TfrmABSinterface.btnAcquireClick(Sender: TObject);
begin
  { Sends values back to calling procedure. }
  Try
    if DisableScaning then
    begin
      ModalResult := mrCancel;
      Exit;
    end;
    gbOEM_Show_Dialog  := chkScannerSoftware.Checked;
    gbAutoFeed         := chkAutoFeed.Checked;
    gbDuplexEnabled    := chkDuplexEnabled.Checked;

    String(fColorVal^) := IntToStr(cboColors.ItemIndex);
    String(fDPIValue^) := IntToStr(cboResolution.ItemIndex);
    Integer(fDocType^) := rgDocType.ItemIndex;
    SaveProperties;
    ModalResult := mrOK;
  except
    ModalResult := mrCancel;
    MessageBox(Application.Handle,'Unable to acquire image.','Error',MB_OK);
  end;
end;


procedure TfrmABSinterface.SaveProperties;
var
  SelectedDPI: integer;
begin
  with frmMain.ImageEnMView1.MIO do
  begin
    AcquireParams.XResolution         := DPI[SelectedDPI];
    AcquireParams.YResolution         := DPI[SelectedDPI];
    AcquireParams.PixelType           := TIEAcquirePixelType( cboColors.ItemIndex );
    AcquireParams.FeederEnabled       := chkAutoFeed.Checked;
    AcquireParams.AutoFeed            := chkAutoFeed.Checked;
    AcquireParams.DuplexEnabled       := chkDuplexEnabled.Checked;
    AcquireParams.VisibleDialog       := chkScannerSoftware.Checked;
    TwainParams.ProgressIndicators    := True;
  end;

  with frmMain.ImageEnIO1 do
  begin
    AcquireParams.XResolution         := DPI[SelectedDPI];
    AcquireParams.YResolution         := DPI[SelectedDPI];
    AcquireParams.PixelType           := TIEAcquirePixelType( cboColors.ItemIndex );
    AcquireParams.FeederEnabled       := false;
    AcquireParams.AutoFeed            := false;
    AcquireParams.DuplexEnabled       := false;
    if chkScannerSoftware.enabled then
      AcquireParams.VisibleDialog       := chkScannerSoftware.Checked;
    TwainParams.ProgressIndicators := True;
  end;

end;


Procedure TfrmMain.DoABSscan(SelectedColors, SelectedDPI, SelectedDocType: Integer);
Begin
  CanUpdateImage := True;
  Application.ProcessMessages;
  Try
    if SelectedDocType < 2 then
    begin
      if ImageEnIO1.Acquire = False then
      begin
        MessageBox(Application.Handle,'We were unable to scan this image. The '+
          'scanner may not ready. If your scanner is turned on and warmed up, '+
          'it may not be fully compatible with ABSŪ. You should try the '+
          'manufacturer''s scanning software as an alternative. Another '+
          'alternative is to use your scanner directly, and then import the '+
          'scanned image into ABS Document Manager.','Quick & Easy Error',MB_OK);
        exit;
      end;
    end;
  except
    on E: Exception do
    begin
    MessageBox(Application.Handle,PChar(E.Message),PChar('Scan Failed'),MB_OK + MB_ICONERROR);
    exit;
    end;
  end;
  Application.ProcessMessages;
  try
    ImageEnView1.AutoStretch := true;
  except
  end;


  Try
    case SelectedDocType of
      0:begin {JPG}
          NewFileName := GetFileName(gsDocManPath, '.JPG');
          ImageEnIO1.Params.JPEG_Quality := giJPEG_Better;
          ImageEnIO1.SaveToFile(gsDocManPath + NewFileName);
        end;
      1:begin {PNG}
          NewFileName := GetFileName(gsDocManPath, '.PNG');
          ImageEnIO1.Params.PNG_Compression:=9;
          ImageEnIO1.Params.PNG_Interlaced := False;
          ImageEnIO1.SaveToFile(gsDocManPath + NewFileName);
        end;
      2:begin {PDF}
          ImageEnMView1.Clear;
          if not ImageEnMView1.MIO.Acquire then exit;
          Application.ProcessMessages;
          NewFileName := frmMain.GetFileName(gsDocmanPath, '.PDF');
          ImageEnMView1.MIO.SaveToFilePDF(gsDocManPath + NewFileName);
        end;
    end;
    Application.ProcessMessages;

//    IsNewImage := True;
    // Save Image to File.
    Application.ProcessMessages;
    qImageList.Append ;  { Append New image info to database. }
    qImageList.FieldByName('FK_ID').AsInteger := StrToInt(gsHHkey);
    qImageList.FieldByName('ImageName').AsString := NewFileName;
    qImageList.FieldByName('Caption').AsString := 'Scanned '+ DateTimeToStr(Now);
    qImageList.FieldByName('DateStamp').AsDateTime:= Date;
    qImageList.FieldByName('HHName').AsString := AccountName;
    Application.ProcessMessages;
    qImageList.Post;
    Application.ProcessMessages;
    qImageList.Last;
    Application.ProcessMessages;
    RzStatusPane3.Caption := 'File: ' + qImageList.FieldByName('ImageName').AsString;
  Except
    MessageBox(Application.Handle,
        PChar('Unable to save this document. Please try to save it manually.'),
        PChar('FYI'), MB_OK + MB_ICONINFORMATION);
  end;
  RzProgressBar1.Percent := 0;
  Application.ProcessMessages;
 end;

xequte Posted - Dec 29 2021 : 15:01:16
Hi

Can you show me the code that closes your MyDialog and displays the scanner dialog. Perhaps the closing of the calling window trips it up.

Nigel
Xequte Software
www.imageen.com
Homer Posted - Dec 29 2021 : 12:54:00
Sorry for the delay in response. Santa Clause kept me from the keyboard.

The demo you suggested was one of the ones I had already tried. With it, the scanner's dialog opens in the top left (0,0). However, that dialog is opened by the demo app's main form. Mine is different. If you look at the previous image, you'll see my main form creates a dialog (MyDialog) and that dialog opens the scanner's dialog.

Perhaps this image will make clear what is happening. If MyDialog has the "show dialog" checkbox checked when the OK button is clicked. MyDialog closes and the scanner's dialog opens behind the main form. You'll see Item B in the image below shows the scanner's dialog in the task bar. Hovering over it shows Item A. If you minimize my main form, the scanner's dialog is there, hiding behind the main form.



xequte Posted - Dec 23 2021 : 17:37:25
Hmmm. I cannot reproduce that.

Please test this version of the Acquire Demo that acquires via a sub-form:

http://imageen.com/temp/AllAcquire_Dlg.zip

Also, please check the FormStyle properties of your forms to ensure they are fsNormal.


Nigel
Xequte Software
www.imageen.com
Homer Posted - Dec 22 2021 : 20:33:45
I can't think of a way to set the z-order of the scanner's dialog because I won't know the handle or title (too many unknown brands).
Homer Posted - Dec 22 2021 : 20:12:55
Good question. In the Acquire All demo, the position of the OEM dialog depends on the selection of the input device. Actually, in my case it was the same HP scanner, but it behaved differently depending on whether I picked Twain or Wia. With WIA the dialog opened at the very top left (0,0). With Twain, the dialog opened relative to the app's main form. In other words, its top-left was always about 50px above and to the left of the Acquire button. If I moved the main form somewhere else, the OEM dialog opened relative to its new position.

However, my app has its own dialog separate from its main form. On that dialog, the user can check a box to use the OEM dialog or not (see the screen capture). If not, the scanner just works. If they check the box for the scanner's dialog, it opens behind the app's main form. Not behind my dialog, but behind the main form where it is completely hidden. It didn't matter if it was Twain or Wia.

This is my main form with my dialog showing on top.
xequte Posted - Dec 21 2021 : 22:34:21
Hi

Does the same issue happen in our demo? Is this using Twain?

Nigel
Xequte Software
www.imageen.com