Click here to Skip to main content
15,867,330 members
Articles / Programming Languages / C++
Article

The ViewPort Explorer

Rate me:
Please Sign up or sign in to vote.
4.91/5 (22 votes)
11 Jul 20051 min read 55.7K   1.6K   59   4
A viewport explorer utility.

Introduction

This little project came about because I found what I thought was an error in a description of mapping modes. The author insisted the description was correct, so to prove that it was wrong, I wrote a little program that demonstrated what was going on. The result demonstrated that I was correct.

However, the program seemed quite useful, so I enhanced it. It has all sorts of interesting features that might be useful beyond its ability to demonstrate SetWindowOrg, SetWindowExt, SetViewportOrg and SetViewportExt.

The application dialog is shown below. It allows setting the parameters for the four scaling APIs, and options for selecting the mapping mode.

Because changing modes can make the axis indicators move off-screen, the "circles" option provides a "finder" capability (like that found on oscilloscopes) so you can drag the image around.

This demonstrates the use of mapping modes and the use of logical coordinates. It also implements DPtoLP and LPtoDP. In the picture, note that MM_ANISOTROPIC was selected, and both the values for the window extent are negative, thus reversing the normal axis, with x increasing to the left and y increasing upwards.

Image 1

Other cute features include the owner-draw buttons with arrows, mouse capture and dragging, handling the CTRL key during a drag operation, and some cute graphical computation functions.

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here


Written By
Retired
United States United States
PhD, Computer Science, Carnegie Mellon University, 1975
Certificate in Forensic Science and the Law, Duquesne University, 2008

Co-Author, [i]Win32 Programming[/i]

Comments and Discussions

 
QuestionI am very happy to see the source, but i have found four missing code? Pin
Member 33719029-Jul-09 21:27
Member 33719029-Jul-09 21:27 
The source let me learn SetWindowOrg and SetViewPortOrg easily, but i have found the LPtoDP trouble, the max value in DP text box just show '100'? D'Oh! | :doh:
Your code write very good, so i found the missing quickly. Laugh | :laugh: thx!

BOOL CViewportDlg::OnInitDialog()
{
CDialog::OnInitDialog();

// Add "About..." menu item to system menu.

// IDM_ABOUTBOX must be in the system command range.
ASSERT((IDM_ABOUTBOX & 0xFFF0) == IDM_ABOUTBOX);
ASSERT(IDM_ABOUTBOX < 0xF000);

CMenu* pSysMenu = GetSystemMenu(FALSE);
if (pSysMenu != NULL)
{
CString strAboutMenu;
strAboutMenu.LoadString(IDS_ABOUTBOX);
if (!strAboutMenu.IsEmpty())
{
pSysMenu->AppendMenu(MF_SEPARATOR);
pSysMenu->AppendMenu(MF_STRING, IDM_ABOUTBOX, strAboutMenu);
}
}

// Set the icon for this dialog. The framework does this automatically
// when the application's main window is not a dialog
SetIcon(m_hIcon, TRUE); // Set big icon
SetIcon(m_hIcon, FALSE); // Set small icon

// TODO: Add extra initialization here
//****************************************************************
// Intialize SetViewportOrg values
//****************************************************************
c_SpinSetViewportOrgX.SetRange32(-5000, 5000);
c_SpinSetViewportOrgX.SetPos(0);
c_SpinSetViewportOrgY.SetRange32(-5000, 5000);
c_SpinSetViewportOrgY.SetPos(0);

//****************************************************************
// Initialize SetWindowOrg values
//****************************************************************
c_SpinSetWindowOrgX.SetRange32(-5000, 5000);
c_SpinSetWindowOrgX.SetPos32(0);
c_SpinSetWindowOrgY.SetRange32(-5000, 5000);
c_SpinSetWindowOrgY.SetPos32(0);

//****************************************************************
// Initialize the grid parameter controls
//****************************************************************
c_SpinDeviceGrid.SetRange32(1, 5000);
c_SpinDeviceGrid.SetPos32(50);
c_Canvas.SetDeviceGrid(c_SpinDeviceGrid.GetPos32());

c_SpinLogicalGrid.SetRange32(1, 5000);
c_SpinLogicalGrid.SetPos32(50);
c_Canvas.SetLogicalGrid(c_SpinLogicalGrid.GetPos32());

c_SpinPositive.SetRange32(0, 5000);
c_SpinPositive.SetPos32(100);
c_Canvas.SetPositive(c_SpinPositive.GetPos32());

c_GridLines.SetCheck(BST_CHECKED);

//****************************************************************
// Initialize the mapping mode buttons
//****************************************************************
CheckRadioButton(IDC_MM_TEXT, IDC_MM_ANISOTROPIC, IDC_MM_TEXT);
c_Canvas.SetMapMode(MM_TEXT);

//****************************************************************
// Initialize the window and viewport extents
//****************************************************************
SetInitialWindowExt();
SetInitialViewportExt();

//****************************************************************
// Set the line styles
//****************************************************************
CheckRadioButton(IDC_PS_SOLID, IDC_PS_DASHDOTDOT, IDC_PS_DOT);
c_Canvas.SetLineStyle(PS_DOT);

//****************************************************************
// Initialize the LPtoDP and DPtoLP controls
//****************************************************************
//--------------------------------
// Set the button arrow directions
//--------------------------------
c_LPtoDP.SetDirection(DrawArrow::ARROW_S);
c_DPtoLP.SetDirection(DrawArrow::ARROW_N);

//----------------
// LP <> DP
//----------------
c_SpinLogicalX.SetRange32(-5000, 5000);
c_SpinLogicalX.SetPos(0);
c_SpinLogicalY.SetRange32(-5000, 5000);
c_SpinLogicalY.SetPos(0);

<big>    //add 2009.07.10
    c_SpinPhysicalX.SetRange32(-5000, 5000);
    c_SpinPhysicalX.SetPos(0);
    c_SpinPhysicalY.SetRange32(-5000, 5000);
    c_SpinPhysicalY.SetPos(0);</big>


//****************************************************************
// Initialization is complete
//****************************************************************
initialized = TRUE;

OnLptodp(); // Must happen after Initialized is set TRUE

OnGridLines(); // Must happen after initialized is set TRUE

updateControls();

return TRUE; // return TRUE unless you set the focus to a control
}
GeneralVery helpful Pin
caram8823-Dec-08 13:25
caram8823-Dec-08 13:25 
GeneralText considerations Pin
prcarp11-Jul-05 3:09
prcarp11-Jul-05 3:09 
GeneralRe: Text considerations Pin
Joseph M. Newcomer11-Jul-05 14:47
Joseph M. Newcomer11-Jul-05 14:47 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.