@@ -25,35 +25,11 @@ using namespace std::experimental::drawing;
2525
2626#define MAX_LOADSTRING 100
2727
28- class ref_counted_bool {
29- ::std::atomic<int > m_refCount;
30- public:
31- ref_counted_bool () : m_refCount(0 ) {}
32- ref_counted_bool& operator =(bool value) {
33- if (value) {
34- m_refCount++;
35- }
36- else {
37- auto count = m_refCount.load (memory_order_acquire);
38- if (--count < 0 ) {
39- count = 0 ;
40- }
41- m_refCount.store (count, memory_order_release);
42- }
43- return *this ;
44- }
45- operator bool () {
46- return m_refCount.load () != 0 ;
47- }
48- };
4928
5029// Global Variables:
5130HINSTANCE hInst; // current instance
5231TCHAR szTitle[MAX_LOADSTRING]; // The title bar text
5332TCHAR szWindowClass[MAX_LOADSTRING]; // the main window class name
54- // unique_ptr<surface> g_psurface;
55- // RECT g_previousClientRect;
56- // ref_counted_bool g_doNotPaint;
5733
5834// Everything in the Draw function should be portable C++ code.
5935void Draw (surface& surface) {
@@ -199,59 +175,6 @@ void Draw(surface& surface) {
199175 context.show_text (" Hello C++!" );
200176}
201177
202- // void OnPaint(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam) {
203- // UNREFERENCED_PARAMETER(message);
204- // UNREFERENCED_PARAMETER(wParam);
205- // UNREFERENCED_PARAMETER(lParam);
206- //
207- // PAINTSTRUCT ps;
208- // HDC hdc;
209- // RECT updateRect{ };
210- // auto getUpdateRectResult = GetUpdateRect(hWnd, &updateRect, FALSE);
211- //
212- // // There's a bug somewhere (possibly cairo?) where if you run this code without the check to make sure that
213- // // updateRect.left and .top are both 0, it crashes and does so in the cairo DLL such that it's immune to
214- // // being caught. Specifically in a Win32/Debug config it throws well inside cairo on the ctxt.paint() call
215- // // on an illegal memory access (actually in pixman-sse2.c in a call to "void save_128_aligned(__m128i*, __m128i);").
216- // if (getUpdateRectResult != FALSE && updateRect.left == 0 && updateRect.top == 0) {
217- // hdc = BeginPaint(hWnd, &ps);
218- //
219- // RECT clientRect;
220- // if (!GetClientRect(hWnd, &clientRect)) {
221- // throw_get_last_error<logic_error>("Failed GetClientRect call.");
222- // }
223- // auto width = clientRect.right - clientRect.left;
224- // auto height = clientRect.bottom - clientRect.top;
225- // auto previousWidth = g_previousClientRect.right - g_previousClientRect.left;
226- // auto previousHeight = g_previousClientRect.bottom - g_previousClientRect.top;
227- //
228- // // To enable screenshot saving, we are using a global unique_ptr surface. I did not rewrite the boilerplate
229- // // Win32 code so that it'd be a class, hence the globals.
230- // if ((g_psurface == nullptr) || (width != previousWidth) || (height != previousHeight)) {
231- // g_psurface = unique_ptr<surface>(new surface(move(make_surface(format::argb32, width, height))));
232- // g_previousClientRect = clientRect;
233- // }
234- //
235- // // Draw to the off-screen buffer.
236- // Draw(*g_psurface);
237- //
238- // // Flush to ensure that it is drawn to the window.
239- // g_psurface->flush();
240- //
241- // auto surface = make_surface(cairo_win32_surface_create(hdc));
242- // auto ctxt = context(surface);
243- // ctxt.set_source_surface(*g_psurface, 0.0, 0.0);
244- // ctxt.paint();
245- // surface.flush();
246- // EndPaint(hWnd, &ps);
247- // }
248- // else {
249- // if (getUpdateRectResult != FALSE) {
250- // hdc = BeginPaint(hWnd, &ps);
251- // EndPaint(hWnd, &ps);
252- // }
253- // }
254- // }
255178
256179int WINAPI wWinMain (
257180 _In_ HINSTANCE hInstance,
@@ -261,7 +184,7 @@ int WINAPI wWinMain(
261184 ) {
262185 UNREFERENCED_PARAMETER (hPrevInstance);
263186 UNREFERENCED_PARAMETER (lpCmdLine);
264- // g_previousClientRect = { }; // Zero out previous client rect.
187+
265188 throw_if_failed_hresult<runtime_error>(
266189 CoInitializeEx (nullptr , COINIT_APARTMENTTHREADED), " Failed call to CoInitializeEx."
267190 );
@@ -274,12 +197,6 @@ int WINAPI wWinMain(
274197 LoadString (hInstance, IDC_N3888_REFIMPL, szWindowClass, MAX_LOADSTRING);
275198 MyRegisterClass (hInstance);
276199
277- // HWND hWnd;
278- // Perform application initialization:
279- // if (!InitInstance(hInstance, nCmdShow, hWnd)) {
280- // CoUninitialize();
281- // return FALSE;
282- // }
283200
284201 hAccelTable = LoadAccelerators (hInstance, MAKEINTRESOURCE (IDC_N3888_REFIMPL));
285202
@@ -361,143 +278,4 @@ ATOM MyRegisterClass(HINSTANCE hInstance) {
361278 wcex.hIconSm = LoadIcon (wcex.hInstance , MAKEINTRESOURCE (IDI_SMALL));
362279
363280 return RegisterClassEx (&wcex);
364- }
365-
366- //
367- // FUNCTION: InitInstance(HINSTANCE, int)
368- //
369- // PURPOSE: Saves instance handle and creates main window
370- //
371- // COMMENTS:
372- //
373- // In this function, we save the instance handle in a global variable and
374- // create and display the main program window.
375- //
376- BOOL InitInstance (HINSTANCE hInstance, int nCmdShow, HWND& hWnd) {
377- // HWND hWnd;
378- INITCOMMONCONTROLSEX initCommonControlsEx{ };
379- initCommonControlsEx.dwSize = sizeof (initCommonControlsEx);
380- initCommonControlsEx.dwICC = ICC_LINK_CLASS;
381- if (InitCommonControlsEx (&initCommonControlsEx) == FALSE ) {
382- throw runtime_error (" Failed call to InitCommonControlsEx." );
383- }
384-
385- hInst = hInstance; // Store instance handle in our global variable
386-
387- hWnd = CreateWindow (szWindowClass, szTitle, WS_OVERLAPPEDWINDOW,
388- CW_USEDEFAULT, 0 , CW_USEDEFAULT, 0 , NULL , NULL , hInstance, NULL );
389-
390- if (!hWnd) {
391- return FALSE ;
392- }
393-
394- ShowWindow (hWnd, nCmdShow);
395- UpdateWindow (hWnd);
396-
397- return TRUE ;
398- }
399-
400-
401- //
402- // FUNCTION: WndProc(HWND, UINT, WPARAM, LPARAM)
403- //
404- // PURPOSE: Processes messages for the main window.
405- //
406- // WM_COMMAND - process the application menu
407- // WM_PAINT - Paint the main window
408- // WM_DESTROY - post a quit message and return
409- //
410- //
411- // LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam) {
412- // int wmId, wmEvent;
413- //
414- // #if defined(DEBUG_WNDPROC)
415- // wstringstream str;
416- // str << L"Message: 0x" << hex << uppercase << message << nouppercase
417- // << L". WPARAM: 0x" << hex << uppercase << static_cast<UINT>(wParam) << nouppercase
418- // << L". LPARAM: 0x" << hex << uppercase << static_cast<UINT>(lParam) << endl;
419- // OutputDebugStringW(str.str().c_str());
420- // #endif
421- //
422- // switch (message) {
423- // case WM_COMMAND:
424- // wmId = LOWORD(wParam);
425- // wmEvent = HIWORD(wParam);
426- // // Parse the menu selections:
427- // switch (wmId) {
428- // case IDM_ABOUT:
429- // {
430- // auto aboutResult = DialogBox(hInst, MAKEINTRESOURCE(IDD_ABOUTBOX), hWnd, About);
431- // if (aboutResult <= 0) {
432- // throw_get_last_error<logic_error>("Failed call to DialogBox.");
433- // }
434- // }
435- // break;
436- // case ID_EDIT_SCREENCAPTURE:
437- // ShowSaveAsPNGDialog();
438- // break;
439- // case IDM_EXIT:
440- // DestroyWindow(hWnd);
441- // break;
442- // default:
443- // return DefWindowProc(hWnd, message, wParam, lParam);
444- // }
445- // break;
446- // case WM_ENTERSIZEMOVE:
447- // g_doNotPaint = true; // Don't paint while resizing to avoid flicker.
448- // return DefWindowProc(hWnd, message, wParam, lParam);
449- // case WM_EXITSIZEMOVE:
450- // g_doNotPaint = false;
451- // return DefWindowProc(hWnd, message, wParam, lParam);
452- // case WM_PAINT:
453- // if (!g_doNotPaint) {
454- // OnPaint(hWnd, message, wParam, lParam);
455- // }
456- // break;
457- // case WM_DESTROY:
458- // PostQuitMessage(0);
459- // break;
460- // default:
461- // return DefWindowProc(hWnd, message, wParam, lParam);
462- // }
463- // return 0;
464- // }
465-
466- // Message handler for about box.
467- // INT_PTR CALLBACK About(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam) {
468- // UNREFERENCED_PARAMETER(lParam);
469- // switch (message) {
470- // case WM_INITDIALOG:
471- // return (INT_PTR)TRUE;
472- //
473- // case WM_COMMAND:
474- // if (LOWORD(wParam) == IDOK || LOWORD(wParam) == IDCANCEL) {
475- // EndDialog(hDlg, LOWORD(wParam));
476- // return (INT_PTR)TRUE;
477- // }
478- // break;
479- // case WM_NOTIFY:
480- // {
481- // PNMLINK pnmLink = reinterpret_cast<PNMLINK>(lParam);
482- // if ((pnmLink->hdr.idFrom == IDC_SYSLINK1) || (pnmLink->hdr.idFrom == IDC_SYSLINK2)) {
483- // switch (pnmLink->hdr.code)
484- // {
485- // case NM_CLICK:
486- // // Intentional fall-through.
487- // case NM_RETURN:
488- // {
489- // auto shExecResult = reinterpret_cast<int>(ShellExecute(nullptr, L"open", pnmLink->item.szUrl, nullptr, nullptr, SW_SHOW));
490- // if (shExecResult <= 32) {
491- // wstringstream err;
492- // err << L"Error calling ShellExecute while trying to open the link. Return code: " << to_wstring(shExecResult) << "." << endl;
493- // MessageBox(hDlg, err.str().c_str(), L"Error opening link", MB_OK | MB_ICONEXCLAMATION);
494- // }
495- // }
496- // return (INT_PTR)TRUE;
497- // }
498- // }
499- // }
500- // break;
501- // }
502- // return (INT_PTR)FALSE;
503- // }
281+ }
0 commit comments