PDFView - Simple Viewer Control - C++ Sample Code

Sample C# code for using Apryse SDK's PDF viewer control in a basic project. This sample uses a number of built-in features from PDFViewCtrl to open PDF files, implement document navigation, text highlighting, markup, and editing. If you are looking for a sample showing how to further customize the viewer (e.g. by implementing custom tools or custom GUI elements), please take a look at the PDFView with customization sample code. Learn more about our Server SDK and PDF Viewer SDK.

1//---------------------------------------------------------------------------------------
2// Copyright (c) 2001-2021 by PDFTron Systems Inc. All Rights Reserved.
3// Consult legal.txt regarding legal and license information.
4//---------------------------------------------------------------------------------------
5// This sample shows how to add PDF viewer control in a basic Win32 project.
6// The sample uses a number of built-in features from PDFViewCtrl to implement
7// document navigation, text highlighting, markup, and editing.
8//
9// PDFViewCtrl offers built-in support for a number of PDF tools (including markup,
10// link creation, forms, text selection, etc) and user interface elements (such as
11// navigation panel, find text, etc). PDFViewCtrl is highly configurable allowing
12// users to implement custom tools or to modify behavior of built-in tools.
13// Default user interface elements such as the navigation panel can be replaced
14// with a custom implementation and users can override window events and various
15// document actions. For example, by default, PDFViewCtrl will launch URL links
16// in a web browser and will jump to a destination for 'GoTo' actions. The default
17// behavior can be overridden using a custom callback function (as shown in the
18// following sample).
19//
20// Besides PDFViewCtrl, the C++ version of PDFNet SDK also includes a low-level class
21// called PDFView. Because PDFView does not process any window messages and does not
22// implement built-in tools it is only suitable for very low-level control development
23// (e.g. if you would like to implement a control similar to PDFViewCtrl from scratch).
24// The basic use of PDFView is illustrated in PDFView sample project.
25//---------------------------------------------------------------------------------------
26
27#include "stdafx.h"
28#include "resource.h"
29#include <Common/Exception.h>
30#include <commdlg.h>
31#include <cassert>
32#include <PDF/PDFViewCtrl.h>
33#include <PDF/PDFDraw.h>
34#include <PDF/PDFNet.h>
35#include <stdlib.h>
36#include <iostream>
37#include <utility>
38#include <algorithm>
39#include <memory>
40#include "../../LicenseKey/CPP/LicenseKey.h"
41
42using namespace pdftron;
43using namespace PDF;
44
45#define MAX_LOADSTRING 100
46
47// Global Variables:
48HINSTANCE hInst; // current instance
49TCHAR szTitle[MAX_LOADSTRING]; // The title bar text
50TCHAR szWindowClass[MAX_LOADSTRING]; // the main window class name
51UString m_doc_name;
52std::auto_ptr<PDF::PDFDoc> mp_doc;
53std::auto_ptr<PDF::PDFViewCtrl> m_view;
54
55
56// Forward declarations of functions included in this code module:
57ATOM MyRegisterClass(HINSTANCE hInstance);
58BOOL InitInstance(HINSTANCE, int);
59LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM);
60INT_PTR CALLBACK About(HWND, UINT, WPARAM, LPARAM);
61
62int APIENTRY _tWinMain(HINSTANCE hInstance,
63 HINSTANCE hPrevInstance,
64 LPTSTR lpCmdLine,
65 int nCmdShow)
66{
67 UNREFERENCED_PARAMETER(hPrevInstance);
68 UNREFERENCED_PARAMETER(lpCmdLine);
69
70 // TODO: Place code here.
71 MSG msg;
72 HACCEL hAccelTable;
73
74 // Initialize global strings
75 LoadString(hInstance, IDS_APP_TITLE, szTitle, MAX_LOADSTRING);
76 LoadString(hInstance, IDC_PDFVIEWSIMPLE, szWindowClass, MAX_LOADSTRING);
77 MyRegisterClass(hInstance);
78
79 // Perform application initialization:
80 if (!InitInstance (hInstance, nCmdShow))
81 {
82 return FALSE;
83 }
84
85 hAccelTable = LoadAccelerators(hInstance, MAKEINTRESOURCE(IDC_PDFVIEWSIMPLE));
86
87 // Main message loop:
88 while (GetMessage(&msg, NULL, 0, 0))
89 {
90 if (!TranslateAccelerator(msg.hwnd, hAccelTable, &msg))
91 {
92 TranslateMessage(&msg);
93 DispatchMessage(&msg);
94 }
95 }
96
97 return (int) msg.wParam;
98}
99
100
101
102//
103// FUNCTION: MyRegisterClass()
104//
105// PURPOSE: Registers the window class.
106//
107// COMMENTS:
108//
109// This function and its usage are only necessary if you want this code
110// to be compatible with Win32 systems prior to the 'RegisterClassEx'
111// function that was added to Windows 95. It is important to call this function
112// so that the application will get 'well formed' small icons associated
113// with it.
114//
115ATOM MyRegisterClass(HINSTANCE hInstance)
116{
117 WNDCLASSEX wcex;
118
119 wcex.cbSize = sizeof(WNDCLASSEX);
120
121 wcex.style = CS_HREDRAW | CS_VREDRAW;
122 wcex.lpfnWndProc = WndProc;
123 wcex.cbClsExtra = 0;
124 wcex.cbWndExtra = 0;
125 wcex.hInstance = hInstance;
126 wcex.hIcon = LoadIcon(hInstance, MAKEINTRESOURCE(IDI_PDFVIEWSIMPLE));
127 wcex.hCursor = LoadCursor(NULL, IDC_ARROW);
128 wcex.hbrBackground = (HBRUSH)(COLOR_WINDOW+1);
129 wcex.lpszMenuName = MAKEINTRESOURCE(IDC_PDFVIEWSIMPLE);
130 wcex.lpszClassName = szWindowClass;
131 wcex.hIconSm = LoadIcon(wcex.hInstance, MAKEINTRESOURCE(IDI_SMALL));
132
133 return RegisterClassEx(&wcex);
134}
135
136
137typedef std::pair< int, PDF::PDFViewCtrl::ToolMode > ToolModeMapType;
138const ToolModeMapType toolModeMap[] = {
139 ToolModeMapType( IDM_TOOL_PAN , PDF::PDFViewCtrl::e_pan ),
140 ToolModeMapType( IDM_TOOL_STRUCTURALSELECTION , PDF::PDFViewCtrl::e_text_struct_select ),
141 ToolModeMapType( IDM_TOOL_RECTANGLESELECTION , PDF::PDFViewCtrl::e_text_rect_select ),
142 ToolModeMapType( IDM_TOOL_RECTANGLEZOOMIN , PDF::PDFViewCtrl::e_zoom_in ),
143 ToolModeMapType( IDM_TOOL_RECTANGLEZOOMOUT , PDF::PDFViewCtrl::e_zoom_out ),
144 ToolModeMapType( IDM_TOOL_ANNOTATIONEDITING , PDF::PDFViewCtrl::e_annot_edit ),
145 ToolModeMapType( IDM_TOOL_TEXTANNOTCREATION , PDF::PDFViewCtrl::e_text_annot_create ),
146 ToolModeMapType( IDM_TOOL_LINECREATION , PDF::PDFViewCtrl::e_line_create ),
147 ToolModeMapType( IDM_TOOL_ARROWCREATION , PDF::PDFViewCtrl::e_arrow_create ),
148 ToolModeMapType( IDM_TOOL_RECTANGLECREATION , PDF::PDFViewCtrl::e_rect_create ),
149 ToolModeMapType( IDM_TOOL_OVALCREATION , PDF::PDFViewCtrl::e_oval_create ),
150 ToolModeMapType( IDM_TOOL_FREEHANDTOOL , PDF::PDFViewCtrl::e_ink_create ),
151 ToolModeMapType( IDM_TOOL_STAMPCREATIONTOOL , PDF::PDFViewCtrl::e_stamp_create ),
152 ToolModeMapType( ID_TOOL_HIGHLIGHTTOOL , PDF::PDFViewCtrl::e_highlight_create ),
153 ToolModeMapType( ID_TOOL_UNDERLINETOOL , PDF::PDFViewCtrl::e_underline_create ),
154 ToolModeMapType( ID_TOOL_STRIKEOUTTOOL , PDF::PDFViewCtrl::e_strikeout_create ),
155 ToolModeMapType( ID_TOOL_SQUIGGLYUNDERLINETOOL , PDF::PDFViewCtrl::e_squiggly_create ),
156 ToolModeMapType( ID_TOOL_CALLOUTTEXTBOXTOOL , PDF::PDFViewCtrl::e_calloutbox_create ),
157 ToolModeMapType( ID_TOOL_SIMPLETEXTBOXTOOL , PDF::PDFViewCtrl::e_text_box_create ),
158 ToolModeMapType( ID_TOOL_POLYGONTOOL , PDF::PDFViewCtrl::e_polygon_create ),
159 ToolModeMapType( ID_TOOL_POLYLINETOOL , PDF::PDFViewCtrl::e_polyline_create ),
160 ToolModeMapType( ID_TOOL_FILEATTACHMENTTOOL , PDF::PDFViewCtrl::e_file_attachment ),
161 ToolModeMapType( ID_TOOL_SOUNDATTACHMENTTOOL , PDF::PDFViewCtrl::e_sound_attachment ),
162 ToolModeMapType( ID_TOOL_MOVIEINSERTIONTOOL , PDF::PDFViewCtrl::e_movie_attachment ),
163 ToolModeMapType( ID_TOOL_CARETPLACEMENTTOOL , PDF::PDFViewCtrl::e_caret_create ),
164 ToolModeMapType( ID_TOOL_REDACTIONTOOL , PDF::PDFViewCtrl::e_redaction_create ),
165 ToolModeMapType( ID_TOOL_TEXTFIELDCREATION , PDF::PDFViewCtrl::e_text_field_create ),
166 ToolModeMapType( ID_TOOL_CHECKBOXCREATIONTOOL , PDF::PDFViewCtrl::e_check_box_create ),
167 ToolModeMapType( ID_TOOL_RADIOBUTTON , PDF::PDFViewCtrl::e_radio_button_create ),
168 ToolModeMapType( ID_TOOL_LISTBOX , PDF::PDFViewCtrl::e_list_box_create ),
169 ToolModeMapType( ID_TOOL_COMBOBOX , PDF::PDFViewCtrl::e_combo_box_create ),
170 ToolModeMapType( ID_TOOL_BUTTONCREATIONTOOL , PDF::PDFViewCtrl::e_button_create )
171};
172const ToolModeMapType* const toolModeMapEnd = toolModeMap + sizeof(toolModeMap)/sizeof(ToolModeMapType);
173struct ToolModePred {
174 int m_code;
175 ToolModePred( int c ) : m_code(c) {}
176 bool operator()( ToolModeMapType tp ) { return tp.first == m_code; }
177};
178
179
180
181// FUNCTION: InitInstance(HINSTANCE, int)
182//
183// PURPOSE: Saves instance handle and creates main window
184//
185// COMMENTS:
186//
187// In this function, we save the instance handle in a global variable and
188// create and display the main program window.
189//
190BOOL InitInstance(HINSTANCE hInstance, int nCmdShow)
191{
192 PDFNet::Initialize(LicenseKey);
193 // PDFNet::SetColorManagement();
194
195 HWND hWnd;
196 hInst = hInstance; // Store instance handle in our global variable
197
198 hWnd = CreateWindow(szWindowClass, szTitle, WS_OVERLAPPEDWINDOW,
199 CW_USEDEFAULT, 0, CW_USEDEFAULT, 0, NULL, NULL, hInstance, NULL);
200
201
202 if (!hWnd)
203 {
204 return FALSE;
205 }
206
207 ShowWindow(hWnd, nCmdShow);
208
209 // Optional: PDFViewCtrl can save its UI state across different sessions.
210 // In this case the config file is save in the current working folder.
211 //m_view->LoadCurrentConfiguration( "my.cfg" );
212 UpdateWindow(hWnd);
213
214 return TRUE;
215}
216
217void ErrorCallback(const char* message, void* custom_data)
218{
219 static bool reported_once = false;
220 if (!reported_once) {
221 reported_once = true;
222 HWND hwnd = (HWND) custom_data; // Case custom data to the expected argument.
223 ::MessageBoxA(hwnd, message, "Error", MB_OK);
224 }
225}
226
227void DownloadCallback(DownloadedType type, PDFDoc* doc, int page_num, int obj_num, const char* message, void* custom_data)
228{
229 switch(type)
230 {
231 case PDF::e_downloadedtype_opened :
232 // e_opened indicates that we have a valid, but incomplete PDFDoc.
233 // the PDF should be treated as read only, and only simple functions
234 // should be called on the doc, until e_finished has been called.
235 break;
236 case PDF::e_downloadedtype_page :
237 // this indicates the entire page is downloaded and it is safe to modify
238 // for example add a new annotation
239 break;
240 case PDF::e_downloadedtype_finished :
241 {
242 // we now have the full PDF file and it can be treated like any other
243 HWND hwnd = (HWND) custom_data; // Case custom data to the expected argument.
244 if(::MessageBoxA(hwnd, "Download complete, would you like to save the PDF locally?",
245 "PDF Downloaded", MB_YESNO)==IDYES)
246 {
247 ::PostMessage(hwnd, WM_COMMAND, MAKELONG(IDM_FILE_SAVEAS,0), 0);
248 }
249 }
250 break;
251 case PDF::e_downloadedtype_failed :
252 {
253 // downloading has stopped if this occurs
254 HWND hwnd = (HWND) custom_data; // Case custom data to the expected argument.
255 ::MessageBoxA(hwnd, message, "Error", MB_OK);
256 }
257 break;
258 }
259}
260
261TRN_Bool MyActionHandler( TRN_Action act, void* custom_data )
262{
263 Action action(act);
264 if (!action.IsValid()) return 1;
265
266 HWND hwnd = (HWND) custom_data; // Case custom data to the expected argument.
267
268 Action::Type type = action.GetType();
269 if (type == Action::e_GoTo)
270 {
271 Destination dest = action.GetDest();
272 if (!dest.IsValid()) {
273 MessageBoxA(hwnd, "Destination is not valid", "MyURLActionHandler", MB_OK | MB_ICONEXCLAMATION);
274 }
275 else {
276 int page_num = dest.GetPage().GetIndex();
277 char buf[256];
278 sprintf(buf, " Links to: page number %d in this document", page_num);
279 MessageBoxA(hwnd, buf, "MyURLActionHandler", MB_OK | MB_ICONEXCLAMATION);
280 return 0; // -> execute the default action handler.
281 }
282 }
283 else if (type == Action::e_URI)
284 {
285 UString uri;
286 action.GetSDFObj().Get("URI").Value().GetAsPDFText(uri);
287
288 char buf[256];
289 sprintf(buf, " Links to: %s", uri.ConvertToAscii().c_str());
290 MessageBoxA(hwnd, buf, "MyURLActionHandler", MB_OK);
291 }
292 else
293 {
294 MessageBoxA(hwnd, "Other Action Type -> Handled by PDFViewCtrl", "MyURLActionHandler", MB_OK);
295 return 0; // -> execute the default action handler.
296 }
297
298 // If this function returns true, PDFViewCtrl will not execute the default
299 // action internally (in case of URL the default action is to open the URL
300 // link in a web browser).
301 return 1;
302}
303
304TRN_Bool MyMouseDoubleClickEvent( PDFViewCtrl::MouseEvent* evt, void* custom_data)
305{
306 if (!evt->m_pdfviewctrl_processed) // Display the message box before the message is processed by PDFNet?
307 {
308 HWND hwnd = (HWND) custom_data; // Case custom data to the expected argument.
309 MessageBoxA(hwnd, "Example of a custom event", "MyMouseDoubleClickEvent", MB_OK);
310 return false; // execute built-in event. To skip event processing in PDFViewCtrl return true.
311 }
312 return false;
313}
314
315BOOL OpenURLProc(HWND hDlg, UINT iMessage, WPARAM wParam, LPARAM lParam)
316{
317 switch( iMessage ){
318 case WM_COMMAND:
319 switch( LOWORD( wParam ) ){
320 case IDOK :
321 {
322 char url[MAX_PATH];
323 char pass[MAX_PATH];
324 GetDlgItemTextA(hDlg, IDC_OPENURL_URL, url, MAX_PATH);
325 GetDlgItemTextA(hDlg, IDC_OPENURL_PASSWORD, pass, MAX_PATH);
326 m_view->CloseDoc();
327 mp_doc.reset();
328 // Open a PDF file at the given url. This works best with PDF's that
329 // are linearized, as pages can be downloaded and viewed in random access order,
330 // without the need to download the entire document. A viewing session can also be
331 // persisted across multiple viewing/application sessions to remove redundant downloads
332 // and improve overall performance by using the optional cache_file parameter.
333 m_view->OpenURLAsync(&url[0], "", &pass[0]);
334 // IMPORTANT: PDFViewCtrl 'owns' downloaded documents, so don't take
335 // ownership of the document (mp_doc == null)
336 }
337 // fall through
338 case IDCANCEL:
339 EndDialog(hDlg, wParam);
340 return TRUE;
341 }
342 break;
343 }
344 return FALSE;
345}
346
347LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
348{
349 int wmId, wmEvent;
350 PAINTSTRUCT ps;
351 HDC hdc;
352 static HMENU hMenu ;
353
354 switch (message)
355 {
356 case WM_CREATE:
357 {
358 m_view = std::auto_ptr<pdftron::PDF::PDFViewCtrl>(new pdftron::PDF::PDFViewCtrl(hWnd, hInst));
359 hMenu = LoadMenu (hInst, MAKEINTRESOURCE(IDC_PDFVIEWSIMPLE));
360 hMenu = GetSubMenu (hMenu, 0);
361
362 // m_view->SetProgressiveRendering(false);
363 // m_view->SetPageBorderVisibility(false);
364 // m_view->SetPageSpacing(0, 0, 0, 0);
365 // m_view->SetDefaultPageColor(255, 255, 255);
366 // m_view->ShowNavPanel(true);
367 // m_view->ShowNavToolbar(true);
368 // m_view->SetAntiAliasing( true );
369 // m_view->SetGamma(0.01);
370
371 m_view->SetErrorReportHandler(ErrorCallback, hWnd);
372 m_view->SetActionHandler(MyActionHandler, hWnd);
373 m_view->SetDownloadReportHandler(DownloadCallback, hWnd);
374
375 PDFViewCtrl::EventHandlers my_handlers;
376 my_handlers.mouse_left_dclick = MyMouseDoubleClickEvent;
377 my_handlers.custom_data = hWnd;
378 m_view->SetCustomEventHandlers( &my_handlers );
379 }
380 break;
381
382 case WM_COMMAND:
383 {
384 wmId = LOWORD(wParam);
385 wmEvent = HIWORD(wParam);
386
387 const ToolModeMapType* const wmId_it = std::find_if( toolModeMap, toolModeMapEnd, ToolModePred(wmId) );
388 if( wmId_it != toolModeMapEnd )
389 m_view->SetToolMode( wmId_it->second );
390 else {
391
392 switch (wmId)
393 {
394 case IDM_ABOUT:
395 // DialogBox(hInst, MAKEINTRESOURCE(IDD_ABOUTBOX), hWnd, About);
396 break;
397 case IDM_EXIT:
398 DestroyWindow(hWnd);
399 break;
400 case IDM_FILE_PRINT:
401 {
402 if(m_view->GetDoc())
403 m_view->Print();
404 }
405 break;
406 case IDM_FILE_SAVEAS:
407 {
408 if(m_view->GetDoc())
409 {
410 TCHAR szFile[256] = { 0 };
411 TCHAR *szFilter =TEXT("PDF Files (*.pdf)\0")
412 TEXT("*.pdf\0")
413 TEXT("All Files\0")
414 TEXT("*.*\0");
415 OPENFILENAME ofn;
416 ZeroMemory(&ofn, sizeof(OPENFILENAME));
417 ofn.lStructSize=sizeof(OPENFILENAME);
418 ofn.lpstrFilter=szFilter;
419 ofn.nFilterIndex=1;
420 ofn.lpstrFile=szFile;
421 ofn.nMaxFile=sizeof(szFile);
422 ofn.lpstrTitle=_T("Save PDF File");
423 ofn.nMaxFileTitle=sizeof(ofn.lpstrFile);
424 //===Start the File Dialog
425 if(GetSaveFileName(&ofn))
426 {
427 m_view->GetDoc()->Save(UString(ofn.lpstrFile), SDF::SDFDoc::e_linearized, 0);
428 }
429 }
430 }
431 break;
432 case IDM_FILE_SAVE:
433 {
434 if(m_view->GetDoc())
435 {
436 if(m_view->GetDoc())
437 {
438 m_view->GetDoc()->Save(m_doc_name, SDF::SDFDoc::e_remove_unused, 0);
439 }
440 }
441 }
442 break;
443 case IDM_FILE_OPEN:
444 {
445 //===File path
446 TCHAR szFile[256] = { 0 };
447 //===Filter
448 TCHAR *szFilter =TEXT("PDF Files (*.pdf)\0")
449 TEXT("*.pdf\0")
450 TEXT("All Files\0")
451 TEXT("*.*\0");
452 OPENFILENAME ofn;
453 ZeroMemory(&ofn, sizeof(OPENFILENAME));
454 ofn.lStructSize=sizeof(OPENFILENAME);
455 ofn.lpstrFilter=szFilter;
456 ofn.nFilterIndex=1;
457 ofn.lpstrFile=szFile;
458 ofn.nMaxFile=sizeof(szFile);
459 ofn.lpstrTitle=_T("Open PDF File");
460 ofn.nMaxFileTitle=sizeof(ofn.lpstrFile);
461 //===Start the File Dialog
462 if(GetOpenFileName(&ofn))
463 {
464 m_doc_name=UString(ofn.lpstrFile);
465 try{
466 std::auto_ptr<PDF::PDFDoc> doc(new PDF::PDFDoc(m_doc_name));
467 if(m_view->SetDoc(*doc))
468 {
469 mp_doc=doc;
470 // m_view->ShowNavPanel(true);
471 // m_view->ShowNavToolbar(true);
472 }
473 }
474 catch(...)
475 {
476 ::MessageBoxA(hWnd,"An error occurred while opening a file","PDFViewSimple Error",MB_OK);
477 }
478 }
479 }
480 break;
481 case IDM_FILE_OPENURL:
482 {
483 ::DialogBox(hInst, MAKEINTRESOURCE(IDD_OPENURL), hWnd, DLGPROC(OpenURLProc));
484 }
485 break;
486 case IDM_PAGELAYOUT_SINGLEPAGE:
487 {
488 m_view->SetPagePresentationMode(PDF::PDFViewCtrl::e_single_page);
489 }
490 break;
491 case IDM_PAGELAYOUT_SINGLECONTINUOUS:
492 {
493 if(m_view->GetDoc())
494 {
495 m_view->SetPagePresentationMode(PDF::PDFViewCtrl::e_single_continuous);
496 }
497 }
498 break;
499 case IDM_PAGELAYOUT_FACING:
500 {
501 m_view->SetPagePresentationMode(PDF::PDFViewCtrl::e_facing);
502 }
503 break;
504 case IDM_PAGELAYOUT_FACINGCONTINUOUS:
505 {
506 if(m_view->GetDoc())
507 {
508 m_view->SetPagePresentationMode(PDF::PDFViewCtrl::e_facing_continuous);
509 }
510 }
511 break;
512 case IDM_PAGELAYOUT_FACING_COVER:
513 {
514 if(m_view->GetDoc())
515 {
516 m_view->SetPagePresentationMode(PDF::PDFViewCtrl::e_facing_cover);
517 }
518 }
519 break;
520 case IDM_PAGELAYOUT_FACINGCONTINUOUS_COVER:
521 {
522 if(m_view->GetDoc())
523 {
524 m_view->SetPagePresentationMode(PDF::PDFViewCtrl::e_facing_continuous_cover);
525 }
526 }
527 break;
528 case IDM_PAGEVIEWMODE_FITPAGE:
529 {
530 m_view->SetPageViewMode(PDF::PDFViewCtrl::e_fit_page);
531 }
532 break;
533 case IDM_PAGEVIEWMODE_FITWIDTH:
534 {
535 m_view->SetPageViewMode(PDF::PDFViewCtrl::e_fit_width);
536 }
537 break;
538 case IDM_VIEW_ZOOMIN:
539 {
540 if(m_view->GetDoc())
541 {
542 m_view->SetZoom(m_view->GetZoom()*2);
543 }
544 }
545 break;
546 case IDM_VIEW_ZOOMOUT:
547 {
548 if(m_view->GetDoc())
549 {
550 m_view->SetZoom(m_view->GetZoom()/2);
551 }
552 }
553 break;
554 case IDM_PAGENAVIGATION_GOTONEXTPAGE:
555 {
556 if(m_view->GetDoc())
557 {
558 m_view->GotoNextPage();
559 }
560 }
561 break;
562 case IDM_PAGENAVIGATION_GOTOPREVIOUSPAGE:
563 {
564 if(m_view->GetDoc())
565 {
566 m_view->GotoPreviousPage();
567 }
568 }
569 break;
570 case IDM_PAGENAVIGATION_GOT:
571 {
572 if(m_view->GetDoc())
573 {
574 m_view->GotoLastPage();
575 }
576 }
577 break;
578 case IDM_PAGENAVIGATION_GOTOFIRSTPAGE:
579 {
580 if(m_view->GetDoc())
581 {
582 m_view->GotoFirstPage();
583 }
584 }
585 break;
586 case IDM_EDIT_COPY:
587 {
588 if(m_view->GetDoc())
589 {
590 m_view->Copy();
591 }
592 }
593 break;
594 case IDM_EDIT_FIND:
595 {
596 if(m_view->GetDoc())
597 {
598 m_view->Find();
599 }
600 }
601 break;
602 case IDM_EDIT_SELECTALL:
603 {
604 if(m_view->GetDoc())
605 {
606 m_view->SelectAll();
607 }
608 }
609 break;
610 case ID_TOGGLE_NAV_PANEL:
611 m_view->ShowNavPanel(!m_view->IsNavPanelVisible());
612 break;
613 default:
614 return DefWindowProc(hWnd, message, wParam, lParam);
615 }
616 }
617 }
618 break;
619 case WM_PAINT:
620 hdc = BeginPaint(hWnd, &ps);
621 // TODO: Add any drawing code here...
622 EndPaint(hWnd, &ps);
623 break;
624 case WM_CLOSE:
625 //m_view->SaveCurrentConfiguration("my.cfg");
626 m_view.reset();
627 DestroyWindow(hWnd);
628 return 0;
629 case WM_DESTROY:
630 PostQuitMessage(0);
631 return 0;
632 case WM_SIZE:
633 // this is never getting called, wxWidgets handles these events internally
634 break;
635 default:
636 return DefWindowProc(hWnd, message, wParam, lParam);
637 }
638 return 0;
639}
640
641// Message handler for about box.
642INT_PTR CALLBACK About(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam)
643{
644 UNREFERENCED_PARAMETER(lParam);
645 switch (message)
646 {
647 case WM_INITDIALOG:
648 return (INT_PTR)TRUE;
649
650 case WM_COMMAND:
651 if (LOWORD(wParam) == IDOK || LOWORD(wParam) == IDCANCEL)
652 {
653 EndDialog(hDlg, LOWORD(wParam));
654 return (INT_PTR)TRUE;
655 }
656 break;
657 }
658 return (INT_PTR)FALSE;
659}

Did you find this helpful?

Trial setup questions?

Ask experts on Discord

Need other help?

Contact Support

Pricing or product questions?

Contact Sales