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

Last change on this file since 134 was 134, checked in by roman, 11 years ago
File size: 5.5 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                }
172                break;
173        #pragma endregion
174
175        case WM_COMMAND:
176                wmId    = LOWORD(wParam);
177                wmEvent = HIWORD(wParam);
178                // Parse the menu selections:
179                switch (wmId)
180                {
181                case IDM_ABOUT:
182                        DialogBox(hInst, MAKEINTRESOURCE(IDD_ABOUTBOX), hWnd, About);
183                        break;
184                case IDM_EXIT:
185                        DestroyWindow(hWnd);
186                        break;
187                default:
188                        return DefWindowProc(hWnd, message, wParam, lParam);
189                }
190                break;
191        case WM_PAINT:
192                hdc = BeginPaint(hWnd, &ps);
193                // TODO: Add any drawing code here...
194                EndPaint(hWnd, &ps);
195                break;
196        case WM_DESTROY:
197                PostQuitMessage(0);
198                break;
199        default:
200                return DefWindowProc(hWnd, message, wParam, lParam);
201        }
202        return 0;
203}
204
205// Message handler for about box.
206INT_PTR CALLBACK About(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam)
207{
208        UNREFERENCED_PARAMETER(lParam);
209        switch (message)
210        {
211        case WM_INITDIALOG:
212                return (INT_PTR)TRUE;
213
214        case WM_COMMAND:
215                if (LOWORD(wParam) == IDOK || LOWORD(wParam) == IDCANCEL)
216                {
217                        EndDialog(hDlg, LOWORD(wParam));
218                        return (INT_PTR)TRUE;
219                }
220                break;
221        }
222        return (INT_PTR)FALSE;
223}
Note: See TracBrowser for help on using the repository browser.