Leaked source code of windows server 2003
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

124 lines
2.4 KiB

  1. /* File: D:\WACKER\tdll\clipbrd.c (Created: 24-Jan-1994)
  2. *
  3. * Copyright 1994 by Hilgraeve Inc. -- Monroe, MI
  4. * All rights reserved
  5. *
  6. * $Revision: 2 $
  7. * $Date: 5/09/01 4:42p $
  8. */
  9. #include <windows.h>
  10. #pragma hdrstop
  11. #include "stdtyp.h"
  12. #include "assert.h"
  13. #include "session.h"
  14. #include "tdll.h"
  15. #include "cloop.h"
  16. #include "htchar.h"
  17. #include "mc.h"
  18. /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
  19. * FUNCTION:
  20. * CopyBufferToClipBoard
  21. *
  22. * DESCRIPTION:
  23. * Function to copy text to clipboard
  24. *
  25. * ARGUMENTS:
  26. * HWND hwnd - window that will own clipboard.
  27. * DWORD dwCnt - size of buffer
  28. * void *pvBuf - pointer to buffer
  29. *
  30. * RETURNS:
  31. * BOOL
  32. *
  33. */
  34. BOOL CopyBufferToClipBoard(const HWND hwnd, const DWORD dwCnt, const void *pvBuf)
  35. {
  36. HGLOBAL hMem;
  37. void *pvMem;
  38. TCHAR *pszTemp;
  39. if (pvBuf == 0 || dwCnt == 0)
  40. {
  41. assert(FALSE);
  42. return FALSE;
  43. }
  44. if (!OpenClipboard(hwnd))
  45. return FALSE;
  46. hMem = GlobalAlloc(GMEM_DDESHARE | GMEM_MOVEABLE, dwCnt + 1);
  47. if (hMem == 0)
  48. {
  49. assert(FALSE);
  50. return FALSE;
  51. }
  52. pvMem = GlobalLock(hMem);
  53. if (dwCnt)
  54. MemCopy(pvMem, pvBuf, dwCnt);
  55. pszTemp = pvMem;
  56. *(pszTemp + dwCnt) = 0;
  57. GlobalUnlock(hMem);
  58. EmptyClipboard();
  59. SetClipboardData(CF_TEXT, hMem);
  60. CloseClipboard();
  61. return TRUE;
  62. }
  63. /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
  64. * FUNCTION:
  65. * PasteFromClipboardToHost
  66. *
  67. * DESCRIPTION:
  68. * This function copies text from the clipboard to host.
  69. *
  70. * ARGUMENTS:
  71. * HWND hwnd - window handle
  72. * HSESSION hSession - the session handle
  73. *
  74. * RETURNS:
  75. * BOOL
  76. *
  77. */
  78. BOOL PasteFromClipboardToHost(const HWND hwnd, const HSESSION hSession)
  79. {
  80. HANDLE hMem;
  81. LPTSTR lptStr;
  82. // Clipboard had to have been opened first...
  83. //
  84. if (!OpenClipboard(hwnd))
  85. return FALSE;
  86. // Check to see if the clipboard format is available.
  87. //
  88. if (IsClipboardFormatAvailable(CF_TEXT) == FALSE)
  89. return FALSE;
  90. // Do we need to enumerate clipboard formats?
  91. if ((hMem = GetClipboardData(CF_TEXT)))
  92. {
  93. // hMem is owned by the clipboard, so we must not free it
  94. // or leave it locked!
  95. //
  96. if ((lptStr = GlobalLock(hMem)))
  97. {
  98. CLoopSend(sessQueryCLoopHdl(hSession),
  99. lptStr,
  100. (size_t)(StrCharGetByteCount(lptStr)),
  101. 0);
  102. GlobalUnlock(hMem);
  103. }
  104. }
  105. CloseClipboard();
  106. return TRUE;
  107. }