Click here to Skip to main content
15,898,826 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
GeneralRe: CFtpConnection ???? Pin
racing5715-Aug-06 4:14
racing5715-Aug-06 4:14 
QuestionWriting different language into VC6 Pin
Stan the man3-Aug-06 5:20
Stan the man3-Aug-06 5:20 
AnswerRe: Writing different language into VC6 Pin
Ștefan-Mihai MOGA3-Aug-06 14:00
professionalȘtefan-Mihai MOGA3-Aug-06 14:00 
QuestionKeeping an MDI file locked with CFile::shareExclusive Pin
bob169723-Aug-06 4:50
bob169723-Aug-06 4:50 
AnswerRe: Keeping an MDI file locked with CFile::shareExclusive Pin
Viorel.3-Aug-06 5:13
Viorel.3-Aug-06 5:13 
GeneralRe: Keeping an MDI file locked with CFile::shareExclusive Pin
bob169723-Aug-06 5:47
bob169723-Aug-06 5:47 
Questionneed good idea of print-preview Pin
includeh103-Aug-06 4:42
includeh103-Aug-06 4:42 
AnswerRe: need good idea of print-preview Pin
bob169723-Aug-06 4:59
bob169723-Aug-06 4:59 
Disclaimer: This is not exactly what your asking for but it provides a generic skeleton for your OnDraw stuff so that the view, print, and print preview size themselves dynamically in a fit to width fashion. It uses an arbitrary world space to draw in.

Here's a little to get you started. Start a new MFC/SDI app (CScrollView) and plop this stuff in the appropriate locations. Set up menu/toolbar buttons for the zoomin/zoomout. Add some drawing code to your OnDraw and you should find that the drawing is fit_to_width in the view and it should be fit to width when printing and print preview. The rest is up to you. have fun...
(Let me know if I missed something)

///////////////////////////////////////////////

//Constants
const int MAX_SCALE = 20; // The maximum scale factor

//CDocument members...

protected:
CSize m_DocSize;

CSize CYourDoc::GetDocSize() const
{
return m_DocSize;
}

CYourDoc::CYourDoc()
{
// TODO: add one-time construction code here
m_DocSize=CSize(2000,2800);
}

//CScrollView members...

protected:
int m_Scale;

CYourView::CYourView()
{
// TODO: add construction code here

m_Scale=1; // Set scale factor 1:1
SetScrollSizes(MM_TEXT,CSize(0,0)); // Set arbitrary values
}

void CYourView::OnPrepareDC(CDC* pDC, CPrintInfo* pInfo)
{
CScrollView::OnPrepareDC(pDC);

// TODO: Add your specialized code here and/or call the base class

// Set up the DC for the current scale factor
int nExtentX;
int nExtentY;
CSize sizeDoc;
CRect rectClient;

// Allows the rectangle to include the bottom and rightmost logical unit
// SetGraphicsMode(pDC->m_hDC,GM_ADVANCED);

pDC->SetMapMode(MM_ISOTROPIC); // Allow scaling with aspect ratio preserved

// Get pertinent rectangle data
GetClientRect(&rectClient);
sizeDoc=GetDocument()->GetDocSize();

sizeDoc.cy=(-sizeDoc.cy); // Y goes down as it increments
pDC->SetWindowExt(sizeDoc); // Window extent is size of document

// Calculate viewport extent
nExtentX=(int)(GetScale()*rectClient.Width());
nExtentY=(int)((GetScale()*((nExtentX*sizeDoc.cy)/(sizeDoc.cx))));

// What kind of device context do we have?
if (pDC->IsPrinting()==TRUE) {
// Printer Context. Allow printing to edge of context. No scaling. Margins?
pDC->SetViewportExt(pDC->GetDeviceCaps(HORZRES),-pDC->GetDeviceCaps(VERTRES));
} else {
// Context is for screen
pDC->SetViewportExt(nExtentX,nExtentY);
}
}

int CYourView::GetScale()
{
return m_Scale;
}

void CYourView::SetScale(int nScaleFactor)
{
m_Scale=nScaleFactor;
ResetScrollBars(); // Adjust scrollbars to new scale
}

void CYourView::OnUpdateViewZoomout(CCmdUI* pCmdUI)
{
// TODO: Add your command update UI handler code here
if (GetScale()>=2) pCmdUI->Enable(TRUE);
else pCmdUI->Enable(FALSE);
}

void CYourView::OnUpdateViewZoomin(CCmdUI* pCmdUI)
{
// TODO: Add your command update UI handler code here
if (GetScale()<MAX_SCALE) pCmdUI->Enable(TRUE);
else pCmdUI->Enable(FALSE);
}

void CYourView::ResetScrollBars()
{
CSize sizeDoc;
CClientDC dc(this);

this->OnPrepareDC(&dc); // Update the device context

sizeDoc=GetDocument()->GetDocSize();
dc.LPtoDP(&sizeDoc); // Logical to device

this->SetScrollSizes(MM_TEXT,sizeDoc); // Update scrollbars
}

void CYourView::OnInitialUpdate()
{
CScrollView::OnInitialUpdate();

// TODO: calculate the total size of this view
ResetScrollBars();
}

void CYourView::OnSize(UINT nType, int cx, int cy)
{
CScrollView::OnSize(nType, cx, cy);

// TODO: Add your message handler code here
ResetScrollBars();
}

// Toolbar/menu button handler
void CYourView::OnViewZoomin()
{
// TODO: Add your command handler code here
if (GetScale()<MAX_SCALE) SetScale(GetScale()+1);

Invalidate();
}

// Toolbar/menu button handler
void CYourView::OnViewZoomout()
{
// TODO: Add your command handler code here
if (GetScale()>=2) SetScale(GetScale()-1);

Invalidate();
}
GeneralRe: need good idea of print-preview Pin
includeh103-Aug-06 8:14
includeh103-Aug-06 8:14 
AnswerRe: need good idea of print-preview Pin
Hamid_RT4-Aug-06 7:02
Hamid_RT4-Aug-06 7:02 
QuestionWinsock - Multicasting with CCESocket [modified] Pin
king minger3-Aug-06 4:27
king minger3-Aug-06 4:27 
NewsRe: Winsock - Multicasting with CCESocket [modified] Pin
king minger3-Aug-06 5:08
king minger3-Aug-06 5:08 
AnswerRe: Winsock - Multicasting with CCESocket Pin
king minger4-Aug-06 1:26
king minger4-Aug-06 1:26 
QuestionDeclaring Array Variable for a Class [modified] Pin
Andy Rama3-Aug-06 4:16
Andy Rama3-Aug-06 4:16 
AnswerRe: Declaring Array Variable for a Class Pin
David Crow3-Aug-06 4:22
David Crow3-Aug-06 4:22 
GeneralRe: Declaring Array Variable for a Class Pin
Andy Rama3-Aug-06 8:43
Andy Rama3-Aug-06 8:43 
QuestionRe: Declaring Array Variable for a Class Pin
David Crow4-Aug-06 2:32
David Crow4-Aug-06 2:32 
QuestionRe: Declaring Array Variable for a Class Pin
Andy Rama4-Aug-06 2:51
Andy Rama4-Aug-06 2:51 
AnswerRe: Declaring Array Variable for a Class Pin
David Crow4-Aug-06 2:59
David Crow4-Aug-06 2:59 
AnswerRe: Declaring Array Variable for a Class Pin
Zac Howland3-Aug-06 5:01
Zac Howland3-Aug-06 5:01 
GeneralRe: Declaring Array Variable for a Class Pin
Andy Rama3-Aug-06 19:31
Andy Rama3-Aug-06 19:31 
GeneralRe: Declaring Array Variable for a Class Pin
Zac Howland4-Aug-06 3:18
Zac Howland4-Aug-06 3:18 
GeneralRe: Declaring Array Variable for a Class Pin
Andy Rama4-Aug-06 8:01
Andy Rama4-Aug-06 8:01 
GeneralRe: Declaring Array Variable for a Class Pin
Zac Howland4-Aug-06 8:22
Zac Howland4-Aug-06 8:22 
Questionwhat does 0.1 inch mean? Pin
includeh103-Aug-06 4:07
includeh103-Aug-06 4:07 

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.