1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74
   | procedure TFrmTestStructureMemoire.TimerAutoSetPrintFileName(Sender: TObject);
var
  HwndEdit, HwndButton: HWND;
  lpClassName: PChar;	// pointer to class name
  lpWindowName: PChar; 	// pointer to window name
  lpString: PChar;       // address of string
  HwndParent: HWND;
  HwndChildAfter: HWND;	// handle to a child window
  lpszClass: PChar;	    // pointer to class name
  lpszWindow: PChar;	    // pointer to window name
  lpRes : array[0..256] of Char;
  TmpStr : String;
begin
      lpClassName:= nil; //'#32770';	                // pointer to class name
      lpWindowName:= 'Imprimer dans un Fichier'; 	// pointer to window name
      {Récupère le handle de la boite de dialogue Ouvrir}
      HwndParent := FindWindow(lpClassName, lpWindowName);
 
      if HwndParent <> 0 then begin
         if GetWindowText( HwndParent, lpRes, 256) > 0 then begin
            FichierLog('ShowMessage','Parent GetWindowText',lpRes);
         end;
 
         { Mettre la fenêtre au premier plan en connaissant son handle }
         BringWindowToTop(HwndParent);
 
         HwndChildAfter := GetWindow(HwndParent, GW_CHILD);
         if HwndChildAfter <> 0 then begin
 
            lpszClass := 'Edit';
            lpszWindow := nil;
            HwndEdit  := FindWindowEx(HwndParent, HwndChildAfter, lpszClass, lpszWindow);
            if HwndEdit <> 0 then begin
               if GetWindowText( HwndEdit, lpRes, 256) > 0 then begin
                  FichierLog('ShowMessage','Old Edit GetWindowText', lpRes);
               end;
               TmpStr := '.\PrintFile' + IntToStr(Timer1.Tag) + '.txt';
               if DeleteFile(TmpStr) then begin
                  FichierLog('ShowMessage','DeleteFile', TmpStr);
               end;
               lpString := PChar(TmpStr);
               // lpString := nil;
               // if not SetWindowText(HwndEdit, lpString) then begin
               //    FichierLog('ShowMessage','SetWindowText', IntToStr(GetLastError()));
               // end else begin
                   SendMessage(HwndEdit, WM_SETTEXT, 0, Longint(lpString));
                   SendMessage(HwndEdit, CM_TEXTCHANGED, 0, 0);
                   if GetWindowText( HwndEdit, lpRes, 256) > 0 then begin
                      FichierLog('ShowMessage','New Edit GetWindowText', lpRes);
                   end;
               //end;
            end else begin
                FichierLog('ShowMessage','FindWindowEx', IntToStr(GetLastError()));
            end;
 
            lpszClass := 'Button';
            lpszWindow := 'OK';
            HwndButton  := FindWindowEx(HwndParent, HwndChildAfter, lpszClass, lpszWindow);
            if HwndButton <> 0 then begin
               // SendMessage(HwndButton, BM_CLICK, 0, 0);
               SendMessage(HwndButton, WM_LBUTTONDOWN, 0, 0);
               SendMessage(HwndButton, WM_LBUTTONUP, 0, 0);
            end else begin
                FichierLog('ShowMessage','FindWindowEx', IntToStr(GetLastError()));
            end;
 
 
         end else begin
             FichierLog('ShowMessage','GetWindow', IntToStr(GetLastError()));
         end;
      end else begin
          FichierLog('ShowMessage','FindWindow', IntToStr(GetLastError()));
      end;
end; | 
Partager