📄 displayremotescreenunit.pas
字号:
ShowImageStyle := msg.IDItem;
CheckMenuItem(hMenu, ShowImageStyle, MF_CHECKED);
InvalidateRect(Self.Handle, nil, True);
end;
IDM_ShowCousor:
begin
Bool_ShowCousor := not Bool_ShowCousor;
CheckMenuItem(hMenu, msg.IDItem, byte(Bool_ShowCousor) * 8);
end;
IDM_AllowRemoteCtronl:
begin
Bool_AllowRemoteCtronl := not Bool_AllowRemoteCtronl;
CheckMenuItem(hMenu, msg.IDItem, byte(Bool_AllowRemoteCtronl) * 8);
end;
IDM_SaveSiglePic:
begin
if ImageBitsData <> nil then
begin
SinglePic := TBitmap.Create;
case ImageInforHeaderData^.bmiHeader.biBitCount of
1:
SinglePic.PixelFormat := pf1bit;
4:
SinglePic.PixelFormat := pf4bit;
8:
SinglePic.PixelFormat := pf8bit;
16:
SinglePic.PixelFormat := pf16bit;
24:
SinglePic.PixelFormat := pf24bit;
end;
SinglePic.Width := RemoteScreenWidth;
SinglePic.Height := RemoteScreenHeight;
DrawClientDC(SinglePic.Canvas.Handle, 0, 0);
FileName := InPutBox('文件名输入', '请输入文件名', '小牛牛');
SinglePic.SaveToFile(ExtractFilePath(ParamStr(0)) + '\' + FileName + '.bmp');
SinglePic.Free;
end;
end;
else
inherited;
end;
end;
//响应PaintMessage消息
function TDisplayRemoteScreen.WndProcScrollPaintMessage(hWnd: HWND; Msg: UINT;
wParam: WPARAM; lParam: LPARAM): LRESULT; stdcall;
var
hdcWnd : hDC;
ps: TPaintStruct;
SI: TScrollInfo;
iVertPos, iHorzPos : Integer;
begin
Result := 0;
case Msg of
WM_SIZE:
begin
ClientWidth := LOWORD(lParam);
ClientHeight := HIWORD(lParam);
end;
WM_VSCROLL:
begin
if ShowImageStyle = IDM_Orignal then
begin
//get the vertical scroll bar information
SI.cbSize := SizeOf(SI);
SI.fMask := SIF_ALL;
GetScrollInfo(hWnd, SB_VERT, SI);
//store the postion
iVertPos := SI.nPos;
//case the different information
case LOWORD(wParam) of
SB_TOP : SI.nPos := SI.nMin;
SB_BOTTOM : SI.nPos := SI.nMax;
SB_LINEUP : SI.nPos := SI.nPos - 6;
SB_LINEDOWN : SI.nPos := SI.nPos + 6;
SB_PAGEUP : SI.nPos := SI.nPos - integer(SI.nPage);
SB_PAGEDOWN : SI.nPos := SI.nPos + integer(SI.nPage);
SB_THUMBTRACK: SI.nPos := SI.nTrackPos;
end;
SI.fMask := SIF_POS;
SetScrollInfo(hWnd, SB_VERT, SI, TRUE);
GetScrollInfo(hWnd, SB_VERT, SI);
//generation the invidate rect
if (SI.nPos <> iVertPos) then
begin
ScrollWindow(hWnd, 0, (iVertPos - SI.nPos), nil, nil);
UpdateWindow(hWnd);
end;
end;
end;
WM_HSCROLL:
begin
if ShowImageStyle = IDM_Orignal then
begin
SI.cbSize := SizeOf(SI);
SI.fMask := SIF_ALL;
GetScrollInfo(hWnd, SB_HORZ, SI);
iHorzPos := SI.nPos;
case LOWORD(wParam) of
SB_LINELEFT : SI.nPos := SI.nPos - 3;
SB_LINERIGHT : SI.nPos := SI.nPos + 3;
SB_PAGELEFT : SI.nPos := SI.nPos - integer(SI.nPage);
SB_PAGERIGHT : SI.nPos := SI.nPos + integer(SI.nPage);
SB_THUMBPOSITION: SI.nPos := SI.nTrackPos;
end;
SI.fMask := SIF_POS;
SetScrollInfo(hWnd, SB_HORZ, SI, TRUE);
GetScrollInfo(hWnd, SB_HORZ, SI);
if (SI.nPos <> iHorzPos) then
begin
ScrollWindow(hWnd, (iHorzPos - SI.nPos), 0, nil, nil);
UpdateWindow(hWnd);
end;
end;
end;
WM_KEYDOWN:
begin //dispatch the scroll messages
case wParam of
VK_HOME : SendMessage(hWnd, WM_VSCROLL, SB_TOP, 0);
VK_END : SendMessage(hWnd, WM_VSCROLL, SB_BOTTOM, 0);
VK_PRIOR : SendMessage(hWnd, WM_VSCROLL, SB_PAGEUP, 0);
VK_NEXT : SendMessage(hWnd, WM_VSCROLL, SB_PAGEDOWN, 0);
VK_UP : SendMessage(hWnd, WM_VSCROLL, SB_LINEUP, 0);
VK_DOWN : SendMessage(hWnd, WM_VSCROLL, SB_LINEDOWN, 0);
VK_LEFT : SendMessage(hWnd, WM_HSCROLL, SB_PAGEUP, 0);
VK_RIGHT : SendMessage(hWnd, WM_HSCROLL, SB_PAGEDOWN, 0);
end;
end;
WM_MOUSEWHEEL:
begin
case wParam of
-7864320: //向下滚
SendMessage(hWnd, WM_VSCROLL, SB_PAGEDOWN, 0);
7864320: //向上滚
SendMessage(hWnd, WM_VSCROLL, SB_PAGEUP, 0);
end;
end;
WM_PAINT:
begin
if ShowImageStyle <> IDM_Orignal then
begin
// set vertical scroll information
SI.cbSize := SizeOf(SI);
SI.fMask := SIF_RANGE or SIF_PAGE;
SI.nMin := 0;
SI.nMax := 0;
SI.nPage := 0;
SetScrollInfo(hWnd, SB_VERT, SI, TRUE);
// set horizontal scroll information
SI.cbSize := SizeOf(SI);
SI.fMask := SIF_RANGE or SIF_PAGE;
SI.nMin := 0;
SI.nMax := 0;
SI.nPage := 0;
SetScrollInfo(hWnd, SB_HORZ, SI, TRUE);
end
else
begin
// set vertical scroll information
SI.cbSize := SizeOf(SI);
SI.fMask := SIF_RANGE or SIF_PAGE;
SI.nMin := 0;
SI.nMax := RemoteScreenHeight - 1;
SI.nPage := ClientHeight;
SetScrollInfo(hWnd, SB_VERT, SI, TRUE);
// set horizontal scroll information
SI.cbSize := SizeOf(SI);
SI.fMask := SIF_RANGE or SIF_PAGE;
SI.nMin := 0;
SI.nMax := RemoteScreenWidth - 1;
SI.nPage := ClientWidth;
SetScrollInfo(hWnd, SB_HORZ, SI, TRUE);
end;
SI.cbSize := SizeOf(SI) ;
SI.fMask := SIF_POS;
//get the vertical postion
GetScrollInfo(hWnd, SB_VERT, SI);
iVertPos := SI.nPos ;
//get horz positon
GetScrollInfo(hWnd, SB_HORZ, SI);
iHorzPos := SI.nPos;
//caculate the drawing position
xPaintBeg := 0 - iHorzPos;
yPaintBeg := 0 - iVertPos;
hdcWnd := BeginPaint(hWnd, ps);
if (ImageBitsData <> nil) then
begin
DrawClientDC(hdcWnd, xPaintBeg, yPaintBeg);
end;
EndPaint(hWnd, ps);
end;
end;
end;
//
function TDisplayRemoteScreen.DealWndProc(hWnd: HWND; Msg: UINT;
wParam: WPARAM; lParam: LPARAM): LRESULT;
begin
Result := 0;
case Msg of
WM_SIZE,
WM_VSCROLL,
WM_HSCROLL,
WM_MOUSEWHEEL,
WM_PAINT:
begin
WndProcScrollPaintMessage(hWnd, Msg, wParam, lParam);
end;
//远程图像帧接受完毕
WM_DealDataMsg:
begin
Self.Caption := Self.CaptionStr + ',100%';
ReceivedData := RemoteUnCmpedFrameData;
DrawMemDC;
//通知接收线程可以继续了
SetEvent(MsgDealDataOkNotifyEvent);
end;
WM_KEYDOWN:
begin
if (Bool_AllowRemoteCtronl) then
begin
myTKeyAndCursorData.MouseX := integer(wParam);
myTKeyAndCursorData.MouseY := 0;
myTKeyAndCursorData.WMtpye := Msg;
SetCtrlStructure(ClientSocket, myTKeyAndCursorData, CtrlPerHandleData);
end;
end;
WM_LBUTTONDOWN,
WM_LBUTTONUP,
WM_LBUTTONDBLCLK,
WM_RBUTTONDOWN,
WM_RBUTTONUP,
WM_RBUTTONDBLCLK,
WM_MOUSEMOVE:
begin
//发送鼠标和键盘的控制消息
if (Bool_AllowRemoteCtronl) and (ClientSocket <> 0) then
begin
myTKeyAndCursorData.WMtpye := Msg;
case ShowImageStyle of
IDM_Orignal:
begin
//根据滚动条的位置调整
myTKeyAndCursorData.MouseX := (LOWORD(lParam) - xPaintBeg);
myTKeyAndCursorData.MouseY := (HIWORD(lParam) - yPaintBeg);
SetCtrlStructure(ClientSocket, myTKeyAndCursorData, CtrlPerHandleData);
end;
IDM_Stretch:
begin
//全client都有strecth
myTKeyAndCursorData.MouseX := RemoteScreenWidth * LOWORD(lParam) div ClientWidth;
myTKeyAndCursorData.MouseY := RemoteScreenHeight * HIWORD(lParam) div ClientHeight;
SetCtrlStructure(ClientSocket, myTKeyAndCursorData, CtrlPerHandleData);
end;
end;
end;
end;
else
Result := CallWindowProc(Pointer(prevWndProc), hWnd, Msg, wParam, lParam);
end;
end;
(*----------------------------以下是图像的绘制部分-------------------------*)
//capture mouse
procedure TDisplayRemoteScreen.DrawCursor(hMemDC : HDC;
const MouseX, MouseY : Word; const CousorType : Byte);
var
tmpHCURSOR : HCURSOR;
Icon : hIcon;
begin
case CousorType of
0:
tmpHCURSOR := LoadCursor(0, IDC_APPSTARTING);
1:
tmpHCURSOR := LoadCursor(0, IDC_ARROW);
2:
tmpHCURSOR := LoadCursor(0, IDC_CROSS);
3:
tmpHCURSOR := LoadCursor(0, IDC_HAND);
4:
tmpHCURSOR := LoadCursor(0, IDC_HELP);
5:
tmpHCURSOR := LoadCursor(0, IDC_IBEAM);
6:
tmpHCURSOR := LoadCursor(0, IDC_ICON);
7:
tmpHCURSOR := LoadCursor(0, IDC_NO);
8:
tmpHCURSOR := LoadCursor(0, IDC_SIZE);
9:
tmpHCURSOR := LoadCursor(0, IDC_SIZEALL);
10:
tmpHCURSOR := LoadCursor(0, IDC_SIZENESW);
11:
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -