예제 #1
0
void CFileView::OnFileNew()
{
	CMultiDocTemplate* pUIDocTemplate = theApp.GetUIDocTemplate();
	CDocument* pDoc = pUIDocTemplate->OpenDocumentFile(NULL);
	CString strFilePath = CGlobalVariable::m_strProjectPath + pDoc->GetTitle() + _T(".xml");
	pDoc->DoSave(strFilePath);
	HTREEITEM hSelectedItem = m_wndFileView.GetSelectedItem();
	DWORD dwInfo = m_wndFileView.GetItemData(hSelectedItem);
	HTREEITEM hParent = (dwInfo != INFO_FILE) ? hSelectedItem : m_wndFileView.GetParentItem(hSelectedItem);
	HTREEITEM hNewItem = m_wndFileView.InsertItem(pDoc->GetTitle(), 2, 2, hParent);
	m_wndFileView.SetItemData(hNewItem, INFO_FILE);
	m_wndFileView.Expand(hParent, TVE_EXPAND);
}
예제 #2
0
파일: winmdi.cpp 프로젝트: AeonAxan/mpc-hc
void CMDIFrameWnd::OnUpdateFrameTitle(BOOL bAddToTitle)
{
	if ((GetStyle() & FWS_ADDTOTITLE) == 0)
		return;     // leave it alone!

#ifndef _AFX_NO_OLE_SUPPORT
	// allow hook to set the title (used for OLE support)
	if (m_pNotifyHook != NULL && m_pNotifyHook->OnUpdateFrameTitle())
		return;
#endif

	CMDIChildWnd* pActiveChild = NULL;
	CDocument* pDocument = GetActiveDocument();
	if (bAddToTitle &&
	  (pActiveChild = MDIGetActive()) != NULL &&
	  (pActiveChild->GetStyle() & WS_MAXIMIZE) == 0 &&
	  (pDocument != NULL ||
	   (pDocument = pActiveChild->GetActiveDocument()) != NULL))
		UpdateFrameTitleForDocument(pDocument->GetTitle());
	else
	{
		LPCTSTR lpstrTitle = NULL;
		CString strTitle;

		if (pActiveChild != NULL &&
			(pActiveChild->GetStyle() & WS_MAXIMIZE) == 0)
		{
			strTitle = pActiveChild->GetTitle();
			if (!strTitle.IsEmpty())
				lpstrTitle = strTitle;
		}
		UpdateFrameTitleForDocument(lpstrTitle);
	}
}
예제 #3
0
bool CMainFrame::MakeWave(const WAVEGEN_PARMS& Parms)
{
	POSITION	pos = theApp.GetFirstDocTemplatePosition();
	CDocTemplate	*pTpl = theApp.GetNextDocTemplate(pos);
	CWaveShopDoc	*pDoc = DYNAMIC_DOWNCAST(CWaveShopDoc, pTpl->CreateNewDocument());
	if (pDoc == NULL)
		return(FALSE);
	bool	retc, canceled;
	{
		CProgressDlg	ProgDlg;
		if (!ProgDlg.Create())	// create progress dialog
			AfxThrowResourceException();
		ProgDlg.SetWindowText(LDS(IDS_MAIN_GENERATING_AUDIO));
		retc = CWaveGenDlg::MakeWave(Parms, pDoc->m_Wave, &ProgDlg);
		canceled = ProgDlg.Canceled();
	}	// destroy progress dialog
	if (!retc) {	// if generation failed
		if (!canceled)	// if user canceled
			AfxMessageBox(IDS_MAIN_CANT_MAKE_WAVE);
		return(FALSE);
	}
	CDocument	*pEmptyDoc = pTpl->OpenDocumentFile(NULL);	// create new view
	if (pEmptyDoc == NULL || m_View == NULL)
		return(FALSE);
	CString	title = pEmptyDoc->GetTitle();
	pEmptyDoc->RemoveView(m_View);	// remove empty document from view
	pDoc->SetTitle(title);	// copy empty document's title to generated document
	pDoc->AddView(m_View);	// add generated document to view
	m_View->OnInitialUpdate();
	OnActivateView(m_View);
	// view is still linked to empty document's undo manager; must relink
	m_View->SetUndoManager(&pDoc->m_UndoMgr);	// link view to undo manager
	pDoc->m_UndoMgr.SetRoot(m_View);	// link undo manager to view
	return(TRUE);
}
예제 #4
0
파일: MainFrm.cpp 프로젝트: ddcatgg/duilib
LRESULT CMainFrame::OnGetTabToolTip(WPARAM /*wp*/, LPARAM lp)
{
	CMFCTabToolTipInfo* pInfo = (CMFCTabToolTipInfo*) lp;
	ASSERT(pInfo != NULL);
	if (!pInfo)
	{
		return 0;
	}

	ASSERT_VALID(pInfo->m_pTabWnd);

	if (!pInfo->m_pTabWnd->IsMDITab())
	{
		return 0;
	}

	CFrameWnd* pFrame = DYNAMIC_DOWNCAST(CFrameWnd, pInfo->m_pTabWnd->GetTabWnd(pInfo->m_nTabIndex));
	if (pFrame == NULL)
	{
		return 0;
	}

	CDocument* pDoc = pFrame->GetActiveDocument();
	if (pDoc == NULL)
	{
		return 0;
	}

	pInfo->m_strText = pDoc->GetPathName();
	if(pInfo->m_strText.IsEmpty())
		pInfo->m_strText=pDoc->GetTitle();

	return 0;
}
예제 #5
0
파일: Childfrm.cpp 프로젝트: aidush/openmpt
void CChildFrame::OnUpdateFrameTitle(BOOL bAddToTitle)
//----------------------------------------------------
{
    // update our parent window first
    GetMDIFrame()->OnUpdateFrameTitle(bAddToTitle);

    if ((GetStyle() & FWS_ADDTOTITLE) == 0) {
        return;     // leave child window alone!
    }

    CDocument* pDocument = GetActiveDocument();
    if (bAddToTitle) {
        TCHAR szText[256+_MAX_PATH];
        if (pDocument == NULL) {
            lstrcpy(szText, m_strTitle);
        } else {
            lstrcpy(szText, pDocument->GetTitle());
            if (pDocument->IsModified()) lstrcat(szText, "*");
        }
        if (m_nWindow > 0) {
            wsprintf(szText + lstrlen(szText), _T(":%d"), m_nWindow);
        }

        // set title if changed, but don't remove completely
        AfxSetWindowText(m_hWnd, szText);
    }
}
예제 #6
0
파일: winmdi.cpp 프로젝트: AeonAxan/mpc-hc
void CMDIChildWnd::OnUpdateFrameTitle(BOOL bAddToTitle)
{
	// update our parent window first
	GetMDIFrame()->OnUpdateFrameTitle(bAddToTitle);

	if ((GetStyle() & FWS_ADDTOTITLE) == 0)
		return;     // leave child window alone!

	CDocument* pDocument = GetActiveDocument();
	if (bAddToTitle)
	{
		TCHAR szText[256+_MAX_PATH];
		if (pDocument == NULL)
			Checked::tcsncpy_s(szText, _countof(szText), m_strTitle, _TRUNCATE);
		else
			Checked::tcsncpy_s(szText, _countof(szText), pDocument->GetTitle(), _TRUNCATE);
		if (m_nWindow > 0)
		{
			TCHAR szWinNumber[16+1];
			_stprintf_s(szWinNumber, _countof(szWinNumber), _T(":%d"), m_nWindow);
			
			if( lstrlen(szText) + lstrlen(szWinNumber) < _countof(szText) )
			{
				Checked::tcscat_s( szText, _countof(szText), szWinNumber ); 
			}
		}

		// set title if changed, but don't remove completely
		AfxSetWindowText(m_hWnd, szText);
	}
}
예제 #7
0
void CMDIChildWnd::OnUpdateFrameTitle( BOOL bAddToTitle )
/*******************************************************/
{
    UNUSED_ALWAYS( bAddToTitle );

    CDocument *pDoc = GetActiveDocument();
    if( pDoc != NULL ) {
        if( m_nWindow == 0 ) {
            ::SetWindowText( m_hWnd, pDoc->GetTitle() );
        } else {
            TCHAR szTitleBarText[256];
            _sntprintf( szTitleBarText, 255, _T("%s : %d"),
                        (LPCTSTR)pDoc->GetTitle(), m_nWindow );
            ::SetWindowText( m_hWnd, szTitleBarText );
        }
    } else {
        ::SetWindowText( m_hWnd, NULL );
    }
}
예제 #8
0
// @pymethod string|PyCDocument|GetTitle|Returns the title of the current document.
// This will often be the file name portion of the path name.
PyObject *
ui_doc_get_title(PyObject *self, PyObject *args)
{
	CDocument *pDoc;
	if (!(pDoc=PyCDocument::GetDoc(self)))
		return NULL;
	CHECK_NO_ARGS2(args,GetTitle);
	GUI_BGN_SAVE;
	CString path = pDoc->GetTitle(); // @pyseemfc CDocument|GetTitle
	GUI_END_SAVE;
	return PyWinObject_FromTCHAR(path);
}
예제 #9
0
void OleDocRoot::SetTitle(LPCTSTR lpszTitle)
  {
  CString s(lpszTitle);
  CDocTemplate* pTempl = GetDocTemplate();
  if (pTempl)
    {
    flag Found = True;
    while (Found)
      {
      Found = False;
      POSITION Pos = pTempl->GetFirstDocPosition();
      while (Pos && !Found)
        {
        CDocument * pDoc = pTempl->GetNextDoc(Pos);
        if (pDoc!=this)
          {
          CString Title = pDoc->GetTitle();
          if (Title.GetLength()==s.GetLength() && _stricmp((const char*)s, (const char*)Title)==0)
            Found = True;
          }
        }
      if (Found)
        {
        CString Ext = "";
        int DotPos = s.ReverseFind('.');
        if (DotPos>=0)
          {
          Ext = s.Mid(DotPos, 256);
          s = s.Left(DotPos);
          }
        int _Pos = s.ReverseFind('_');
        if (_Pos>=0)
          {
          CString ss = s.Mid(_Pos+1, 256);
          s = s.Left(_Pos+1);
          if (ss.GetLength()>0)
            {
            char Buff[32];
            sprintf(Buff, "%d", atoi((const char*)ss) + 1);
            s += Buff;
            }
          else
            s += "1";
          }
        else
          s += "_1";
        s += Ext;
        }
      }
    }
  COleLinkingDoc::SetTitle((const char*)s);
  }
예제 #10
0
CString CXTPMDIWndTab::GetChildWndText(HWND hWnd) const
{
	// Check to see if the user has defined a label for the tab first.
	CString strTitle;
	if (m_mapTabLabels.Lookup(hWnd, strTitle))
	{
		return strTitle;
	}

	// Get a pointer to the frame window.
	CMDIChildWnd* pChildFrame = (CMDIChildWnd*)CWnd::FromHandle(hWnd);
	if (!::IsWindow(pChildFrame->GetSafeHwnd()))
	{
		return _T("");
	}

	// Get the window text for the frame and use it for the tab label.
	pChildFrame->GetWindowText(strTitle);

	// If the string is empty the document's title.
	if (strTitle.IsEmpty())
	{
		CWnd* pChildWnd = pChildFrame->GetWindow(GW_CHILD);
		while (pChildWnd)
		{
			if (pChildWnd->IsKindOf(RUNTIME_CLASS(CView)))
			{
				// Get a pointer to the view's document.
				CDocument* pDoc = ((CView*)pChildWnd)->GetDocument();
				if (pDoc == NULL)
				{
					return _T("");
				}

				// Set the return string value
				strTitle = pDoc->GetTitle();

				// Reset the frames title
				pChildFrame->SetWindowText(strTitle);

				// Return the document title.
				return strTitle;
			}
			pChildWnd = pChildWnd->GetWindow(GW_HWNDNEXT);
		}
	}

	// Return the MDI frame window's title.
	return strTitle;
}
예제 #11
0
void CFrameWnd::OnUpdateFrameTitle( BOOL bAddToTitle )
/****************************************************/
{
    if( bAddToTitle ) {
        CDocument *pDoc = GetActiveDocument();
        if( pDoc != NULL ) {
            UpdateFrameTitleForDocument( pDoc->GetTitle() );
        } else {
            UpdateFrameTitleForDocument( NULL );
        }
    } else {
        UpdateFrameTitleForDocument( NULL );
    }
}
예제 #12
0
BOOL CBackStagePageInfo::OnInitDialog() 
{
	LFDialog::OnInitDialog();

	LFStaticLayout* pLayout = (LFStaticLayout*)GetLayout();
	ASSERT_VALID(pLayout);
	
	pLayout->AddAnchor(IDC_PATH_LABEL, LFStaticLayout::e_MoveTypeNone, LFStaticLayout::e_SizeTypeHorz);
	
	pLayout->AddAnchor(IDC_SEPARATOR_1, LFStaticLayout::e_MoveTypeNone, LFStaticLayout::e_SizeTypeHorz);
	pLayout->AddAnchor(IDC_TEXT1, LFStaticLayout::e_MoveTypeNone, LFStaticLayout::e_SizeTypeHorz);
	
	pLayout->AddAnchor(IDC_SEPARATOR_2, LFStaticLayout::e_MoveTypeNone, LFStaticLayout::e_SizeTypeHorz);
	pLayout->AddAnchor(IDC_TEXT2, LFStaticLayout::e_MoveTypeNone, LFStaticLayout::e_SizeTypeHorz);
	
	pLayout->AddAnchor(IDC_SEPARATOR_3, LFStaticLayout::e_MoveTypeNone, LFStaticLayout::e_SizeTypeHorz);
	pLayout->AddAnchor(IDC_TEXT3, LFStaticLayout::e_MoveTypeNone, LFStaticLayout::e_SizeTypeHorz);
	
	pLayout->AddAnchor(IDC_SEPARATOR_4, LFStaticLayout::e_MoveTypeHorz, LFStaticLayout::e_SizeTypeVert);
	
	pLayout->AddAnchor(IDC_INFO_LABEL, LFStaticLayout::e_MoveTypeHorz, LFStaticLayout::e_SizeTypeNone);
	pLayout->AddAnchor(IDC_SEPARATOR_5, LFStaticLayout::e_MoveTypeHorz, LFStaticLayout::e_SizeTypeNone);
	pLayout->AddAnchor(IDC_PREVIEW, LFStaticLayout::e_MoveTypeHorz, LFStaticLayout::e_SizeTypeNone);
	pLayout->AddAnchor(IDC_TEXT4, LFStaticLayout::e_MoveTypeHorz, LFStaticLayout::e_SizeTypeNone);

	CFrameWnd* pMainFrame = (CFrameWnd*)AfxGetMainWnd();
	
	CFrameWnd* pFrame = pMainFrame->GetActiveFrame();
	if (pFrame != NULL)
	{
		CDocument* pDoc = pFrame->GetActiveDocument();
		if (pDoc != NULL)
		{
			m_strDocName = pDoc->GetTitle();
			m_strPath = pDoc->GetPathName();
		}
	}

	PreparePreviewBitmap();

	return TRUE;  // return TRUE unless you set the focus to a control
	              // EXCEPTION: OCX Property Pages should return FALSE
}
예제 #13
0
void CChildFrame::OnUpdateFrameTitle(BOOL bAddToTitle)
{
	GetMDIFrame()->OnUpdateFrameTitle(bAddToTitle);

	if ( (GetStyle() & FWS_ADDTOTITLE) == 0) return;

	if (bAddToTitle)
	{
		CDocument* pDoc = GetActiveDocument();
		CString csText;
		if (pDoc == NULL) csText = m_strTitle;
		else {
			csText = pDoc->GetTitle();
		}

		if (m_nWindow > 0) csText.Format(_T("%s: %d"), csText, m_nWindow);
		if (pDoc->IsModified()) csText += " *";

		AfxSetWindowText(m_hWnd, csText);
	}
}
예제 #14
0
void CExtMdiWindowsListDlg::_FillMDIWindowList()
{
	m_ListWindows.SetRedraw(FALSE);
	m_ListWindows.ResetContent();
	
	CMDIChildWnd* pActiveChild = (CMDIChildWnd*)m_pMDIFrameWnd->MDIGetActive();
	if (pActiveChild != NULL) 
	{
		CMDIChildWnd* pChildFrame = (CMDIChildWnd*)pActiveChild->GetWindow(GW_HWNDLAST);
		while (pChildFrame != NULL) 
		{
			HWND hChildFrame = pChildFrame->GetSafeHwnd();
			CString strWindowText;
			pChildFrame->GetWindowText( strWindowText );
			if( strWindowText.IsEmpty() )
			{
				CWnd* pMDIChildWnd = pChildFrame->GetWindow(GW_CHILD);
				while( pMDIChildWnd )
				{
					if( pMDIChildWnd->IsKindOf(RUNTIME_CLASS(CView)) ) 
					{
						CDocument* pDocument = ((CView*)pMDIChildWnd)->GetDocument();
						if (pDocument == NULL)
							strWindowText = _T("");
						strWindowText = pDocument->GetTitle();
						pChildFrame->SetWindowText( strWindowText );
					} // if( pMDIChildWnd->IsKindOf(RUNTIME_CLASS(CView)) ) 
					pMDIChildWnd = pMDIChildWnd->GetWindow(GW_HWNDNEXT);
				} // while( pMDIChildWnd )
			} // if( strWindowText.IsEmpty() )
			int iIndex = m_ListWindows.AddString(strWindowText);
			m_ListWindows.SetItemData(iIndex, (DWORD)hChildFrame);
			
			pChildFrame = (CMDIChildWnd*)pChildFrame->GetWindow(GW_HWNDPREV);
		} // while (pChildFrame != NULL) 
	} // if (pActiveChild != NULL) 

	m_ListWindows.SetRedraw(TRUE);
}
예제 #15
0
void CMainFrame::OnViewPrediction()
{
	// TODO: Add your command handler code here
	CDocument* pDoc;
	CView* pView;
	CCreateContext context;
	CRect rect;
	pView=(CView*)m_splitter.GetPane(0,0);
	pView->GetWindowRect(rect);
	if(!pView)
	{
		AfxMessageBox("Unexpected error occurs");
		return;
	}
	pDoc=pView->GetDocument();
	CString title=pDoc->GetTitle();
	if(!pDoc)
	{
		AfxMessageBox("Unexpected error occurs");
		return;
	}
	pDoc->m_bAutoDelete=false;
	m_splitter.GetPane(0,0)->DestroyWindow();
	pDoc->m_bAutoDelete=true;
	context.m_pNewViewClass=RUNTIME_CLASS(CPredView);
	context.m_pCurrentDoc=pDoc;
	context.m_pLastView=NULL;
	context.m_pNewDocTemplate=NULL;
	context.m_pCurrentFrame=NULL;
	m_splitter.CreateView(0,0,RUNTIME_CLASS(CPredView),CSize(rect.Width(),rect.Height()),&context);
	((CView*)m_splitter.GetPane(0,0))->OnInitialUpdate();// it is important to call initial update before create a view expecially a CScrollView
	m_splitter.RecalcLayout();
	m_splitter.GetPane(0,0)->SendMessage(WM_PAINT);
	SetActiveView((CScrollView*)m_splitter.GetPane(0,0));
	pDoc->SetTitle(title);
	((CFCCDoc*)pDoc)->MessageCenter(IDS_MESSAGE_MAKEPREDICTION);
	

}
예제 #16
0
// Returns the name of the currently opened file, including extension (if saved).
CString CTemplateFormater::GetFile(void)
{
	// Use the generic view class to make this class as portable as possible
	CView* pView = NULL;

	CMDIFrameWnd* pFrame = reinterpret_cast<CMDIFrameWnd*>(AfxGetApp()->m_pMainWnd);
	
	// Get the active MDI child window.
	CMDIChildWnd* pChild = 
		reinterpret_cast<CMDIChildWnd*>(pFrame->GetActiveFrame());		
	// or CMDIChildWnd *pChild = pFrame->MDIGetActive();
	
	// Get the active view attached to the active MDI child window.
	pView = reinterpret_cast<CView*>(pChild->GetActiveView());		

	ASSERT(pView != NULL);
	// If at this point the view could not be obtained, the leave
	if (pView != NULL)
	{
		CDocument* pDoc = pView->GetDocument();
		ASSERT(pDoc != NULL);
		if (pDoc != NULL)
		{
			CString strPathName = pDoc->GetPathName(); 

			if (!strPathName.IsEmpty())
			{
				CCFileSpec fs(strPathName);	//NOTE: This part is not portable!
				return fs.GetFileName();
			}
			else
			{
				return pDoc->GetTitle();
			}
		}
	}

	return _T("");
};
예제 #17
0
void DocRoot::SetTitle(LPCTSTR lpszTitle)
  {
  CString s(lpszTitle);
  CDocTemplate* pTempl = GetDocTemplate();
  if (pTempl)
    {
    CString se;
    pTempl->GetDocString(se, CDocTemplate::filterExt);
    bool Grf = (se==".scg");
    int No = 5;
    flag Found = True;
    while (Found)
      {
      Found = False;
      POSITION Pos = pTempl->GetFirstDocPosition();
      while (Pos && !Found)
        {
        CDocument* pDoc = pTempl->GetNextDoc(Pos);
        if (pDoc!=this)
          {
          CString Title = pDoc->GetTitle();
          if (Title.GetLength()==s.GetLength() && _stricmp((const char*)s, (const char*)Title)==0)
            Found = True;
          }
        }
      if (Found)
        {
        CString Ext = "";
        int DotPos = s.ReverseFind('.');
        if (DotPos>=0)
          {
          Ext = s.Mid(DotPos, 256);
          s = s.Left(DotPos);
          }
        if (Grf)
          {
          s.Format("%02d%s", No, "_Flowsheet");
          No += 5;
          }
        else
          {
          int _Pos = s.ReverseFind('_');
          if (_Pos>=0)
            {
            CString ss = s.Mid(_Pos+1, 256);
            s = s.Left(_Pos+1);
            if (ss.GetLength()>0)
              {
              char Buff[32];
              sprintf(Buff, "%d", atoi((const char*)ss) + 1);
              s += Buff;
              }
            else
              s += "1";
            }
          else
            s += "_1";
          }
        s += Ext;
        }
      }
    }
  CDocument::SetTitle((const char*)s);
  }
예제 #18
0
void CView::OnFilePrint()
{
	// get default print info
	CPrintInfo printInfo;
	ASSERT(printInfo.m_pPD != NULL);    // must be set

	if (LOWORD(GetCurrentMessage()->wParam) == ID_FILE_PRINT_DIRECT)
	{
		CCommandLineInfo* pCmdInfo = AfxGetApp()->m_pCmdInfo;

		if (pCmdInfo != NULL)
		{
			if (pCmdInfo->m_nShellCommand == CCommandLineInfo::FilePrintTo)
			{
				printInfo.m_pPD->m_pd.hDC = ::CreateDC(pCmdInfo->m_strDriverName,
					pCmdInfo->m_strPrinterName, pCmdInfo->m_strPortName, NULL);
				if (printInfo.m_pPD->m_pd.hDC == NULL)
				{
					AfxMessageBox(AFX_IDP_FAILED_TO_START_PRINT);
					return;
				}
			}
		}

		printInfo.m_bDirect = TRUE;
	}

	if (OnPreparePrinting(&printInfo))
	{
		// hDC must be set (did you remember to call DoPreparePrinting?)
		ASSERT(printInfo.m_pPD->m_pd.hDC != NULL);

		// gather file to print to if print-to-file selected
		CString strOutput;
		if (printInfo.m_pPD->m_pd.Flags & PD_PRINTTOFILE && !printInfo.m_bDocObject)
		{
			// construct CFileDialog for browsing
			CString strDef(MAKEINTRESOURCE(AFX_IDS_PRINTDEFAULTEXT));
			CString strPrintDef(MAKEINTRESOURCE(AFX_IDS_PRINTDEFAULT));
			CString strFilter(MAKEINTRESOURCE(AFX_IDS_PRINTFILTER));
			CString strCaption(MAKEINTRESOURCE(AFX_IDS_PRINTCAPTION));
			CFileDialog dlg(FALSE, strDef, strPrintDef,
				OFN_HIDEREADONLY|OFN_OVERWRITEPROMPT, strFilter, NULL, 0);
			dlg.m_ofn.lpstrTitle = strCaption;

			if (dlg.DoModal() != IDOK)
				return;

			// set output device to resulting path name
			strOutput = dlg.GetPathName();
		}

		// set up document info and start the document printing process
		CString strTitle;
		CDocument* pDoc = GetDocument();
		if (pDoc != NULL)
			strTitle = pDoc->GetTitle();
		else
			EnsureParentFrame()->GetWindowText(strTitle);
		DOCINFO docInfo;
		memset(&docInfo, 0, sizeof(DOCINFO));
		docInfo.cbSize = sizeof(DOCINFO);
		docInfo.lpszDocName = strTitle;
		CString strPortName;
		if (strOutput.IsEmpty())
		{
			docInfo.lpszOutput = NULL;
			strPortName = printInfo.m_pPD->GetPortName();
		}
		else
		{
			docInfo.lpszOutput = strOutput;
			AfxGetFileTitle(strOutput,
				strPortName.GetBuffer(_MAX_PATH), _MAX_PATH);
		}

		// setup the printing DC
		CDC dcPrint;
		if (!printInfo.m_bDocObject)
		{
			dcPrint.Attach(printInfo.m_pPD->m_pd.hDC);  // attach printer dc
			dcPrint.m_bPrinting = TRUE;
		}
		OnBeginPrinting(&dcPrint, &printInfo);

		if (!printInfo.m_bDocObject)
			dcPrint.SetAbortProc(_AfxAbortProc);

		// disable main window while printing & init printing status dialog
		// Store the Handle of the Window in a temp so that it can be enabled 
		// once the printing is finished
		CWnd * hwndTemp = AfxGetMainWnd();
		hwndTemp->EnableWindow(FALSE);
		CPrintingDialog dlgPrintStatus(this);

		CString strTemp;
		dlgPrintStatus.SetDlgItemText(AFX_IDC_PRINT_DOCNAME, strTitle);
		dlgPrintStatus.SetDlgItemText(AFX_IDC_PRINT_PRINTERNAME,
			printInfo.m_pPD->GetDeviceName());
		dlgPrintStatus.SetDlgItemText(AFX_IDC_PRINT_PORTNAME, strPortName);
		dlgPrintStatus.ShowWindow(SW_SHOW);
		dlgPrintStatus.UpdateWindow();

		// start document printing process
		if (!printInfo.m_bDocObject)
		{
			printInfo.m_nJobNumber = dcPrint.StartDoc(&docInfo);
			if (printInfo.m_nJobNumber == SP_ERROR)
			{
				// enable main window before proceeding
				hwndTemp->EnableWindow(TRUE);

				// cleanup and show error message
				OnEndPrinting(&dcPrint, &printInfo);
				dlgPrintStatus.DestroyWindow();
				dcPrint.Detach();   // will be cleaned up by CPrintInfo destructor
				AfxMessageBox(AFX_IDP_FAILED_TO_START_PRINT);
				return;
			}
		}

		// Guarantee values are in the valid range
		UINT nEndPage = printInfo.GetToPage();
		UINT nStartPage = printInfo.GetFromPage();

		if (nEndPage < printInfo.GetMinPage())
			nEndPage = printInfo.GetMinPage();
		if (nEndPage > printInfo.GetMaxPage())
			nEndPage = printInfo.GetMaxPage();

		if (nStartPage < printInfo.GetMinPage())
			nStartPage = printInfo.GetMinPage();
		if (nStartPage > printInfo.GetMaxPage())
			nStartPage = printInfo.GetMaxPage();

		int nStep = (nEndPage >= nStartPage) ? 1 : -1;
		nEndPage = (nEndPage == 0xffff) ? 0xffff : nEndPage + nStep;

		VERIFY(strTemp.LoadString(AFX_IDS_PRINTPAGENUM));

		// If it's a doc object, we don't loop page-by-page
		// because doc objects don't support that kind of levity.

		BOOL bError = FALSE;
		if (printInfo.m_bDocObject)
		{
			OnPrepareDC(&dcPrint, &printInfo);
			OnPrint(&dcPrint, &printInfo);
		}
		else
		{
			// begin page printing loop
			for (printInfo.m_nCurPage = nStartPage;
				printInfo.m_nCurPage != nEndPage; printInfo.m_nCurPage += nStep)
			{
				OnPrepareDC(&dcPrint, &printInfo);

				// check for end of print
				if (!printInfo.m_bContinuePrinting)
					break;

				// write current page
				TCHAR szBuf[80];
				ATL_CRT_ERRORCHECK_SPRINTF(_sntprintf_s(szBuf, _countof(szBuf), _countof(szBuf) - 1, strTemp, printInfo.m_nCurPage));
				
				dlgPrintStatus.SetDlgItemText(AFX_IDC_PRINT_PAGENUM, szBuf);

				// set up drawing rect to entire page (in logical coordinates)
				printInfo.m_rectDraw.SetRect(0, 0,
					dcPrint.GetDeviceCaps(HORZRES),
					dcPrint.GetDeviceCaps(VERTRES));
				dcPrint.DPtoLP(&printInfo.m_rectDraw);

				// attempt to start the current page
				if (dcPrint.StartPage() < 0)
				{
					bError = TRUE;
					break;
				}

				// must call OnPrepareDC on newer versions of Windows because
				// StartPage now resets the device attributes.
				OnPrepareDC(&dcPrint, &printInfo);

				ASSERT(printInfo.m_bContinuePrinting);

				// page successfully started, so now render the page
				OnPrint(&dcPrint, &printInfo);

				// If the user restarts the job when it's spooling, all 
				// subsequent calls to EndPage returns < 0. The first time
				// GetLastError returns ERROR_PRINT_CANCELLED
				if (dcPrint.EndPage() < 0 && (GetLastError()!= ERROR_SUCCESS))
				{
					HANDLE hPrinter;
					if (!OpenPrinter(LPTSTR(printInfo.m_pPD->GetDeviceName().GetBuffer()), &hPrinter, NULL))
					{
						bError = TRUE;
						break;
					}

					DWORD cBytesNeeded;
					if(!GetJob(hPrinter,printInfo.m_nJobNumber,1,NULL,0,&cBytesNeeded))
					{
						if (GetLastError() != ERROR_INSUFFICIENT_BUFFER)
						{
						   bError = TRUE;
						   break;
						}
					}

					JOB_INFO_1 *pJobInfo; 					
					if((pJobInfo = (JOB_INFO_1 *)malloc(cBytesNeeded))== NULL)
					{
						bError = TRUE;
						break;
					}

					DWORD cBytesUsed;

					BOOL bRet = GetJob(hPrinter,printInfo.m_nJobNumber,1,LPBYTE(pJobInfo),cBytesNeeded,&cBytesUsed);

					DWORD dwJobStatus = pJobInfo->Status;

					free(pJobInfo);
					pJobInfo = NULL;

					// if job status is restart, just continue
					if(!bRet || !(dwJobStatus & JOB_STATUS_RESTART) )
					{
						bError = TRUE;
						break;
					}
				}

				if(!_AfxAbortProc(dcPrint.m_hDC, 0))
				{		
					bError = TRUE;
					break;
				}
			}
		}

		// cleanup document printing process
		if (!printInfo.m_bDocObject)
		{
			if (!bError)
				dcPrint.EndDoc();
			else
				dcPrint.AbortDoc();
		}

		hwndTemp->EnableWindow();    // enable main window

		OnEndPrinting(&dcPrint, &printInfo);    // clean up after printing
		dlgPrintStatus.DestroyWindow();

		dcPrint.Detach();   // will be cleaned up by CPrintInfo destructor
	}
}
예제 #19
0
STDMETHODIMP COlePropertiesDialog::XOleUIObjInfo::GetObjectInfo(
	DWORD dwObject, DWORD* lpdwObjSize, LPTSTR* lplpszLabel,
	LPTSTR* lplpszType, LPTSTR* lplpszShortType, LPTSTR* lplpszLocation)
{
	COleClientItem* pItem = (COleClientItem*)dwObject;
	ASSERT_VALID(pItem);
	BOOL bIsLink = (pItem->GetType() == OT_LINK);

	if (lpdwObjSize != NULL)
	{
		ASSERT(pItem->m_lpStorage != NULL);

		// try ILockBytes first, then IStorage
		STATSTG statStg;
		if ((pItem->m_lpLockBytes == NULL ||
			pItem->m_lpLockBytes->Stat(&statStg, STATFLAG_NONAME) != S_OK) &&
			pItem->m_lpStorage->Stat(&statStg, STATFLAG_NONAME) != S_OK)
		{
			*lpdwObjSize = 0xFFFFFFFF;
		}
		else
		{
			ASSERT(statStg.pwcsName == NULL);
			if (statStg.cbSize.HighPart > 0)
				*lpdwObjSize = 0xFFFFFFFE;
			else if (statStg.cbSize.LowPart == 0)
				*lpdwObjSize = 0xFFFFFFFF;
			else
				*lpdwObjSize = statStg.cbSize.LowPart;
		}
	}

	if (lplpszLabel != NULL)
	{
		TCHAR szFormatLink[128];
		AfxLoadString(AFX_IDS_PASTELINKEDTYPE, szFormatLink, _countof(szFormatLink));
		TCHAR szFormatObj[] = _T("%s");
		LPTSTR lpszFormat = bIsLink ? szFormatLink : szFormatObj;
		CString strType;
		pItem->GetUserType(USERCLASSTYPE_FULL, strType);
		CString strResult;
		strResult.Format(lpszFormat, (LPCTSTR)strType);
		*lplpszLabel = AfxAllocTaskString(strResult);
	}

	if (lplpszType != NULL)
	{
		LPOLESTR lpOleStr;
		pItem->m_lpObject->GetUserType(USERCLASSTYPE_FULL, &lpOleStr);
		*lplpszType = TASKSTRINGOLE2T(lpOleStr);
	}

	if (lplpszShortType != NULL)
	{
		LPOLESTR lpOleStr;
		pItem->m_lpObject->GetUserType(USERCLASSTYPE_SHORT, &lpOleStr);
		*lplpszShortType = TASKSTRINGOLE2T(lpOleStr);
	}

	if (lplpszLocation != NULL)
	{
		if (bIsLink)
		{
			LPOLELINK lpOleLink = NULL;
			pItem->m_lpObject->QueryInterface(IID_IOleLink, (LPVOID*)&lpOleLink);
			ASSERT(lpOleLink != NULL);
			LPOLESTR lpOleStr;
			lpOleLink->GetSourceDisplayName(&lpOleStr);
			*lplpszLocation = TASKSTRINGOLE2T(lpOleStr);
			lpOleLink->Release();
		}
		else
		{
			CDocument* pDoc = (CDocument*)pItem->GetDocument();
			CString strLocation = pDoc->GetPathName();
			if (strLocation.IsEmpty())
				strLocation = pDoc->GetTitle();
			*lplpszLocation = AfxAllocTaskString(strLocation);
		}
	}

	return S_OK;
}
예제 #20
0
/////////////////////////////////////////////////////////////////////////////
// CDocSelector message handlers
BOOL CDocSelector::AddButton( CWnd* wnd, WORD wIcon ,HICON hIcon )
{
	CRect rect;
	GetClientRect(&rect);

	// Yogesh Jagota
	CDocument* pDoc = ((CView *) wnd)->GetDocument();

	CString sPath = pDoc->GetPathName();
	CString sFileName;
	
	if ( sPath.IsEmpty() )
		sPath = pDoc->GetTitle();

	// Can be only the filename, like Noname01
	if ( sPath.Find( _T('\\') ) != -1 )
		sFileName = sPath.Mid( sPath.ReverseFind( _T('\\') ) + 1 );
	else
		sFileName = sPath;

	// If there is no space left to display extra buttons...
	int nNewSize = ( ( rect.Width() - DS_MENU_BUTTON_WIDTH ) 
		/ ( m_Buttons.GetSize() + 1 ) ) - DS_SEPERATER_MARGIN;

	bool bShowButton = true;
	if ( nNewSize <= MINWIDTH )
	{
		// Check if the menu button is displayed, if not, display it...
		m_btnMenuButton.ShowWindow( SW_SHOW );

		// Don't show the button...
		bShowButton = false;
	}
	else
		m_nDisplayedButtons++;

	// End Yogesh Jagota

	CSwitcherButton* newbutton = new CSwitcherButton();

	 // Yogesh Jagota
	newbutton->m_AttachedView = wnd;

	// I am saving the frame to make life easier in case
	// of activation in selection process...
	CMDIFrameWnd *pFrame = (CMDIFrameWnd *)AfxGetMainWnd();
	CWnd * pWnd = pFrame->GetWindow( GW_CHILD );
	ASSERT (pWnd);
	pWnd = pWnd->GetWindow( GW_CHILD );
	while (pWnd)
	{
		if ( ((CFrameWnd *)pWnd)->GetActiveView() == (CView*)wnd )
			newbutton->m_FrameWnd = (CFrameWnd *)pWnd;

		pWnd = pWnd->GetWindow( GW_HWNDNEXT );
	}

	// Load the icon....
	if ( hIcon)
	{
		newbutton->m_iIcon=hIcon;
		newbutton->m_iIcon=AfxGetApp()->LoadIcon(IDR_MAINFRAME);
	}
	
	else

	if ( wIcon != -1 )
		newbutton->m_iIcon = ::LoadIcon( AfxGetInstanceHandle(), 
			MAKEINTRESOURCE( wIcon ) );
	// End Yogesh Jagota

	newbutton->m_iID = m_Buttons.GetSize();
	if (!newbutton->DoCreate(this, m_iNextButtonStart, 
		rect.top + 3, m_iButtonWidth, DS_HEIGHT - 2, 
		sFileName, sPath )) // Yogesh Jagota
	{
		return FALSE;
	}

	if ( !bShowButton )
		newbutton->ShowWindow( SW_HIDE );

	m_Buttons.Add((void*)newbutton);
	m_iNextButtonStart += m_iButtonWidth + DS_SEPERATER_MARGIN;

	if (m_iNextButtonStart - DS_SEPERATER_MARGIN > rect.Width())
	{
		// this loop makes a neat little animation
		int newsize = ((rect.Width() - DS_MENU_BUTTON_WIDTH ) 
			/ (m_Buttons.GetSize())) - DS_SEPERATER_MARGIN;

//		Yogesh Jagota. Removed animation because did'nt liked it.
//		Remove if you want animated addition or removal of buttons.
//
//		register int y;
//		for (y = m_iButtonWidth; y >= newsize; y-=3)
//		{
//			ResizeButtons(y);
//			Sleep(15);
//		}
//
//		if (y != newsize)
//			/* ResizeButtons(newsize); */ <- this is the next line...
//		End Yogesh Jagota

		ResizeButtons(newsize);

		if (m_iButtonWidth < MINWIDTH)
		{
			// the smallest allowable button size has been reached...
			// in this version, we can't handle this
			ASSERT(0);
			return FALSE;
		}
	}
	else
		m_btnMenuButton.ShowWindow( SW_HIDE );

	// Yogesh Jagota
	if ( m_iSelectedButton != -1 )
		((CSwitcherButton *) m_Buttons.GetAt( m_iSelectedButton ))->Unselect();

	m_iSelectedButton = newbutton->m_iID;
	((CSwitcherButton *) m_Buttons.GetAt( m_iSelectedButton ))->Select();
	// End Yogesh Jagota

	return TRUE;
}
예제 #21
0
void CView::OnFilePrint()
{
	// get default print info
	CPrintInfo printInfo;
	ASSERT(printInfo.m_pPD != NULL);    // must be set

	if (LOWORD(GetCurrentMessage()->wParam) == ID_FILE_PRINT_DIRECT)
	{
		CCommandLineInfo* pCmdInfo = AfxGetApp()->m_pCmdInfo;

		if (pCmdInfo != NULL)
		{
			if (pCmdInfo->m_nShellCommand == CCommandLineInfo::FilePrintTo)
			{
				printInfo.m_pPD->m_pd.hDC = ::CreateDC(pCmdInfo->m_strDriverName,
					pCmdInfo->m_strPrinterName, pCmdInfo->m_strPortName, NULL);
				if (printInfo.m_pPD->m_pd.hDC == NULL)
				{
					AfxMessageBox(AFX_IDP_FAILED_TO_START_PRINT);
					return;
				}
			}
		}

		printInfo.m_bDirect = TRUE;
	}

	if (OnPreparePrinting(&printInfo))
	{
		// hDC must be set (did you remember to call DoPreparePrinting?)
		ASSERT(printInfo.m_pPD->m_pd.hDC != NULL);

		// gather file to print to if print-to-file selected
		CString strOutput;
		if (printInfo.m_pPD->m_pd.Flags & PD_PRINTTOFILE && !printInfo.m_bDocObject)
		{
			// construct CFileDialog for browsing
			CString strDef(MAKEINTRESOURCE(AFX_IDS_PRINTDEFAULTEXT));
			CString strPrintDef(MAKEINTRESOURCE(AFX_IDS_PRINTDEFAULT));
			CString strFilter(MAKEINTRESOURCE(AFX_IDS_PRINTFILTER));
			CString strCaption(MAKEINTRESOURCE(AFX_IDS_PRINTCAPTION));
			CFileDialog dlg(FALSE, strDef, strPrintDef,
				OFN_HIDEREADONLY|OFN_OVERWRITEPROMPT, strFilter);
			dlg.m_ofn.lpstrTitle = strCaption;

			if (dlg.DoModal() != IDOK)
				return;

			// set output device to resulting path name
			strOutput = dlg.GetPathName();
		}

		// set up document info and start the document printing process
		CString strTitle;
		CDocument* pDoc = GetDocument();
		if (pDoc != NULL)
			strTitle = pDoc->GetTitle();
		else
			GetParentFrame()->GetWindowText(strTitle);
		if (strTitle.GetLength() > 31)
			strTitle.ReleaseBuffer(31);
		DOCINFO docInfo;
		memset(&docInfo, 0, sizeof(DOCINFO));
		docInfo.cbSize = sizeof(DOCINFO);
		docInfo.lpszDocName = strTitle;
		CString strPortName;
		int nFormatID;
		if (strOutput.IsEmpty())
		{
			docInfo.lpszOutput = NULL;
			strPortName = printInfo.m_pPD->GetPortName();
			nFormatID = AFX_IDS_PRINTONPORT;
		}
		else
		{
			docInfo.lpszOutput = strOutput;
			AfxGetFileTitle(strOutput,
				strPortName.GetBuffer(_MAX_PATH), _MAX_PATH);
			nFormatID = AFX_IDS_PRINTTOFILE;
		}

		// setup the printing DC
		CDC dcPrint;
		if (!printInfo.m_bDocObject)
		{
			dcPrint.Attach(printInfo.m_pPD->m_pd.hDC);  // attach printer dc
			dcPrint.m_bPrinting = TRUE;
		}
		OnBeginPrinting(&dcPrint, &printInfo);

		if (!printInfo.m_bDocObject)
			dcPrint.SetAbortProc(_AfxAbortProc);

		// disable main window while printing & init printing status dialog
		AfxGetMainWnd()->EnableWindow(FALSE);
		CPrintingDialog dlgPrintStatus(this);

		CString strTemp;
		dlgPrintStatus.SetDlgItemText(AFX_IDC_PRINT_DOCNAME, strTitle);
		dlgPrintStatus.SetDlgItemText(AFX_IDC_PRINT_PRINTERNAME,
			printInfo.m_pPD->GetDeviceName());
		AfxFormatString1(strTemp, nFormatID, strPortName);
		dlgPrintStatus.SetDlgItemText(AFX_IDC_PRINT_PORTNAME, strTemp);
		dlgPrintStatus.ShowWindow(SW_SHOW);
		dlgPrintStatus.UpdateWindow();

		// start document printing process
		if (!printInfo.m_bDocObject && dcPrint.StartDoc(&docInfo) == SP_ERROR)
		{
			// enable main window before proceeding
			AfxGetMainWnd()->EnableWindow(TRUE);

			// cleanup and show error message
			OnEndPrinting(&dcPrint, &printInfo);
			dlgPrintStatus.DestroyWindow();
			dcPrint.Detach();   // will be cleaned up by CPrintInfo destructor
			AfxMessageBox(AFX_IDP_FAILED_TO_START_PRINT);
			return;
		}

		// Guarantee values are in the valid range
		UINT nEndPage = printInfo.GetToPage();
		UINT nStartPage = printInfo.GetFromPage();

		if (nEndPage < printInfo.GetMinPage())
			nEndPage = printInfo.GetMinPage();
		if (nEndPage > printInfo.GetMaxPage())
			nEndPage = printInfo.GetMaxPage();

		if (nStartPage < printInfo.GetMinPage())
			nStartPage = printInfo.GetMinPage();
		if (nStartPage > printInfo.GetMaxPage())
			nStartPage = printInfo.GetMaxPage();

		int nStep = (nEndPage >= nStartPage) ? 1 : -1;
		nEndPage = (nEndPage == 0xffff) ? 0xffff : nEndPage + nStep;

		VERIFY(strTemp.LoadString(AFX_IDS_PRINTPAGENUM));

		// If it's a doc object, we don't loop page-by-page
		// because doc objects don't support that kind of levity.

		BOOL bError = FALSE;
		if (printInfo.m_bDocObject)
		{
			OnPrepareDC(&dcPrint, &printInfo);
			OnPrint(&dcPrint, &printInfo);
		}
		else
		{
			// begin page printing loop
			for (printInfo.m_nCurPage = nStartPage;
				printInfo.m_nCurPage != nEndPage; printInfo.m_nCurPage += nStep)
			{
				OnPrepareDC(&dcPrint, &printInfo);

				// check for end of print
				if (!printInfo.m_bContinuePrinting)
					break;

				// write current page
				TCHAR szBuf[80];
				wsprintf(szBuf, strTemp, printInfo.m_nCurPage);
				dlgPrintStatus.SetDlgItemText(AFX_IDC_PRINT_PAGENUM, szBuf);

				// set up drawing rect to entire page (in logical coordinates)
				printInfo.m_rectDraw.SetRect(0, 0,
					dcPrint.GetDeviceCaps(HORZRES),
					dcPrint.GetDeviceCaps(VERTRES));
				dcPrint.DPtoLP(&printInfo.m_rectDraw);

				// attempt to start the current page
				if (dcPrint.StartPage() < 0)
				{
					bError = TRUE;
					break;
				}

				// must call OnPrepareDC on newer versions of Windows because
				// StartPage now resets the device attributes.
				if (afxData.bMarked4)
					OnPrepareDC(&dcPrint, &printInfo);

				ASSERT(printInfo.m_bContinuePrinting);

				// page successfully started, so now render the page
				OnPrint(&dcPrint, &printInfo);
				if (dcPrint.EndPage() < 0 || !_AfxAbortProc(dcPrint.m_hDC, 0))
				{
					bError = TRUE;
					break;
				}
			}
		}

		// cleanup document printing process
		if (!printInfo.m_bDocObject)
		{
			if (!bError)
				dcPrint.EndDoc();
			else
				dcPrint.AbortDoc();
		}

		AfxGetMainWnd()->EnableWindow();    // enable main window

		OnEndPrinting(&dcPrint, &printInfo);    // clean up after printing
		dlgPrintStatus.DestroyWindow();

		dcPrint.Detach();   // will be cleaned up by CPrintInfo destructor
	}
}