我是这样实现的:
  在按钮的单击事件里面这样写的:
  SendMessage(Handle,WM_KEYUP,VK_SNAPSHOT,0);
但是没有效果,请问应该怎样写呢?

解决方案 »

  1.   

    仅仅keyup还不行吧,在前面加上keydown试试,有两个消息模拟按键
      

  2.   

    class procedure CWindowOperator.SendKey(myHwnd: integer;VKey: Word);
    begin
       SendMessage(myHwnd,WM_KEYDOWN, VKey  , 0);
       SendMessage(myHwnd,WM_CHAR   , VKey  , 1);
       SendMessage(myHwnd,WM_KEYUP  , VKey  , 0);
    end;
      

  3.   

    {
    同理,  傳送 'A' 時, 應先送
    KEYDOWN,'a'
    WM_CHAR,'A'
    KEYUP,'a'才能正常運作, 省略掉後面的 message, 會有意外發生.
    }
      

  4.   

    不用消息var
      bmp : TBitmap;
      ScreenCanvas : TCanvas;  Format : Word;
      Data : THandle;
      Palette : HPALETTE;
      Desktop : THandle;
    begin
      ScreenCanvas := TCanvas.Create;
      Desktop := GetDesktopWindow;
      ScreenCanvas.Handle := GetDC(Desktop);  bmp := TBitMap.Create;  bmp.PixelFormat := pf24Bit;
      bmp.Width := Screen.Width;
      bmp.Height := Screen.Height;
      bmp.Canvas.CopyRect(Rect(0,0,bmp.Width,bmp.Height),ScreenCanvas,
        Rect(0,0,Screen.Width,Screen.Height));  bmp.SaveToClipBoardFormat(Format,Data,Palette);
      ClipBoard.SetAsHandle(Format,Data);  bmp.Free;
      ReleaseDC(Desktop,ScreenCanvas.Handle);
      ScreenCanvas.Free;
    end;