source: trunk/Utilities/Miscellaneous/GetClipboardData/GetClipboardData.cpp @ 135

Last change on this file since 135 was 135, checked in by roman, 10 years ago

Added missing forwarding for WM_DRAWCLIPBOARD

File size: 5.6 KB
Line 
1// GetClipboardData.cpp : Defines the entry point for the application.
2//
3
4#include "stdafx.h"
5#include "GetClipboardData.h"
6
7#define MAX_LOADSTRING 100
8
9// Global Variables:
10HINSTANCE hInst;                                                                // current instance
11TCHAR szTitle[MAX_LOADSTRING];                                  // The title bar text
12TCHAR szWindowClass[MAX_LOADSTRING];                    // the main window class name
13
14// Forward declarations of functions included in this code module:
15ATOM                            MyRegisterClass(HINSTANCE hInstance);
16BOOL                            InitInstance(HINSTANCE, int);
17LRESULT CALLBACK        WndProc(HWND, UINT, WPARAM, LPARAM);
18INT_PTR CALLBACK        About(HWND, UINT, WPARAM, LPARAM);
19
20int APIENTRY _tWinMain(HINSTANCE hInstance,
21                     HINSTANCE hPrevInstance,
22                     LPTSTR    lpCmdLine,
23                     int       nCmdShow)
24{
25        UNREFERENCED_PARAMETER(hPrevInstance);
26        UNREFERENCED_PARAMETER(lpCmdLine);
27
28        // TODO: Place code here.
29        MSG msg;
30        HACCEL hAccelTable;
31
32        // Initialize global strings
33        LoadString(hInstance, IDS_APP_TITLE, szTitle, MAX_LOADSTRING);
34        LoadString(hInstance, IDC_GETCLIPBOARDDATA, szWindowClass, MAX_LOADSTRING);
35        MyRegisterClass(hInstance);
36
37        // Perform application initialization:
38        if (!InitInstance (hInstance, nCmdShow))
39        {
40                return FALSE;
41        }
42
43        hAccelTable = LoadAccelerators(hInstance, MAKEINTRESOURCE(IDC_GETCLIPBOARDDATA));
44
45        // Main message loop:
46        while (GetMessage(&msg, NULL, 0, 0))
47        {
48                if (!TranslateAccelerator(msg.hwnd, hAccelTable, &msg))
49                {
50                        TranslateMessage(&msg);
51                        DispatchMessage(&msg);
52                }
53        }
54
55        return (int) msg.wParam;
56}
57
58
59
60//
61//  FUNCTION: MyRegisterClass()
62//
63//  PURPOSE: Registers the window class.
64//
65//  COMMENTS:
66//
67//    This function and its usage are only necessary if you want this code
68//    to be compatible with Win32 systems prior to the 'RegisterClassEx'
69//    function that was added to Windows 95. It is important to call this function
70//    so that the application will get 'well formed' small icons associated
71//    with it.
72//
73ATOM MyRegisterClass(HINSTANCE hInstance)
74{
75        WNDCLASSEX wcex;
76
77        wcex.cbSize = sizeof(WNDCLASSEX);
78
79        wcex.style                      = CS_HREDRAW | CS_VREDRAW;
80        wcex.lpfnWndProc        = WndProc;
81        wcex.cbClsExtra         = 0;
82        wcex.cbWndExtra         = 0;
83        wcex.hInstance          = hInstance;
84        wcex.hIcon                      = LoadIcon(hInstance, MAKEINTRESOURCE(IDI_GETCLIPBOARDDATA));
85        wcex.hCursor            = LoadCursor(NULL, IDC_ARROW);
86        wcex.hbrBackground      = (HBRUSH)(COLOR_WINDOW+1);
87        wcex.lpszMenuName       = MAKEINTRESOURCE(IDC_GETCLIPBOARDDATA);
88        wcex.lpszClassName      = szWindowClass;
89        wcex.hIconSm            = LoadIcon(wcex.hInstance, MAKEINTRESOURCE(IDI_SMALL));
90
91        return RegisterClassEx(&wcex);
92}
93
94//
95//   FUNCTION: InitInstance(HINSTANCE, int)
96//
97//   PURPOSE: Saves instance handle and creates main window
98//
99//   COMMENTS:
100//
101//        In this function, we save the instance handle in a global variable and
102//        create and display the main program window.
103//
104BOOL InitInstance(HINSTANCE hInstance, int nCmdShow)
105{
106   HWND hWnd;
107
108   hInst = hInstance; // Store instance handle in our global variable
109
110   hWnd = CreateWindow(szWindowClass, szTitle, WS_OVERLAPPEDWINDOW,
111      CW_USEDEFAULT, 0, CW_USEDEFAULT, 0, NULL, NULL, hInstance, NULL);
112
113   if (!hWnd)
114   {
115      return FALSE;
116   }
117
118   ShowWindow(hWnd, nCmdShow);
119   UpdateWindow(hWnd);
120
121   return TRUE;
122}
123
124//
125//  FUNCTION: WndProc(HWND, UINT, WPARAM, LPARAM)
126//
127//  PURPOSE:  Processes messages for the main window.
128//
129//  WM_COMMAND  - process the application menu
130//  WM_PAINT    - Paint the main window
131//  WM_DESTROY  - post a quit message and return
132//
133//
134
135HWND hNextClipboardViewerWindow;
136
137LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
138{
139        int wmId, wmEvent;
140        PAINTSTRUCT ps;
141        HDC hdc;
142
143        switch (message)
144        {
145
146        #pragma region Real Code
147        case WM_CREATE:
148                hNextClipboardViewerWindow = SetClipboardViewer(hWnd);
149                break;
150        case WM_CHANGECBCHAIN:
151                {
152                        HWND hRemovedWindow = (HWND) wParam;
153                        HWND hNextWindow = (HWND) lParam;
154                        if(hNextClipboardViewerWindow == hRemovedWindow)
155                                hNextClipboardViewerWindow = hNextWindow;
156                        else if(hNextClipboardViewerWindow)
157                                SendMessage(hNextClipboardViewerWindow, WM_CHANGECBCHAIN, wParam, lParam);
158                }
159                break;
160        case WM_DRAWCLIPBOARD:
161                {
162                        if(OpenClipboard(hWnd)) 
163                        {
164                                if(IsClipboardFormatAvailable(CF_UNICODETEXT))
165                                {
166                                        HGLOBAL hData = (HGLOBAL) GetClipboardData(CF_UNICODETEXT);
167                                        // ...
168                                }
169                                CloseClipboard();
170                        }
171                        if(hNextClipboardViewerWindow)
172                                SendMessage(hNextClipboardViewerWindow, WM_DRAWCLIPBOARD, wParam, lParam);             
173                }
174                break;
175        #pragma endregion
176
177        case WM_COMMAND:
178                wmId    = LOWORD(wParam);
179                wmEvent = HIWORD(wParam);
180                // Parse the menu selections:
181                switch (wmId)
182                {
183                case IDM_ABOUT:
184                        DialogBox(hInst, MAKEINTRESOURCE(IDD_ABOUTBOX), hWnd, About);
185                        break;
186                case IDM_EXIT:
187                        DestroyWindow(hWnd);
188                        break;
189                default:
190                        return DefWindowProc(hWnd, message, wParam, lParam);
191                }
192                break;
193        case WM_PAINT:
194                hdc = BeginPaint(hWnd, &ps);
195                // TODO: Add any drawing code here...
196                EndPaint(hWnd, &ps);
197                break;
198        case WM_DESTROY:
199                PostQuitMessage(0);
200                break;
201        default:
202                return DefWindowProc(hWnd, message, wParam, lParam);
203        }
204        return 0;
205}
206
207// Message handler for about box.
208INT_PTR CALLBACK About(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam)
209{
210        UNREFERENCED_PARAMETER(lParam);
211        switch (message)
212        {
213        case WM_INITDIALOG:
214                return (INT_PTR)TRUE;
215
216        case WM_COMMAND:
217                if (LOWORD(wParam) == IDOK || LOWORD(wParam) == IDCANCEL)
218                {
219                        EndDialog(hDlg, LOWORD(wParam));
220                        return (INT_PTR)TRUE;
221                }
222                break;
223        }
224        return (INT_PTR)FALSE;
225}
Note: See TracBrowser for help on using the repository browser.