AGB  ·  Datenschutz  ·  Impressum  







Anmelden
Nützliche Links
Registrieren
Zurück Delphi-PRAXiS Sprachen und Entwicklungsumgebungen Sonstige Fragen zu Delphi Delphi Probleme mit Sendkey nach Umstieg auf Win764Bit
Thema durchsuchen
Ansicht
Themen-Optionen

Probleme mit Sendkey nach Umstieg auf Win764Bit

Ein Thema von Bomberbb · begonnen am 3. Mär 2010 · letzter Beitrag vom 3. Mär 2010
Antwort Antwort
Seite 2 von 2     12   
Benutzerbild von himitsu
himitsu

Registriert seit: 11. Okt 2003
Ort: Elbflorenz
43.132 Beiträge
 
Delphi 12 Athens
 
#11

Re: Probleme mit Sendkey nach Umstieg auf Win764Bit

  Alt 3. Mär 2010, 15:22
Für SendMessage müßte 0 richtig sein (0 = ich habe verarbeitet).

Hmmmm, dann weiß ich auch erstmal nicht weiter.

Das richtige Fenster (HWND) wird auch verwendet?
Garbage Collector ... Delphianer erzeugen keinen Müll, also brauchen sie auch keinen Müllsucher.
my Delphi wish list : BugReports/FeatureRequests
  Mit Zitat antworten Zitat
Bomberbb

Registriert seit: 23. Sep 2003
227 Beiträge
 
#12

Re: Probleme mit Sendkey nach Umstieg auf Win764Bit

  Alt 3. Mär 2010, 15:57
Also das richtige Handle scheint es zu sein. Hab mal ein Closewindow mit dem Handle gemacht und die Liste geht zu.
Zumal kommen ja die Befehle mit Shiftstate=[] an. Nur die z.B. nicht die ssctrl haben...

Hier auch noch mal der ganze Quelltext:
Delphi-Quellcode:
Program SaveWatchList;

{$IFDEF COMPILER_8}
{$IFNDEF VER170}
{$IFNDEF VER160}
{$IFNDEF VER150}
{$IFNDEF VER140}
{$IFNDEF VER130}
{$IFNDEF VER120}
{$IFNDEF VER100}
{$IFNDEF VER90}
{$IFNDEF VER80}
{$DEFINE Delphi_2005_UP}
{$ENDIF}
{$ENDIF}
{$ENDIF}
{$ENDIF}
{$ENDIF}
{$ENDIF}
{$ENDIF}
{$ENDIF}
{$ENDIF}
{$ENDIF}

Uses
  Forms,
  Windows,
  Messages,
  Classes,
  SysUtils,
  shellapi,
  ClipBrd;

{$R-}

Type
  pHWND=^HWND;

Procedure PostKeyExHWND(hWindow:HWnd;key:Word;Const shift:TShiftState;specialkey:Boolean=false);

Type
  TBuffers=Array[0..1] Of TKeyboardState;
Var
  pKeyBuffers :^TBuffers;
  lParam :LongInt;
Begin
  (* check if the target window exists *)
  If IsWindow(hWindow) Then
  Begin
    (* set local variables to default values *)
    pKeyBuffers := Nil;
    lParam := MakeLong(0,MapVirtualKey(key,0));

    (* modify lparam if special key requested *)
    If specialkey Then
      lParam := lParam Or $1000000;

    (* allocate space for the key state buffers *)
    New(pKeyBuffers);
    Try
      (* Fill buffer 1 with current state so we can later restore it.
         Null out buffer 0 to get a "no key pressed" state. *)

      GetKeyboardState(pKeyBuffers^[1]);
      FillChar(pKeyBuffers^[0],SizeOf(TKeyboardState),0);

      (* set the requested modifier keys to "down" state in the buffer*)
      If ssShift In shift Then
        pKeyBuffers^[0][VK_SHIFT] := $80;
      If ssAlt In shift Then
      Begin
        (* Alt needs special treatment since a bit in lparam needs also be set *)
        pKeyBuffers^[0][VK_MENU] := $80;
        lParam := lParam Or $20000000;
      End;
      If ssCtrl In shift Then
        pKeyBuffers^[0][VK_CONTROL] := $80;
      If ssLeft In shift Then
        pKeyBuffers^[0][VK_LBUTTON] := $80;
      If ssRight In shift Then
        pKeyBuffers^[0][VK_RBUTTON] := $80;
      If ssMiddle In shift Then
        pKeyBuffers^[0][VK_MBUTTON] := $80;

      (* make out new key state array the active key state map *)
      SetKeyboardState(pKeyBuffers^[0]);
      (* post the key messages *)
      If ssAlt In Shift Then
      Begin
        If Not PostMessage(hWindow,WM_SYSKEYDOWN,key,lParam)
          Or Not PostMessage(hWindow,WM_SYSKEYUP,key,lParam Or $C0000000) Then
          Raise Exception.Create(SysErrorMessage(GetLastError));
      End
      Else
      Begin
        If Not PostMessage(hWindow,WM_KEYDOWN,key,lParam)
          Or Not PostMessage(hWindow,WM_KEYUP,key,lParam Or $C0000000) Then
          Raise Exception.Create(SysErrorMessage(GetLastError));
      End;

      (* restore the old key state map *)
      SetKeyboardState(pKeyBuffers^[1]);
    Finally
      (* free the memory for the key state buffers *)
      Dispose(pKeyBuffers);
    End;{ If }
  End;
End;{ PostKeyEx }

Procedure SelectAll_CopyClipboard_SaveToFile(wndParent,wndChild:HWND;Filename:String;bAppendFile:Boolean);
Var
  List :TStringlist;

Var
  hOtherWin,hFocusWin :THandle;
  OtherThreadID,ProcessID :DWORD;
  Text :String;
Begin
  List := Nil;
  hOtherWin := wndChild;
  If IsWindow(hOtherWin) Then
  Begin
    OtherThreadID := GetWindowThreadProcessID(hOtherWin,@ProcessID);
    If AttachThreadInput(GetCurrentThreadID,OtherThreadID,True) Then
    Begin
      hFocusWin := GetFocus;
      If hFocusWin<>0 Then
      Try
        Clipboard.Clear;
        List := TStringlist.Create;
        If bAppendFile And Fileexists(FileName) Then
          List.LoadFromFile(FileName);

        List.Add('**** '+DateTimeToStr(Now)+'****');

        {$IFDEF Delphi_2005_UP}
        PostKeyExHWND(wndChild,VK_HOME, []);
        {$ELSE}
        PostKeyExHWND(wndChild,VK_HOME, [ssCtrl]);
        {$ENDIF}
        Repeat
          Sleep(30);

          PostKeyExHWND(wndChild,Ord('C'), [ssCtrl]);

          Sleep(30);

          PostKeyExHWND(wndChild,VK_DOWN, []);

          Sleep(30);

          Text := Clipboard.AsText;

          List.Add(Text);
        Until Text='';
        List.SaveToFile(FileName); *)
      Finally
        AttachThreadInput(GetCurrentThreadID,OtherThreadID,False);
        list.Free;
      End;
    End;
  End;
End;

Procedure HandleParamstr(Out FileName:String;Out bAppendFile,bOpen:Boolean);

  Function IsInParam(Const s:String):Boolean;
  Var
    i :Byte;
  Begin
    Result := false;
    For i := 1 To ParamCount Do
    Begin
      If pos(s,uppercase(paramstr(i)))=1 Then
        Result := true;
    End;
  End;

Begin
  FileName := 'SaveWatchlist.txt';
  bAppendFile := true;
  If ParamCount>0 Then
  Begin
    If (UpperCase(Paramstr(1))='/HELP')Or(Paramstr(1)='/?') Then
    Begin
      MessageBox(0,'Saves the Delphi Watch List to a file specified by the filename parameter.'
        +#13#10#13#10+'Usage: SaveWatchlist [<path>] <parameter>'
        +#13#10#13#10+'Parameter:'
        +#13#10+' /append'+#9+'Appends the output to the outputfile'
        ,'Save Watch List',MB_OK);
    End
    Else
    Begin
      bAppendFile := IsInParam('/APPEND');
      bopen := IsInParam('/OPEN');
      If copy(paramstr(1),0,1)<>'/Then
        FileName := Paramstr(1);
    End;
  End;
End;

Function EnumProcTWatchWindow(wnd:HWND;pwnd:pHWND):BOOL; Stdcall;
Var
  buf :Array[0..255] Of char;
Begin
  Result := True;
  GetClassName(wnd,buf,SizeOf(buf)-1);
  If (buf='TWatchWindow') Then
  Begin
    pwnd^ := wnd;
    Result := false;
  End;
End;

Function FindWatchWindow(Out wndWatchWindow,wndChild:HWND):Boolean;
Var
  wndEditWindow :HWND;
Begin
  Result := False;
  wndWatchWindow := 0;

  //Fenster TWatchWindow suchen
  EnumWindows(@EnumProcTWatchWindow,integer(@wndWatchWindow));

  //Wenn es angedockt ist, befindet es sich in einen TEditWindow
  If wndWatchWindow=0 Then
  Begin
    wndEditWindow := FindWindow('TEditWindow',Nil);
    EnumChildWindows(wndEditWindow,@EnumProcTWatchWindow,integer(@wndWatchWindow));
  End;

  If wndWatchWindow<>0 Then
  Begin
    {$IFDEF Delphi_2005_up}
    wndChild := FindWindowEx(wndWatchWindow,0,'TVirtualStringTree',Nil);
    {$ELSE}
    wndChild := FindWindowEx(wndWatchWindow,0,'TDrawGrid',Nil);
    {$ENDIF}
    Result := wndChild<>0;
  End;
End;

Var
  wndWatchWindow,wndChild :HWND;
  OutPutFilename :String;
  bAppendFile,bOpen :Boolean;

Begin
  HandleParamstr(OutPutFilename,bAppendFile,bOpen);
  If FindWatchWindow(wndWatchWindow,wndChild) Then
  Begin
    SetForeGroundWindow(wndWatchWindow);
    SetFocus(wndWatchWindow);
    Sleep(200);
    SelectAll_CopyClipboard_SaveToFile(wndWatchWindow,wndChild,OutPutFilename,bAppendFile);
    If bopen Then
      ShellExecute(0,'open',pchar(OutPutFilename),Pchar(''),Nil,SW_SHOWDEFAULT)
  End
  Else
    MessageBox(0,'The Watch Window could not be found.','Information',MB_OK);
End.
  Mit Zitat antworten Zitat
Antwort Antwort
Seite 2 von 2     12   


Forumregeln

Es ist dir nicht erlaubt, neue Themen zu verfassen.
Es ist dir nicht erlaubt, auf Beiträge zu antworten.
Es ist dir nicht erlaubt, Anhänge hochzuladen.
Es ist dir nicht erlaubt, deine Beiträge zu bearbeiten.

BB-Code ist an.
Smileys sind an.
[IMG] Code ist an.
HTML-Code ist aus.
Trackbacks are an
Pingbacks are an
Refbacks are aus

Gehe zu:

Impressum · AGB · Datenschutz · Nach oben
Alle Zeitangaben in WEZ +1. Es ist jetzt 09:58 Uhr.
Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO © 2011, Crawlability, Inc.
Delphi-PRAXiS (c) 2002 - 2023 by Daniel R. Wolf, 2024 by Thomas Breitkreuz