ReactOS  0.4.14-dev-52-g6116262
clipbrd.c File Reference
#include "precomp.h"
Include dependency graph for clipbrd.c:

Go to the source code of this file.

Functions

static void SaveClipboardToFile (void)
 
static void LoadClipboardDataFromFile (LPWSTR lpszFileName)
 
static void LoadClipboardFromFile (void)
 
static void LoadClipboardFromDrop (HDROP hDrop)
 
static void SetDisplayFormat (UINT uFormat)
 
static void InitMenuPopup (HMENU hMenu, LPARAM index)
 
static void UpdateDisplayMenu (void)
 
static int OnCommand (HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
 
static void OnPaint (HWND hWnd, WPARAM wParam, LPARAM lParam)
 
static LRESULT WINAPI MainWndProc (HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
 
int WINAPI wWinMain (HINSTANCE hInstance, HINSTANCE hPrevInstance, LPWSTR lpCmdLine, int nCmdShow)
 

Variables

static const WCHAR szClassName [] = L"ClipBookWClass"
 
CLIPBOARD_GLOBALS Globals
 
SCROLLSTATE Scrollstate
 

Function Documentation

◆ InitMenuPopup()

static void InitMenuPopup ( HMENU  hMenu,
LPARAM  index 
)
static

Definition at line 135 of file clipbrd.c.

136 {
137  if ((GetMenuItemID(hMenu, 0) == CMD_DELETE) || (GetMenuItemID(hMenu, 1) == CMD_SAVE_AS))
138  {
139  if (CountClipboardFormats() == 0)
140  {
143  }
144  else
145  {
148  }
149  }
150 
152 }
BOOL WINAPI DrawMenuBar(_In_ HWND)
#define CMD_DELETE
Definition: resources.h:18
#define CMD_SAVE_AS
Definition: resources.h:16
CLIPBOARD_GLOBALS Globals
Definition: clipbrd.c:13
BOOL WINAPI EnableMenuItem(_In_ HMENU, _In_ UINT, _In_ UINT)
#define MF_ENABLED
Definition: winuser.h:128
UINT WINAPI GetMenuItemID(_In_ HMENU, _In_ int)
#define MF_GRAYED
Definition: winuser.h:129
int WINAPI CountClipboardFormats(void)
Definition: ntwrapper.h:184

Referenced by MainWndProc().

◆ LoadClipboardDataFromFile()

static void LoadClipboardDataFromFile ( LPWSTR  lpszFileName)
static

Definition at line 52 of file clipbrd.c.

53 {
57  {
58  return;
59  }
60 
62  {
64  return;
65  }
66 
68  ReadClipboardFile(lpszFileName);
69 
71 }
#define IDYES
Definition: winuser.h:829
#define MB_ICONWARNING
Definition: winuser.h:780
void ShowLastWin32Error(HWND hwndParent)
Definition: winutils.c:11
CLIPBOARD_GLOBALS Globals
Definition: clipbrd.c:13
#define MB_YESNO
Definition: winuser.h:811
#define STRING_DELETE_TITLE
Definition: resources.h:27
int MessageBoxRes(HWND hWnd, HINSTANCE hInstance, UINT uText, UINT uCaption, UINT uType)
Definition: winutils.c:49
BOOL WINAPI EmptyClipboard(void)
Definition: ntwrapper.h:190
BOOL WINAPI CloseClipboard(void)
Definition: ntwrapper.h:178
#define STRING_DELETE_MSG
Definition: resources.h:26
BOOL WINAPI OpenClipboard(_In_opt_ HWND)
void ReadClipboardFile(LPCWSTR lpFileName)
Definition: fileutils.c:275
HINSTANCE hInstance
Definition: precomp.h:43

Referenced by LoadClipboardFromDrop(), LoadClipboardFromFile(), and wWinMain().

◆ LoadClipboardFromDrop()

static void LoadClipboardFromDrop ( HDROP  hDrop)
static

Definition at line 100 of file clipbrd.c.

101 {
102  WCHAR szFileName[MAX_PATH];
103 
104  DragQueryFileW(hDrop, 0, szFileName, ARRAYSIZE(szFileName));
105  DragFinish(hDrop);
106 
107  LoadClipboardDataFromFile(szFileName);
108 }
static void LoadClipboardDataFromFile(LPWSTR lpszFileName)
Definition: clipbrd.c:52
#define ARRAYSIZE(array)
Definition: filtermapper.c:47
__wchar_t WCHAR
Definition: xmlstorage.h:180
#define MAX_PATH
Definition: compat.h:26
void WINAPI DragFinish(HDROP h)
Definition: shellole.c:543
UINT WINAPI DragQueryFileW(HDROP hDrop, UINT lFile, LPWSTR lpszwFile, UINT lLength)
Definition: shellole.c:627

Referenced by MainWndProc().

◆ LoadClipboardFromFile()

static void LoadClipboardFromFile ( void  )
static

Definition at line 73 of file clipbrd.c.

74 {
76  LPWSTR c;
77  WCHAR szFileName[MAX_PATH];
78  WCHAR szFilterMask[MAX_STRING_LEN + 10];
79 
80  ZeroMemory(&szFilterMask, sizeof(szFilterMask));
81  c = szFilterMask + LoadStringW(Globals.hInstance, STRING_FORMAT_GEN, szFilterMask, MAX_STRING_LEN) + 1;
82  wcscpy(c, L"*.clp");
83 
84  ZeroMemory(&szFileName, sizeof(szFileName));
85  ZeroMemory(&ofn, sizeof(ofn));
86  ofn.lStructSize = sizeof(ofn);
89  ofn.lpstrFilter = szFilterMask;
90  ofn.lpstrFile = szFileName;
91  ofn.nMaxFile = ARRAYSIZE(szFileName);
93 
94  if (!GetOpenFileNameW(&ofn))
95  return;
96 
97  LoadClipboardDataFromFile(szFileName);
98 }
#define OFN_FILEMUSTEXIST
Definition: commdlg.h:106
HWND hwndOwner
Definition: commdlg.h:330
static void LoadClipboardDataFromFile(LPWSTR lpszFileName)
Definition: clipbrd.c:52
OPENFILENAME ofn
Definition: main.cpp:37
#define ARRAYSIZE(array)
Definition: filtermapper.c:47
#define ZeroMemory
Definition: winbase.h:1635
#define MAX_STRING_LEN
Definition: precomp.h:36
int WINAPI LoadStringW(_In_opt_ HINSTANCE hInstance, _In_ UINT uID, _Out_writes_to_(cchBufferMax, return+1) LPWSTR lpBuffer, _In_ int cchBufferMax)
DWORD nMaxFile
Definition: commdlg.h:337
CLIPBOARD_GLOBALS Globals
Definition: clipbrd.c:13
BOOL WINAPI GetOpenFileNameW(OPENFILENAMEW *ofn)
Definition: filedlg.c:4564
HINSTANCE hInstance
Definition: commdlg.h:331
#define OFN_PATHMUSTEXIST
Definition: commdlg.h:117
__wchar_t WCHAR
Definition: xmlstorage.h:180
#define MAX_PATH
Definition: compat.h:26
DWORD lStructSize
Definition: commdlg.h:329
const GLubyte * c
Definition: glext.h:8905
_CRTIMP wchar_t *__cdecl wcscpy(_Out_writes_z_(_String_length_(_Source)+1) wchar_t *_Dest, _In_z_ const wchar_t *_Source)
static const WCHAR L[]
Definition: oid.c:1250
#define OFN_HIDEREADONLY
Definition: commdlg.h:107
LPSTR lpstrFile
Definition: commdlg.h:336
LPCSTR lpstrFilter
Definition: commdlg.h:332
#define c
Definition: ke_i.h:80
WCHAR * LPWSTR
Definition: xmlstorage.h:184
HINSTANCE hInstance
Definition: precomp.h:43
#define STRING_FORMAT_GEN
Definition: resources.h:29
DWORD Flags
Definition: commdlg.h:342

Referenced by OnCommand().

◆ MainWndProc()

static LRESULT WINAPI MainWndProc ( HWND  hWnd,
UINT  uMsg,
WPARAM  wParam,
LPARAM  lParam 
)
static

Definition at line 381 of file clipbrd.c.

382 {
383  switch(uMsg)
384  {
385  case WM_CREATE:
386  {
387  TEXTMETRICW tm;
388  HDC hDC = GetDC(hWnd);
389 
390  /*
391  * Note that the method with GetObjectW just returns
392  * the original parameters with which the font was created.
393  */
394  if (GetTextMetricsW(hDC, &tm))
395  {
396  Globals.CharWidth = tm.tmMaxCharWidth; // tm.tmAveCharWidth;
397  Globals.CharHeight = tm.tmHeight + tm.tmExternalLeading;
398  }
399  ReleaseDC(hWnd, hDC);
400 
401 
404 
405  // For now, the Help dialog item is disabled because of lacking of HTML support
407 
409 
411  SetDisplayFormat(0);
412 
414  break;
415  }
416 
417  case WM_CLOSE:
418  {
420  break;
421  }
422 
423  case WM_DESTROY:
424  {
426 
428  {
429  HGLOBAL hglb;
430  PRECT prc;
431 
432  hglb = GlobalAlloc(GMEM_MOVEABLE, sizeof(*prc));
433  if (hglb)
434  {
435  prc = GlobalLock(hglb);
436  SetRectEmpty(prc);
437  GlobalUnlock(hglb);
438 
440  (WPARAM)hWnd, (LPARAM)hglb);
441 
442  GlobalFree(hglb);
443  }
444  }
445 
446  PostQuitMessage(0);
447  break;
448  }
449 
450  case WM_PAINT:
451  {
453  break;
454  }
455 
456  case WM_KEYDOWN:
457  {
459  break;
460  }
461 
462  case WM_MOUSEWHEEL:
463  case WM_MOUSEHWHEEL:
464  {
466  break;
467  }
468 
469  case WM_HSCROLL:
470  {
471  // NOTE: Windows uses an offset of 16 pixels
473  break;
474  }
475 
476  case WM_VSCROLL:
477  {
478  // NOTE: Windows uses an offset of 16 pixels
480  break;
481  }
482 
483  case WM_SIZE:
484  {
485  RECT rc;
486 
488  {
489  HGLOBAL hglb;
490  PRECT prc;
491 
492  hglb = GlobalAlloc(GMEM_MOVEABLE, sizeof(*prc));
493  if (hglb)
494  {
495  prc = GlobalLock(hglb);
496  if (wParam == SIZE_MINIMIZED)
497  SetRectEmpty(prc);
498  else
500  GlobalUnlock(hglb);
501 
503  (WPARAM)hWnd, (LPARAM)hglb);
504 
505  GlobalFree(hglb);
506  }
507  break;
508  }
509 
512 
513  // NOTE: There still are little problems drawing
514  // the background when displaying clipboard text.
520  {
522  }
523  else
524  {
526  }
527 
528  break;
529  }
530 
531  case WM_CHANGECBCHAIN:
532  {
533  /* Transmit through the clipboard viewer chain */
534  if ((HWND)wParam == Globals.hWndNext)
535  {
537  }
538  else if (Globals.hWndNext != NULL)
539  {
541  }
542 
543  break;
544  }
545 
546  case WM_DESTROYCLIPBOARD:
547  break;
548 
549  case WM_RENDERALLFORMATS:
550  {
551  /*
552  * When the user has cleared the clipboard via the DELETE command,
553  * we (clipboard viewer) become the clipboard owner. When we are
554  * subsequently closed, this message is then sent to us so that
555  * we get a chance to render everything we can. Since we don't have
556  * anything to render, just empty the clipboard.
557  */
559  break;
560  }
561 
562  case WM_RENDERFORMAT:
563  // TODO!
564  break;
565 
566  case WM_DRAWCLIPBOARD:
567  {
569  SetDisplayFormat(0);
570 
571  /* Pass the message to the next window in clipboard viewer chain */
573  break;
574  }
575 
576  case WM_COMMAND:
577  {
578  if ((LOWORD(wParam) > CMD_AUTOMATIC))
579  {
581  }
582  else
583  {
584  OnCommand(hWnd, uMsg, wParam, lParam);
585  }
586  break;
587  }
588 
589  case WM_INITMENUPOPUP:
590  {
592  break;
593  }
594 
595  case WM_DROPFILES:
596  {
598  break;
599  }
600 
601  case WM_PALETTECHANGED:
602  {
603  /* Ignore if this comes from ourselves */
604  if ((HWND)wParam == hWnd)
605  break;
606 
607  /* Fall back to WM_QUERYNEWPALETTE */
608  }
609 
610  case WM_QUERYNEWPALETTE:
611  {
612  BOOL Success;
613  HDC hDC;
614 
616  return FALSE;
617 
618  hDC = GetDC(hWnd);
619  if (!hDC)
620  {
621  CloseClipboard();
622  return FALSE;
623  }
624 
626 
627  ReleaseDC(hWnd, hDC);
628  CloseClipboard();
629 
630  if (Success)
631  {
634  return TRUE;
635  }
636  return FALSE;
637  }
638 
639  case WM_SYSCOLORCHANGE:
640  {
642  break;
643  }
644 
645  case WM_SETTINGCHANGE:
646  {
648  {
650  }
651  break;
652  }
653 
654  default:
655  {
656  return DefWindowProc(hWnd, uMsg, wParam, lParam);
657  }
658  }
659 
660  return 0;
661 }
#define WM_CHANGECBCHAIN
Definition: winuser.h:1856
#define WM_SYSCOLORCHANGE
Definition: winuser.h:1608
SCROLLSTATE Scrollstate
Definition: clipbrd.c:14
#define TRUE
Definition: types.h:120
HGLOBAL NTAPI GlobalAlloc(UINT uFlags, SIZE_T dwBytes)
Definition: heapmem.c:368
HWND WINAPI SetClipboardViewer(_In_ HWND)
#define WM_RENDERFORMAT
Definition: winuser.h:1848
BOOL WINAPI GetTextMetricsW(_In_ HDC, _Out_ LPTEXTMETRICW)
Definition: text.c:221
#define MF_BYCOMMAND
Definition: winuser.h:202
#define WM_SIZECLIPBOARD
Definition: winuser.h:1854
HDC WINAPI GetDC(_In_opt_ HWND)
#define SB_VERT
Definition: winuser.h:553
#define WM_RENDERALLFORMATS
Definition: winuser.h:1849
#define CMD_AUTOMATIC
Definition: resources.h:22
#define WM_INITMENUPOPUP
Definition: winuser.h:1728
#define WM_MOUSEWHEEL
Definition: treelist.c:96
#define SB_HORZ
Definition: winuser.h:552
#define SPI_SETWHEELSCROLLLINES
Definition: zmouse.h:30
BOOL GetClipboardDataDimensions(UINT uFormat, PRECT pRc)
Definition: cliputils.c:248
static HDC
Definition: imagelist.c:92
BOOL WINAPI UpdateWindow(_In_ HWND)
HWND hWnd
Definition: settings.c:17
void WINAPI DragAcceptFiles(HWND hWnd, BOOL b)
Definition: shellole.c:527
HANDLE HWND
Definition: compat.h:13
static int OnCommand(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
Definition: clipbrd.c:202
BOOL WINAPI ChangeClipboardChain(_In_ HWND, _In_ HWND)
UINT_PTR WPARAM
Definition: windef.h:207
LONG right
Definition: windef.h:293
BOOL WINAPI DestroyWindow(_In_ HWND)
WPARAM wParam
Definition: combotst.c:138
#define WM_SETTINGCHANGE
Definition: winuser.h:1611
CLIPBOARD_GLOBALS Globals
Definition: clipbrd.c:13
BOOL WINAPI EnableMenuItem(_In_ HMENU, _In_ UINT, _In_ UINT)
BOOL RealizeClipboardPalette(HDC hdc)
Definition: winutils.c:334
unsigned int BOOL
Definition: ntddk_ex.h:94
#define CF_OWNERDISPLAY
Definition: constants.h:413
int WINAPI ReleaseDC(_In_opt_ HWND, _In_ HDC)
#define WM_DROPFILES
Definition: winuser.h:1807
void DeleteClipboardContent(void)
Definition: cliputils.c:134
#define CF_UNICODETEXT
Definition: constants.h:408
smooth NULL
Definition: ftsmooth.c:416
void OnScroll(HWND hWnd, INT nBar, WPARAM wParam, INT iDelta, LPSCROLLSTATE state)
Definition: scrollutils.c:124
static void LoadClipboardFromDrop(HDROP hDrop)
Definition: clipbrd.c:100
#define WM_KEYDOWN
Definition: winuser.h:1697
LONG_PTR LPARAM
Definition: windef.h:208
static void InitMenuPopup(HMENU hMenu, LPARAM index)
Definition: clipbrd.c:135
#define DefWindowProc
Definition: ros2win.h:31
#define CF_TEXT
Definition: constants.h:396
#define WM_DESTROY
Definition: winuser.h:1591
#define WM_QUERYNEWPALETTE
Definition: winuser.h:1860
BOOL IsClipboardFormatSupported(UINT uFormat)
Definition: cliputils.c:173
#define WM_SIZE
Definition: winuser.h:1593
#define WM_CLOSE
Definition: winuser.h:1603
#define WM_PALETTECHANGED
Definition: winuser.h:1859
BOOL WINAPI InvalidateRect(_In_opt_ HWND, _In_opt_ LPCRECT, _In_ BOOL)
HGLOBAL NTAPI GlobalFree(HGLOBAL hMem)
Definition: heapmem.c:611
#define SIZE_MINIMIZED
Definition: winuser.h:2481
LRESULT SendClipboardOwnerMessage(IN BOOL bUnicode, IN UINT uMsg, IN WPARAM wParam, IN LPARAM lParam)
Definition: cliputils.c:12
BOOL WINAPI CloseClipboard(void)
Definition: ntwrapper.h:178
#define WM_PAINT
Definition: winuser.h:1602
LPVOID NTAPI GlobalLock(HGLOBAL hMem)
Definition: heapmem.c:755
void UpdateLinesToScroll(LPSCROLLSTATE state)
Definition: scrollutils.c:241
#define WM_DRAWCLIPBOARD
Definition: winuser.h:1851
BOOL WINAPI SetRectEmpty(_Out_ LPRECT)
Definition: time.h:76
#define WM_COMMAND
Definition: winuser.h:1722
void OnMouseScroll(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam, LPSCROLLSTATE state)
Definition: scrollutils.c:61
static HDC hDC
Definition: 3dtext.c:33
BOOL WINAPI GetClientRect(_In_ HWND, _Out_ LPRECT)
#define CF_OEMTEXT
Definition: constants.h:402
#define CMD_HELP
Definition: resources.h:19
LRESULT WINAPI SendMessageW(_In_ HWND, _In_ UINT, _In_ WPARAM, _In_ LPARAM)
static void UpdateDisplayMenu(void)
Definition: clipbrd.c:154
#define WM_HSCROLL
Definition: winuser.h:1725
BOOL NTAPI GlobalUnlock(HGLOBAL hMem)
Definition: heapmem.c:1190
void UpdateWindowScrollState(HWND hWnd, INT nMaxWidth, INT nMaxHeight, LPSCROLLSTATE lpState)
Definition: scrollutils.c:256
#define WM_DESTROYCLIPBOARD
Definition: winuser.h:1850
#define WM_CREATE
Definition: winuser.h:1590
LONG bottom
Definition: windef.h:294
void OnKeyScroll(HWND hWnd, WPARAM wParam, LPARAM lParam, LPSCROLLSTATE state)
Definition: scrollutils.c:11
#define CF_DSPTEXT
Definition: constants.h:414
BOOL WINAPI OpenClipboard(_In_opt_ HWND)
#define MF_GRAYED
Definition: winuser.h:129
static void SetDisplayFormat(UINT uFormat)
Definition: clipbrd.c:110
_Out_ LPRECT prc
Definition: ntgdi.h:1658
HMENU WINAPI GetMenu(_In_ HWND)
static void OnPaint(HWND hWnd, WPARAM wParam, LPARAM lParam)
Definition: clipbrd.c:269
static const CLSID *static CLSID *static const GUID VARIANT VARIANT *static IServiceProvider DWORD *static HMENU
Definition: ordinal.c:60
LPARAM lParam
Definition: combotst.c:139
#define LOWORD(l)
Definition: pedump.c:82
__analysis_noreturn void WINAPI PostQuitMessage(_In_ int)
#define GMEM_MOVEABLE
Definition: winbase.h:291
#define WM_VSCROLL
Definition: winuser.h:1726
UINT uDisplayFormat
Definition: precomp.h:47

Referenced by wWinMain().

◆ OnCommand()

static int OnCommand ( HWND  hWnd,
UINT  uMsg,
WPARAM  wParam,
LPARAM  lParam 
)
static

Definition at line 202 of file clipbrd.c.

203 {
204  switch (LOWORD(wParam))
205  {
206  case CMD_OPEN:
207  {
209  break;
210  }
211 
212  case CMD_SAVE_AS:
213  {
215  break;
216  }
217 
218  case CMD_EXIT:
219  {
221  break;
222  }
223 
224  case CMD_DELETE:
225  {
229  {
230  break;
231  }
232 
234  break;
235  }
236 
237  case CMD_AUTOMATIC:
238  {
239  SetDisplayFormat(0);
240  break;
241  }
242 
243  case CMD_HELP:
244  {
245  HtmlHelpW(Globals.hMainWnd, L"clipbrd.chm", 0, 0);
246  break;
247  }
248 
249  case CMD_ABOUT:
250  {
251  HICON hIcon;
253 
258  break;
259  }
260 
261  default:
262  {
263  break;
264  }
265  }
266  return 0;
267 }
#define MAKEINTRESOURCE
Definition: winuser.h:591
static HICON
Definition: imagelist.c:84
#define IDYES
Definition: winuser.h:829
#define CMD_AUTOMATIC
Definition: resources.h:22
#define ARRAYSIZE(array)
Definition: filtermapper.c:47
BOOL WINAPI DeleteObject(_In_ HGDIOBJ)
#define CMD_EXIT
Definition: resources.h:17
#define MAX_STRING_LEN
Definition: precomp.h:36
#define CMD_DELETE
Definition: resources.h:18
#define CMD_SAVE_AS
Definition: resources.h:16
int WINAPI LoadStringW(_In_opt_ HINSTANCE hInstance, _In_ UINT uID, _Out_writes_to_(cchBufferMax, return+1) LPWSTR lpBuffer, _In_ int cchBufferMax)
WPARAM wParam
Definition: combotst.c:138
#define MB_ICONWARNING
Definition: winuser.h:780
CLIPBOARD_GLOBALS Globals
Definition: clipbrd.c:13
#define MB_YESNO
Definition: winuser.h:811
HWND WINAPI HtmlHelpW(HWND caller, LPCWSTR filename, UINT command, DWORD_PTR data)
Definition: hhctrl.c:149
void DeleteClipboardContent(void)
Definition: cliputils.c:134
#define STRING_DELETE_TITLE
Definition: resources.h:27
#define CMD_OPEN
Definition: resources.h:15
smooth NULL
Definition: ftsmooth.c:416
static void LoadClipboardFromFile(void)
Definition: clipbrd.c:73
int MessageBoxRes(HWND hWnd, HINSTANCE hInstance, UINT uText, UINT uCaption, UINT uType)
Definition: winutils.c:49
#define CMD_ABOUT
Definition: resources.h:20
__wchar_t WCHAR
Definition: xmlstorage.h:180
#define WM_CLOSE
Definition: winuser.h:1603
TCHAR szTitle[MAX_LOADSTRING]
Definition: magnifier.c:35
static const WCHAR L[]
Definition: oid.c:1250
static void SaveClipboardToFile(void)
Definition: clipbrd.c:16
BOOL WINAPI ShellAboutW(HWND hWnd, LPCWSTR szApp, LPCWSTR szOtherStuff, HICON hIcon)
#define STRING_DELETE_MSG
Definition: resources.h:26
#define CLIPBRD_ICON
Definition: resources.h:10
#define STRING_CLIPBOARD
Definition: resources.h:24
HICON hIcon
Definition: msconfig.c:44
#define CMD_HELP
Definition: resources.h:19
BOOL WINAPI PostMessageW(_In_opt_ HWND, _In_ UINT, _In_ WPARAM, _In_ LPARAM)
HICON WINAPI LoadIconW(_In_opt_ HINSTANCE, _In_ LPCWSTR)
Definition: cursoricon.c:2044
static void SetDisplayFormat(UINT uFormat)
Definition: clipbrd.c:110
HINSTANCE hInstance
Definition: precomp.h:43
#define LOWORD(l)
Definition: pedump.c:82

Referenced by MainWndProc().

◆ OnPaint()

static void OnPaint ( HWND  hWnd,
WPARAM  wParam,
LPARAM  lParam 
)
static

Definition at line 269 of file clipbrd.c.

270 {
271  HDC hdc;
272  PAINTSTRUCT ps;
273  COLORREF crOldBkColor, crOldTextColor;
274  RECT rc;
275 
277  return;
278 
279  hdc = BeginPaint(hWnd, &ps);
280 
281  /* Erase the background if needed */
282  if (ps.fErase)
283  FillRect(ps.hdc, &ps.rcPaint, (HBRUSH)(COLOR_WINDOW + 1));
284 
285  /* Set the correct background and text colors */
286  crOldBkColor = SetBkColor(ps.hdc, GetSysColor(COLOR_WINDOW));
287  crOldTextColor = SetTextColor(ps.hdc, GetSysColor(COLOR_WINDOWTEXT));
288 
289  /* Realize the clipboard palette if there is one */
291 
292  switch (Globals.uDisplayFormat)
293  {
294  case CF_NONE:
295  {
296  /* The clipboard is empty */
297  break;
298  }
299 
300  case CF_DSPTEXT:
301  case CF_TEXT:
302  case CF_OEMTEXT:
303  case CF_UNICODETEXT:
304  {
306  break;
307  }
308 
309  case CF_DSPBITMAP:
310  case CF_BITMAP:
311  {
313  break;
314  }
315 
316  case CF_DIB:
317  case CF_DIBV5:
318  {
320  break;
321  }
322 
323  case CF_DSPMETAFILEPICT:
324  case CF_METAFILEPICT:
325  {
326  GetClientRect(hWnd, &rc);
328  break;
329  }
330 
331  case CF_DSPENHMETAFILE:
332  case CF_ENHMETAFILE:
333  {
334  GetClientRect(hWnd, &rc);
336  break;
337  }
338 
339  // case CF_PALETTE:
340  // TODO: Draw a palette with squares filled with colors.
341  // break;
342 
343  case CF_OWNERDISPLAY:
344  {
345  HGLOBAL hglb;
346  PPAINTSTRUCT pps;
347 
348  hglb = GlobalAlloc(GMEM_MOVEABLE, sizeof(ps));
349  if (hglb)
350  {
351  pps = GlobalLock(hglb);
352  CopyMemory(pps, &ps, sizeof(ps));
353  GlobalUnlock(hglb);
354 
356  (WPARAM)hWnd, (LPARAM)hglb);
357 
358  GlobalFree(hglb);
359  }
360  break;
361  }
362 
363  default:
364  {
365  GetClientRect(hWnd, &rc);
368  break;
369  }
370  }
371 
372  /* Restore the original colors */
373  SetTextColor(ps.hdc, crOldTextColor);
374  SetBkColor(ps.hdc, crOldBkColor);
375 
376  EndPaint(hWnd, &ps);
377 
378  CloseClipboard();
379 }
SCROLLSTATE Scrollstate
Definition: clipbrd.c:14
#define TRUE
Definition: types.h:120
HGLOBAL NTAPI GlobalAlloc(UINT uFlags, SIZE_T dwBytes)
Definition: heapmem.c:368
#define CF_ENHMETAFILE
Definition: constants.h:409
#define CF_DSPMETAFILEPICT
Definition: constants.h:416
#define DT_WORDBREAK
Definition: winuser.h:544
static HDC
Definition: imagelist.c:92
HWND hWnd
Definition: settings.c:17
void BitBltFromClipboard(PAINTSTRUCT ps, SCROLLSTATE state, DWORD dwRop)
Definition: winutils.c:155
UINT_PTR WPARAM
Definition: windef.h:207
void DrawTextFromResource(HINSTANCE hInstance, UINT uID, HDC hDC, LPRECT lpRect, UINT uFormat)
Definition: winutils.c:65
#define CF_METAFILEPICT
Definition: constants.h:398
BOOL WINAPI EndPaint(_In_ HWND, _In_ const PAINTSTRUCT *)
#define DT_NOPREFIX
Definition: winuser.h:537
#define COLOR_WINDOW
Definition: winuser.h:908
DWORD WINAPI GetSysColor(_In_ int)
COLORREF WINAPI SetBkColor(_In_ HDC, _In_ COLORREF)
Definition: dc.c:975
CLIPBOARD_GLOBALS Globals
Definition: clipbrd.c:13
void PlayEnhMetaFileFromClipboard(HDC hdc, const RECT *lpRect)
Definition: winutils.c:326
BOOL RealizeClipboardPalette(HDC hdc)
Definition: winutils.c:334
#define CF_OWNERDISPLAY
Definition: constants.h:413
HDC WINAPI BeginPaint(_In_ HWND, _Out_ LPPAINTSTRUCT)
#define CF_DSPENHMETAFILE
Definition: constants.h:417
#define CF_UNICODETEXT
Definition: constants.h:408
#define CF_BITMAP
Definition: constants.h:397
void PlayMetaFileFromClipboard(HDC hdc, const RECT *lpRect)
Definition: winutils.c:306
LONG_PTR LPARAM
Definition: windef.h:208
#define CF_TEXT
Definition: constants.h:396
#define ERROR_UNSUPPORTED_FORMAT
Definition: resources.h:46
DWORD COLORREF
Definition: windef.h:285
#define COLOR_WINDOWTEXT
Definition: winuser.h:911
#define CF_DSPBITMAP
Definition: constants.h:415
#define CF_NONE
Definition: precomp.h:39
#define CopyMemory
Definition: winbase.h:1633
HGLOBAL NTAPI GlobalFree(HGLOBAL hMem)
Definition: heapmem.c:611
LRESULT SendClipboardOwnerMessage(IN BOOL bUnicode, IN UINT uMsg, IN WPARAM wParam, IN LPARAM lParam)
Definition: cliputils.c:12
BOOL WINAPI CloseClipboard(void)
Definition: ntwrapper.h:178
LPVOID NTAPI GlobalLock(HGLOBAL hMem)
Definition: heapmem.c:755
HDC hdc
Definition: main.c:9
COLORREF WINAPI SetTextColor(_In_ HDC, _In_ COLORREF)
Definition: text.c:888
BOOL WINAPI GetClientRect(_In_ HWND, _Out_ LPRECT)
#define WM_PAINTCLIPBOARD
Definition: winuser.h:1852
#define CF_OEMTEXT
Definition: constants.h:402
void SetDIBitsToDeviceFromClipboard(UINT uFormat, PAINTSTRUCT ps, SCROLLSTATE state, UINT fuColorUse)
Definition: winutils.c:187
BOOL NTAPI GlobalUnlock(HGLOBAL hMem)
Definition: heapmem.c:1190
#define DT_CENTER
Definition: winuser.h:527
#define CF_DSPTEXT
Definition: constants.h:414
BOOL WINAPI OpenClipboard(_In_opt_ HWND)
#define DIB_RGB_COLORS
Definition: wingdi.h:366
HINSTANCE hInstance
Definition: precomp.h:43
int WINAPI FillRect(HDC, LPCRECT, HBRUSH)
void DrawTextFromClipboard(UINT uFormat, PAINTSTRUCT ps, SCROLLSTATE state)
Definition: winutils.c:75
#define GMEM_MOVEABLE
Definition: winbase.h:291
#define SRCCOPY
Definition: wingdi.h:332
#define CF_DIB
Definition: constants.h:403
UINT uDisplayFormat
Definition: precomp.h:47

Referenced by MainWndProc().

◆ SaveClipboardToFile()

static void SaveClipboardToFile ( void  )
static

Definition at line 16 of file clipbrd.c.

17 {
19  LPWSTR c;
20  WCHAR szFileName[MAX_PATH];
21  WCHAR szFilterMask[MAX_STRING_LEN + 10];
22 
23  ZeroMemory(&szFilterMask, sizeof(szFilterMask));
24  c = szFilterMask + LoadStringW(Globals.hInstance, STRING_FORMAT_NT, szFilterMask, MAX_STRING_LEN) + 1;
25  wcscpy(c, L"*.clp");
26 
27  ZeroMemory(&szFileName, sizeof(szFileName));
28  ZeroMemory(&sfn, sizeof(sfn));
29  sfn.lStructSize = sizeof(sfn);
32  sfn.lpstrFilter = szFilterMask;
33  sfn.lpstrFile = szFileName;
34  sfn.nMaxFile = ARRAYSIZE(szFileName);
36  sfn.lpstrDefExt = L"clp";
37 
38  if (!GetSaveFileNameW(&sfn))
39  return;
40 
42  {
44  return;
45  }
46 
47  WriteClipboardFile(szFileName, CLIP_FMT_NT /* CLIP_FMT_31 */);
48 
50 }
HINSTANCE hInstance
Definition: commdlg.h:362
DWORD Flags
Definition: commdlg.h:373
LPCWSTR lpstrFilter
Definition: commdlg.h:363
LPWSTR lpstrFile
Definition: commdlg.h:367
#define STRING_FORMAT_NT
Definition: resources.h:28
#define ARRAYSIZE(array)
Definition: filtermapper.c:47
#define ZeroMemory
Definition: winbase.h:1635
#define MAX_STRING_LEN
Definition: precomp.h:36
#define CLIP_FMT_NT
Definition: fileutils.h:13
int WINAPI LoadStringW(_In_opt_ HINSTANCE hInstance, _In_ UINT uID, _Out_writes_to_(cchBufferMax, return+1) LPWSTR lpBuffer, _In_ int cchBufferMax)
BOOL WINAPI GetSaveFileNameW(LPOPENFILENAMEW ofn)
Definition: filedlg.c:4629
DWORD lStructSize
Definition: commdlg.h:360
void ShowLastWin32Error(HWND hwndParent)
Definition: winutils.c:11
CLIPBOARD_GLOBALS Globals
Definition: clipbrd.c:13
LPCWSTR lpstrDefExt
Definition: commdlg.h:376
#define OFN_PATHMUSTEXIST
Definition: commdlg.h:117
OPENFILENAMEW sfn
Definition: eventvwr.c:118
__wchar_t WCHAR
Definition: xmlstorage.h:180
#define MAX_PATH
Definition: compat.h:26
const GLubyte * c
Definition: glext.h:8905
DWORD nMaxFile
Definition: commdlg.h:368
BOOL WINAPI CloseClipboard(void)
Definition: ntwrapper.h:178
HWND hwndOwner
Definition: commdlg.h:361
_CRTIMP wchar_t *__cdecl wcscpy(_Out_writes_z_(_String_length_(_Source)+1) wchar_t *_Dest, _In_z_ const wchar_t *_Source)
static const WCHAR L[]
Definition: oid.c:1250
#define OFN_HIDEREADONLY
Definition: commdlg.h:107
#define OFN_OVERWRITEPROMPT
Definition: commdlg.h:116
#define c
Definition: ke_i.h:80
BOOL WINAPI OpenClipboard(_In_opt_ HWND)
WCHAR * LPWSTR
Definition: xmlstorage.h:184
HINSTANCE hInstance
Definition: precomp.h:43
void WriteClipboardFile(LPCWSTR lpFileName, WORD wFileIdentifier)
Definition: fileutils.c:449

Referenced by OnCommand().

◆ SetDisplayFormat()

static void SetDisplayFormat ( UINT  uFormat)
static

Definition at line 110 of file clipbrd.c.

111 {
112  RECT rc;
113 
115  Globals.uCheckedItem = uFormat + CMD_AUTOMATIC;
117 
118  if (uFormat == 0)
119  {
121  }
122  else
123  {
124  Globals.uDisplayFormat = uFormat;
125  }
126 
131 
133 }
SCROLLSTATE Scrollstate
Definition: clipbrd.c:14
#define TRUE
Definition: types.h:120
#define MF_BYCOMMAND
Definition: winuser.h:202
UINT GetAutomaticClipboardFormat(void)
Definition: cliputils.c:150
#define CMD_AUTOMATIC
Definition: resources.h:22
BOOL GetClipboardDataDimensions(UINT uFormat, PRECT pRc)
Definition: cliputils.c:248
LONG right
Definition: windef.h:293
CLIPBOARD_GLOBALS Globals
Definition: clipbrd.c:13
smooth NULL
Definition: ftsmooth.c:416
#define MF_CHECKED
Definition: winuser.h:132
BOOL WINAPI InvalidateRect(_In_opt_ HWND, _In_opt_ LPCRECT, _In_ BOOL)
DWORD WINAPI CheckMenuItem(_In_ HMENU, _In_ UINT, _In_ UINT)
#define MF_UNCHECKED
Definition: winuser.h:204
INT iWheelCarryoverY
Definition: scrollutils.h:15
INT iWheelCarryoverX
Definition: scrollutils.h:14
void UpdateWindowScrollState(HWND hWnd, INT nMaxWidth, INT nMaxHeight, LPSCROLLSTATE lpState)
Definition: scrollutils.c:256
LONG bottom
Definition: windef.h:294
UINT uDisplayFormat
Definition: precomp.h:47

Referenced by MainWndProc(), and OnCommand().

◆ UpdateDisplayMenu()

static void UpdateDisplayMenu ( void  )
static

Definition at line 154 of file clipbrd.c.

155 {
156  UINT uFormat;
157  HMENU hMenu;
158  WCHAR szFormatName[MAX_FMT_NAME_LEN + 1];
159 
161 
162  while (GetMenuItemCount(hMenu) > 1)
163  {
164  DeleteMenu(hMenu, 1, MF_BYPOSITION);
165  }
166 
167  if (CountClipboardFormats() == 0)
168  return;
169 
171  return;
172 
173  AppendMenuW(hMenu, MF_SEPARATOR, 0, NULL);
174 
175  /* Display the supported clipboard formats first */
176  for (uFormat = EnumClipboardFormats(0); uFormat;
177  uFormat = EnumClipboardFormats(uFormat))
178  {
179  if (IsClipboardFormatSupported(uFormat))
180  {
182  szFormatName, ARRAYSIZE(szFormatName));
183  AppendMenuW(hMenu, MF_STRING, CMD_AUTOMATIC + uFormat, szFormatName);
184  }
185  }
186 
187  /* Now display the unsupported clipboard formats */
188  for (uFormat = EnumClipboardFormats(0); uFormat;
189  uFormat = EnumClipboardFormats(uFormat))
190  {
191  if (!IsClipboardFormatSupported(uFormat))
192  {
194  szFormatName, ARRAYSIZE(szFormatName));
195  AppendMenuW(hMenu, MF_STRING | MF_GRAYED, 0, szFormatName);
196  }
197  }
198 
199  CloseClipboard();
200 }
#define TRUE
Definition: types.h:120
#define CMD_AUTOMATIC
Definition: resources.h:22
#define DISPLAY_MENU_POS
Definition: precomp.h:37
#define MF_STRING
Definition: winuser.h:138
#define ARRAYSIZE(array)
Definition: filtermapper.c:47
#define MAX_FMT_NAME_LEN
Definition: fileutils.h:16
BOOL WINAPI AppendMenuW(_In_ HMENU, _In_ UINT, _In_ UINT_PTR, _In_opt_ LPCWSTR)
CLIPBOARD_GLOBALS Globals
Definition: clipbrd.c:13
#define MF_BYPOSITION
Definition: winuser.h:203
int WINAPI GetMenuItemCount(_In_opt_ HMENU)
smooth NULL
Definition: ftsmooth.c:416
#define MF_SEPARATOR
Definition: winuser.h:137
BOOL IsClipboardFormatSupported(UINT uFormat)
Definition: cliputils.c:173
__wchar_t WCHAR
Definition: xmlstorage.h:180
BOOL WINAPI DeleteMenu(_In_ HMENU, _In_ UINT, _In_ UINT)
void RetrieveClipboardFormatName(HINSTANCE hInstance, UINT uFormat, BOOL Unicode, PVOID lpszFormat, UINT cch)
Definition: cliputils.c:95
UINT WINAPI EnumClipboardFormats(_In_ UINT)
BOOL WINAPI CloseClipboard(void)
Definition: ntwrapper.h:178
HMENU WINAPI GetSubMenu(_In_ HMENU, _In_ int)
unsigned int UINT
Definition: ndis.h:50
BOOL WINAPI OpenClipboard(_In_opt_ HWND)
#define MF_GRAYED
Definition: winuser.h:129
HINSTANCE hInstance
Definition: precomp.h:43
int WINAPI CountClipboardFormats(void)
Definition: ntwrapper.h:184
static const CLSID *static CLSID *static const GUID VARIANT VARIANT *static IServiceProvider DWORD *static HMENU
Definition: ordinal.c:60

Referenced by MainWndProc().

◆ wWinMain()

int WINAPI wWinMain ( HINSTANCE  hInstance,
HINSTANCE  hPrevInstance,
LPWSTR  lpCmdLine,
int  nShowCmd 
)

This file has no copyright assigned and is placed in the Public Domain. This file is part of the w64 mingw-runtime package. No warranty is given; refer to the file DISCLAIMER.PD within this package.

Definition at line 663 of file clipbrd.c.

664 {
665  MSG msg;
666  HACCEL hAccel;
667  HWND hPrevWindow;
668  WNDCLASSEXW wndclass;
669  WCHAR szBuffer[MAX_STRING_LEN];
670 
671  hPrevWindow = FindWindowW(szClassName, NULL);
672  if (hPrevWindow)
673  {
674  BringWindowToFront(hPrevWindow);
675  return 0;
676  }
677 
678  switch (GetUserDefaultUILanguage())
679  {
682  break;
683 
684  default:
685  break;
686  }
687 
688  ZeroMemory(&Globals, sizeof(Globals));
690 
691  ZeroMemory(&wndclass, sizeof(wndclass));
692  wndclass.cbSize = sizeof(wndclass);
693  wndclass.lpfnWndProc = MainWndProc;
694  wndclass.hInstance = hInstance;
696  wndclass.hCursor = LoadCursorW(0, IDC_ARROW);
697  wndclass.hbrBackground = (HBRUSH)(COLOR_WINDOW + 1);
699  wndclass.lpszClassName = szClassName;
700 
701  if (!RegisterClassExW(&wndclass))
702  {
704  return 0;
705  }
706 
708 
709  LoadStringW(hInstance, STRING_CLIPBOARD, szBuffer, ARRAYSIZE(szBuffer));
711  szClassName,
712  szBuffer,
718  NULL,
719  NULL,
721  NULL);
722  if (!Globals.hMainWnd)
723  {
725  return 0;
726  }
727 
728  ShowWindow(Globals.hMainWnd, nCmdShow);
730 
732  if (!hAccel)
733  {
735  }
736 
737  /* If the user provided a path to a clipboard data file, try to open it */
738  if (__argc >= 2)
740 
741  while (GetMessageW(&msg, 0, 0, 0))
742  {
744  {
747  }
748  }
749 
750  return (int)msg.wParam;
751 }
LANGID WINAPI GetUserDefaultUILanguage(void)
Definition: lang.c:806
BOOL WINAPI TranslateMessage(_In_ const MSG *)
SCROLLSTATE Scrollstate
Definition: clipbrd.c:14
#define LAYOUT_RTL
Definition: wingdi.h:1370
static void LoadClipboardDataFromFile(LPWSTR lpszFileName)
Definition: clipbrd.c:52
TW_UINT32 TW_UINT16 TW_UINT16 MSG
Definition: twain.h:1827
#define SUBLANG_DEFAULT
Definition: nls.h:168
#define MAIN_MENU
Definition: resources.h:12
BOOL WINAPI UpdateWindow(_In_ HWND)
#define ARRAYSIZE(array)
Definition: filtermapper.c:47
#define ZeroMemory
Definition: winbase.h:1635
HICON hIcon
Definition: winuser.h:3196
#define MAX_STRING_LEN
Definition: precomp.h:36
BOOL WINAPI ShowWindow(_In_ HWND, _In_ int)
int WINAPI LoadStringW(_In_opt_ HINSTANCE hInstance, _In_ UINT uID, _Out_writes_to_(cchBufferMax, return+1) LPWSTR lpBuffer, _In_ int cchBufferMax)
#define COLOR_WINDOW
Definition: winuser.h:908
#define LANG_HEBREW
Definition: nls.h:67
ATOM WINAPI RegisterClassExW(_In_ CONST WNDCLASSEXW *)
void ShowLastWin32Error(HWND hwndParent)
Definition: winutils.c:11
CLIPBOARD_GLOBALS Globals
Definition: clipbrd.c:13
HINSTANCE hInstance
Definition: charmap.c:20
LPCWSTR lpszMenuName
Definition: winuser.h:3199
LRESULT WINAPI DispatchMessageW(_In_ const MSG *)
HACCEL hAccel
Definition: main.c:47
#define CW_USEDEFAULT
Definition: winuser.h:225
HACCEL WINAPI LoadAcceleratorsW(_In_opt_ HINSTANCE, _In_ LPCWSTR)
smooth NULL
Definition: ftsmooth.c:416
LPCWSTR lpszClassName
Definition: winuser.h:3200
BOOL WINAPI SetProcessDefaultLayout(DWORD dwDefaultLayout)
Definition: window.c:1716
static const WCHAR szClassName[]
Definition: clipbrd.c:11
__wchar_t WCHAR
Definition: xmlstorage.h:180
HWND WINAPI FindWindowW(_In_opt_ LPCWSTR, _In_opt_ LPCWSTR)
HBRUSH hbrBackground
Definition: winuser.h:3198
UINT cbSize
Definition: winuser.h:3190
HCURSOR WINAPI LoadCursorW(_In_opt_ HINSTANCE, _In_ LPCWSTR)
Definition: cursoricon.c:2074
#define WS_HSCROLL
Definition: pedump.c:628
HINSTANCE hInstance
Definition: winuser.h:3195
int WINAPI TranslateAcceleratorW(_In_ HWND, _In_ HACCEL, _In_ LPMSG)
HWND WINAPI CreateWindowExW(_In_ DWORD dwExStyle, _In_opt_ LPCWSTR lpClassName, _In_opt_ LPCWSTR lpWindowName, _In_ DWORD dwStyle, _In_ int X, _In_ int Y, _In_ int nWidth, _In_ int nHeight, _In_opt_ HWND hWndParent, _In_opt_ HMENU hMenu, _In_opt_ HINSTANCE hInstance, _In_opt_ LPVOID lpParam)
static LRESULT WINAPI MainWndProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
Definition: clipbrd.c:381
#define CLIPBRD_ICON
Definition: resources.h:10
HCURSOR hCursor
Definition: winuser.h:3197
WNDPROC lpfnWndProc
Definition: winuser.h:3192
#define WS_EX_CLIENTEDGE
Definition: winuser.h:384
#define STRING_CLIPBOARD
Definition: resources.h:24
#define WS_VSCROLL
Definition: pedump.c:627
BOOL WINAPI GetMessageW(_Out_ LPMSG, _In_opt_ HWND, _In_ UINT, _In_ UINT)
#define msg(x)
Definition: auth_time.c:54
#define IDC_ARROW
Definition: winuser.h:682
void BringWindowToFront(HWND hWnd)
Definition: winutils.c:36
_CRTIMP int __argc
Definition: getargs.c:21
_CRTIMP wchar_t ** __wargv
Definition: getargs.c:20
#define ID_ACCEL
Definition: resources.h:13
#define WS_OVERLAPPEDWINDOW
Definition: pedump.c:637
#define MAKELANGID(p, s)
Definition: nls.h:15
HICON WINAPI LoadIconW(_In_opt_ HINSTANCE, _In_ LPCWSTR)
Definition: cursoricon.c:2044
#define MAKEINTRESOURCEW(i)
Definition: winuser.h:582
#define WS_EX_ACCEPTFILES
Definition: pedump.c:648
HINSTANCE hInstance
Definition: precomp.h:43

Variable Documentation

◆ Globals

◆ Scrollstate

SCROLLSTATE Scrollstate

Definition at line 14 of file clipbrd.c.

Referenced by MainWndProc(), OnPaint(), SetDisplayFormat(), and wWinMain().

◆ szClassName