// [!output VIEW_IMPL] : implémentation de la classe [!output VIEW_CLASS] // #include "stdafx.h" #include "[!output APP_HEADER]" [!if OLEDB_RECORD_VIEW || ODBC_RECORD_VIEW] #include "[!output ROWSET_HEADER]" [!endif] #include "[!output DOC_HEADER]" [!if CONTAINER || CONTAINER_SERVER] #include "[!output CONTAINER_ITEM_HEADER]" [!endif] #include "[!output VIEW_HEADER]" #ifdef _DEBUG #define new DEBUG_NEW #endif // [!output VIEW_CLASS] IMPLEMENT_DYNCREATE([!output VIEW_CLASS], [!output VIEW_BASE_CLASS]) BEGIN_MESSAGE_MAP([!output VIEW_CLASS], [!output VIEW_BASE_CLASS]) [!if PROJECT_STYLE_EXPLORER] [!if LIST_VIEW] ON_WM_STYLECHANGED() [!endif] [!endif] [!if CONTAINER || CONTAINER_SERVER] ON_WM_DESTROY() [!if !RICH_EDIT_VIEW] ON_WM_SETFOCUS() ON_WM_SIZE() ON_COMMAND(ID_OLE_INSERT_NEW, &[!output VIEW_CLASS]::OnInsertObject) ON_COMMAND(ID_CANCEL_EDIT_CNTR, &[!output VIEW_CLASS]::OnCancelEditCntr) ON_COMMAND(ID_FILE_PRINT, &[!output VIEW_CLASS]::OnFilePrint) [!else] [!if PRINTING] // Commandes d'impression standard ON_COMMAND(ID_FILE_PRINT, &[!output VIEW_BASE_CLASS]::OnFilePrint) [!endif] [!endif] [!else] [!if PRINTING] // Commandes d'impression standard ON_COMMAND(ID_FILE_PRINT, &[!output VIEW_BASE_CLASS]::OnFilePrint) [!endif] [!endif] [!if MINI_SERVER || FULL_SERVER || CONTAINER_SERVER] ON_COMMAND(ID_CANCEL_EDIT_SRVR, &[!output VIEW_CLASS]::OnCancelEditSrvr) [!endif] [!if PRINTING] [!if !HTML_VIEW && !HTML_EDITVIEW && !ACTIVE_DOC_CONTAINER] ON_COMMAND(ID_FILE_PRINT_DIRECT, &[!output VIEW_BASE_CLASS]::OnFilePrint) ON_COMMAND(ID_FILE_PRINT_PREVIEW, &[!output VIEW_BASE_CLASS]::OnFilePrintPreview) [!endif] [!if ACTIVE_DOC_CONTAINER] ON_COMMAND(ID_FILE_PRINT_DIRECT, &[!output VIEW_BASE_CLASS]::OnFilePrint) ON_COMMAND(ID_FILE_PRINT_PREVIEW, &[!output VIEW_CLASS]::OnFilePrintPreview) [!if !RICH_EDIT_VIEW] ON_UPDATE_COMMAND_UI(ID_FILE_PRINT_PREVIEW, &OnFilePrintPreviewUIUpdate) [!endif] [!endif] [!endif] END_MESSAGE_MAP() [!if HTML_EDITVIEW] BEGIN_DHTMLEDITING_CMDMAP([!output VIEW_CLASS]) DHTMLEDITING_CMD_ENTRY(ID_EDIT_COPY, IDM_COPY) DHTMLEDITING_CMD_ENTRY(ID_EDIT_CUT, IDM_CUT) DHTMLEDITING_CMD_ENTRY(ID_EDIT_PASTE, IDM_PASTE) DHTMLEDITING_CMD_ENTRY(ID_EDIT_UNDO, IDM_UNDO) END_DHTMLEDITING_CMDMAP() [!endif] // construction ou destruction de [!output VIEW_CLASS] [!output VIEW_CLASS]::[!output VIEW_CLASS]() [!if FORM_VIEW || OLEDB_RECORD_VIEW || ODBC_RECORD_VIEW] : [!output VIEW_BASE_CLASS]([!output VIEW_CLASS]::IDD) [!endif] { [!if ACCESSIBILITY] EnableActiveAccessibility(); [!endif] [!if FORM_VIEW || OLEDB_RECORD_VIEW || ODBC_RECORD_VIEW] [!if OLEDB_RECORD_VIEW || ODBC_RECORD_VIEW] m_pSet = NULL; [!endif] [!endif] [!if CONTAINER || CONTAINER_SERVER] [!if !RICH_EDIT_VIEW] m_pSelection = NULL; [!endif] [!endif] // TODO : ajoutez ici du code de construction } [!output VIEW_CLASS]::~[!output VIEW_CLASS]() { } [!if FORM_VIEW || OLEDB_RECORD_VIEW || ODBC_RECORD_VIEW] void [!output VIEW_CLASS]::DoDataExchange(CDataExchange* pDX) { [!output VIEW_BASE_CLASS]::DoDataExchange(pDX); [!if ODBC_RECORD_VIEW] // vous pouvez insérer ici des fonctions DDX_Field* pour lier vos contrôles aux champs de la base de données, par exemple // DDX_FieldText(pDX, IDC_MYEDITBOX, m_pSet->m_szColumn1, m_pSet); // DDX_FieldCheck(pDX, IDC_MYCHECKBOX, m_pSet->m_bColumn2, m_pSet); // Consultez les exemples MSDN et ODBC pour plus d'informations [!endif] [!if OLEDB_RECORD_VIEW] // vous pouvez insérer ici des fonctions DDX_* et des appels API SetDlgItem*/GetDlgItem* pour lier votre base de données à la vue, // par exemple ::SetDlgItemText(m_hWnd, IDC_MYCONTROL, m_pSet->m_MyColumn); // Consultez les exemples MSDN et OLEDB pour plus d'informations [!endif] } [!endif] BOOL [!output VIEW_CLASS]::PreCreateWindow(CREATESTRUCT& cs) { // TODO : changez ici la classe ou les styles Window en modifiant // CREATESTRUCT cs [!if EDIT_VIEW] BOOL bPreCreated = CEditView::PreCreateWindow(cs); cs.style &= ~(ES_AUTOHSCROLL|WS_HSCROLL); // Active le retour automatique à la ligne return bPreCreated; [!else] return [!output VIEW_BASE_CLASS]::PreCreateWindow(cs); [!endif] } [!if !TREE_VIEW && !LIST_VIEW && !HTML_VIEW && !HTML_EDITVIEW && !RICH_EDIT_VIEW && !EDIT_VIEW && !FORM_VIEW && !OLEDB_RECORD_VIEW && !ODBC_RECORD_VIEW] // dessin de [!output VIEW_CLASS] [!if CONTAINER || CONTAINER_SERVER] [!if !ACTIVE_DOC_CONTAINER] void [!output VIEW_CLASS]::OnDraw(CDC* pDC) { if (!pDC) return; [!output DOC_CLASS]* pDoc = GetDocument(); ASSERT_VALID(pDoc); if (!pDoc) return; // TODO : ajoutez ici le code de dessin pour les données natives // TODO : dessinez aussi tous les éléments OLE dans le document // Dessine la sélection à une position arbitraire. Ce code doit être // supprimé lorsque votre code de dessin final est implémenté. Cette position // correspond exactement au rectangle retourné par [!output CONTAINER_ITEM_CLASS] // afin de donner l'effet d'une modification sur place. // TODO : supprimez ce code lorsque votre code de dessin final est complet. if (m_pSelection != NULL) { CSize size; CRect rect(10, 10, 210, 210); if (SUCCEEDED(m_pSelection->GetExtent(&size, m_pSelection->m_nDrawAspect))) { pDC->HIMETRICtoLP(&size); rect.right = size.cx + 10; rect.bottom = size.cy + 10; } m_pSelection->Draw(pDC, rect); } } [!else] void [!output VIEW_CLASS]::OnDraw(CDC* /*pDC*/) { [!output DOC_CLASS]* pDoc = GetDocument(); ASSERT_VALID(pDoc); if (!pDoc) return; // TODO : ajoutez ici le code de dessin pour les données natives }[!endif] [!else] void [!output VIEW_CLASS]::OnDraw(CDC* /*pDC*/) { [!output DOC_CLASS]* pDoc = GetDocument(); ASSERT_VALID(pDoc); if (!pDoc) return; // TODO : ajoutez ici le code de dessin pour les données natives } [!endif] [!endif] [!if PRINTING] [!if TREE_VIEW || LIST_VIEW] void [!output VIEW_CLASS]::OnDraw(CDC* /*pDC*/) { [!output DOC_CLASS]* pDoc = GetDocument(); ASSERT_VALID(pDoc); // TODO : ajoutez ici le code de dessin pour les données natives } [!endif] [!endif] [!if SCROLL_VIEW || CONTAINER || CONTAINER_SERVER || OLEDB_RECORD_VIEW || LIST_VIEW || TREE_VIEW || FORM_VIEW || HTML_VIEW || ODBC_RECORD_VIEW] void [!output VIEW_CLASS]::OnInitialUpdate() { [!if ODBC_RECORD_VIEW] m_pSet = &GetDocument()->[!output ROWSET_CLASS_VARIABLE_NAME]; [!endif] [!if OLEDB_RECORD_VIEW] m_pSet = &GetDocument()->[!output ROWSET_CLASS_VARIABLE_NAME]; { CWaitCursor wait; HRESULT hr = m_pSet->OpenAll(); if (FAILED(hr)) { // Impossible d'ouvrir le jeu d'enregistrements. Si ce jeu est une // procédure stockée, vérifiez que vous avez correctement // initialisé les paramètres d'entrée avant d'appeler // la méthode OpenAll(). AfxMessageBox(_T("Impossible d'ouvrir le jeu d'enregistrements."), MB_OK); // Désactiver les commandes Enregistrement suivant et Enregistrement précédent, // car toute tentative de modification de l'enregistrement en cours sans // Rowset ouvert se soldera par une erreur m_bOnFirstRecord = TRUE; m_bOnLastRecord = TRUE; } if( hr == DB_S_ENDOFROWSET ) { // le Rowset est vide (il ne contient aucune ligne) AfxMessageBox(_T("Le jeu d'enregistrements est ouvert, mais il ne contient aucune ligne à retourner."), MB_OK); // Désactiver les commandes Enregistrement suivant et Enregistrement précédent m_bOnFirstRecord = TRUE; m_bOnLastRecord = TRUE; } } [!endif] [!output VIEW_BASE_CLASS]::OnInitialUpdate(); [!if FORM_VIEW] [!if APP_TYPE_SDI] GetParentFrame()->RecalcLayout(); [!endif] ResizeParentToFit(); [!endif] [!if LIST_VIEW] // TODO : vous pouvez remplir votre contrôle ListView avec des éléments en accédant directement // au contrôle List par un appel à GetListCtrl(). [!if TREE_VIEW] // TODO : vous pouvez remplir votre contrôle TreeView avec des éléments en accédant directement // au contrôle Tree par un appel à GetTreeCtrl(). [!if HTML_VIEW] // TODO : ce code renvoie à un emplacement populaire sur le Web. // Changez-le pour un emplacement où vous souhaitez aller. [!endif] [!endif] [!endif] [!if HTML_VIEW] Navigate2(_T("http://www.microsoft.com/france/visualc/"),NULL,NULL); [!endif] [!if CONTAINER || CONTAINER_SERVER] [!if !RICH_EDIT_VIEW] // TODO : supprimez ce code lorsque votre code de modèle de sélection est complet m_pSelection = NULL; // initialiser la sélection [!endif] [!if RICH_EDIT_VIEW] // Définir les marges d'impression (720 twips = 1/2 pouce) SetMargins(CRect(720, 720, 720, 720)); [!endif] [!endif] [!if SCROLL_VIEW] CSize sizeTotal; // TODO : calculez la taille totale de cette vue sizeTotal.cx = sizeTotal.cy = 100; SetScrollSizes(MM_TEXT, sizeTotal); [!endif] } [!endif] [!if PRINTING] // impression de [!output VIEW_CLASS] [!if ACTIVE_DOC_CONTAINER] [!if !RICH_EDIT_VIEW] void [!output VIEW_CLASS]::OnFilePrintPreviewUIUpdate(CCmdUI* pCmdUI) { if (!pCmdUI) return; if (m_pSelection != NULL) { DWORD dwStatus = 0; if (SUCCEEDED(m_pSelection->QueryCommand(OLECMDID_PRINTPREVIEW, &dwStatus)) && dwStatus & OLECMDF_ENABLED) { pCmdUI->Enable(TRUE); return; } } pCmdUI->Enable(FALSE); } [!endif] void [!output VIEW_CLASS]::OnFilePrintPreview() { [!if !RICH_EDIT_VIEW] if (!m_pSelection) return; m_pSelection->ExecCommand(OLECMDID_PRINTPREVIEW); [!else] [!output VIEW_BASE_CLASS]::OnFilePrintPreview(); [!endif] } [!endif] [!if !HTML_VIEW && !HTML_EDITVIEW] BOOL [!output VIEW_CLASS]::OnPreparePrinting(CPrintInfo* pInfo) { [!if EDIT_VIEW] // préparation par défaut de CEditView return CEditView::OnPreparePrinting(pInfo); [!else] [!if ACTIVE_DOC_CONTAINER] if (!CView::DoPreparePrinting(pInfo)) return FALSE; if (!COleDocObjectItem::OnPreparePrinting(this, pInfo)) return FALSE; return TRUE; [!else] // préparation par défaut return DoPreparePrinting(pInfo); [!endif] [!endif] } [!if !RICH_EDIT_VIEW] [!if EDIT_VIEW] void [!output VIEW_CLASS]::OnBeginPrinting(CDC* pDC, CPrintInfo* pInfo) [!else] void [!output VIEW_CLASS]::OnBeginPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/) [!endif] { [!if EDIT_VIEW] // début de l'impression par défaut de CEditView CEditView::OnBeginPrinting(pDC, pInfo); [!else] // TODO : ajoutez une initialisation supplémentaire avant l'impression [!endif] } [!if EDIT_VIEW] void [!output VIEW_CLASS]::OnEndPrinting(CDC* pDC, CPrintInfo* pInfo) [!else] void [!output VIEW_CLASS]::OnEndPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/) [!endif] { [!if EDIT_VIEW] // fin de l'impression par défaut de CEditView CEditView::OnEndPrinting(pDC, pInfo); [!else] // TODO : ajoutez un nettoyage après l'impression [!endif] } [!endif] [!endif] [!if FORM_VIEW || ACTIVE_DOC_CONTAINER] [!if ACTIVE_DOC_CONTAINER] void [!output VIEW_CLASS]::OnPrint(CDC* pDC, CPrintInfo* pInfo) [!else] void [!output VIEW_CLASS]::OnPrint(CDC* pDC, CPrintInfo* /*pInfo*/) [!endif] { // TODO : ajoutez ici le code d'impression personnalisé [!if ACTIVE_DOC_CONTAINER] if(pInfo->m_bDocObject) COleDocObjectItem::OnPrint(this, pInfo, TRUE); else CView::OnPrint(pDC, pInfo); [!endif] } [!endif] [!endif] [!if CONTAINER || CONTAINER_SERVER] void [!output VIEW_CLASS]::OnDestroy() { // Désactiver l'élément en destruction ; cela est important // lorsqu'une vue fractionnée est utilisée COleClientItem* pActiveItem = GetDocument()->GetInPlaceActiveItem(this); if (pActiveItem != NULL && pActiveItem->GetActiveView() == this) { pActiveItem->Deactivate(); ASSERT(GetDocument()->GetInPlaceActiveItem(this) == NULL); } [!output VIEW_BASE_CLASS]::OnDestroy(); } [!if !RICH_EDIT_VIEW] // prise en charge et commandes du client OLE BOOL [!output VIEW_CLASS]::IsSelected(const CObject* pDocItem) const { // L'implémentation ci-après est appropriée si votre sélection comporte // uniquement des objets [!output CONTAINER_ITEM_CLASS]. Pour gérer des mécanismes de sélection // différents, cette implémentation doit être remplacée // TODO : implémentez cette fonction qui vérifie un élément sélectionné du client OLE return pDocItem == m_pSelection; } void [!output VIEW_CLASS]::OnInsertObject() { // Appeler la boîte de dialogue standard 'Insérer un objet' pour obtenir des informations // sur le nouvel objet [!output CONTAINER_ITEM_CLASS] COleInsertDialog dlg; [!if ACTIVE_DOC_CONTAINER] if (dlg.DoModal(COleInsertDialog::DocObjectsOnly) != IDOK) return; [!else] if (dlg.DoModal() != IDOK) return; [!endif] BeginWaitCursor(); [!output CONTAINER_ITEM_CLASS]* pItem = NULL; TRY { // Créer un nouvel élément lié à ce document [!output DOC_CLASS]* pDoc = GetDocument(); ASSERT_VALID(pDoc); pItem = new [!output CONTAINER_ITEM_CLASS](pDoc); ASSERT_VALID(pItem); // Initialise l'élément en fonction des données de la boîte de dialogue if (!dlg.CreateItem(pItem)) AfxThrowMemoryException(); // toute exception fera l'affaire ASSERT_VALID(pItem); [!if ACTIVE_DOC_CONTAINER] pItem->DoVerb(OLEIVERB_SHOW, this); [!else] if (dlg.GetSelectionType() == COleInsertDialog::createNewItem) pItem->DoVerb(OLEIVERB_SHOW, this); [!endif] ASSERT_VALID(pItem); // En tant que design d'interface utilisateur arbitraire, définit la sélection // sur le dernier élément inséré // TODO : implémentez de nouveau la sélection pour votre application m_pSelection = pItem; // définit la sélection sur le dernier élément inséré pDoc->UpdateAllViews(NULL); } CATCH(CException, e) { if (pItem != NULL) { ASSERT_VALID(pItem); pItem->Delete(); } AfxMessageBox(IDP_FAILED_TO_CREATE); } END_CATCH EndWaitCursor(); } // Le gestionnaire de commande suivant fournit l'interface utilisateur // clavier standard pour annuler une session de modification sur place. Ici, // le conteneur (pas le serveur) provoque la désactivation void [!output VIEW_CLASS]::OnCancelEditCntr() { // Ferme tout élément qui est actif sur place dans cette vue. COleClientItem* pActiveItem = GetDocument()->GetInPlaceActiveItem(this); if (pActiveItem != NULL) { pActiveItem->Close(); } ASSERT(GetDocument()->GetInPlaceActiveItem(this) == NULL); } // Une gestion particulière de OnSetFocus et OnSize est requise pour un conteneur // lorsqu'un objet est modifié sur place void [!output VIEW_CLASS]::OnSetFocus(CWnd* pOldWnd) { COleClientItem* pActiveItem = GetDocument()->GetInPlaceActiveItem(this); if (pActiveItem != NULL && pActiveItem->GetItemState() == COleClientItem::activeUIState) { // le focus doit être défini sur cet élément s'il se trouve dans la même vue CWnd* pWnd = pActiveItem->GetInPlaceWindow(); if (pWnd != NULL) { pWnd->SetFocus(); // la classe de base n'est pas appelée return; } } [!output VIEW_BASE_CLASS]::OnSetFocus(pOldWnd); } void [!output VIEW_CLASS]::OnSize(UINT nType, int cx, int cy) { [!output VIEW_BASE_CLASS]::OnSize(nType, cx, cy); COleClientItem* pActiveItem = GetDocument()->GetInPlaceActiveItem(this); if (pActiveItem != NULL) pActiveItem->SetItemRects(); } void [!output VIEW_CLASS]::OnFilePrint() { //Par défaut, le document actif s'imprime //en utilisant IOleCommandTarget. Si ce comportement ne vous convient pas, //supprimez l'appel à COleDocObjectItem::DoDefaultPrinting. //Si l'appel échoue, le document //sera imprimé à l'aide de l'interface IPrint dans la mesure du possible. CPrintInfo printInfo; ASSERT(printInfo.m_pPD != NULL); if (S_OK == COleDocObjectItem::DoDefaultPrinting(this, &printInfo)) return; CView::OnFilePrint(); } [!endif] [!endif] [!if MINI_SERVER || FULL_SERVER || CONTAINER_SERVER] // Prise en charge du serveur OLE // Le gestionnaire de commande suivant fournit l'interface utilisateur // clavier standard pour annuler une session de modification sur place. Ici, // le serveur (pas le conteneur) provoque la désactivation void [!output VIEW_CLASS]::OnCancelEditSrvr() { GetDocument()->OnDeactivateUI(FALSE); } [!endif] // diagnostics pour [!output VIEW_CLASS] #ifdef _DEBUG void [!output VIEW_CLASS]::AssertValid() const { [!output VIEW_BASE_CLASS]::AssertValid(); } void [!output VIEW_CLASS]::Dump(CDumpContext& dc) const { [!output VIEW_BASE_CLASS]::Dump(dc); } [!output DOC_CLASS]* [!output VIEW_CLASS]::GetDocument() const // la version non déboguée est en ligne { ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS([!output DOC_CLASS]))); return ([!output DOC_CLASS]*)m_pDocument; } #endif //_DEBUG [!if OLEDB_RECORD_VIEW] // prise en charge des bases de données [!output VIEW_CLASS] CRowset<>* [!output VIEW_CLASS]::OnGetRowset() { return m_pSet->GetRowsetBase(); } [!endif] [!if ODBC_RECORD_VIEW] // prise en charge des bases de données [!output VIEW_CLASS] CRecordset* [!output VIEW_CLASS]::OnGetRecordset() { return m_pSet; } [!endif] // gestionnaires de messages pour [!output VIEW_CLASS] [!if PROJECT_STYLE_EXPLORER] [!if LIST_VIEW] void [!output VIEW_CLASS]::OnStyleChanged(int nStyleType, LPSTYLESTRUCT lpStyleStruct) { //TODO : ajoutez ici le code qui définit le comportement de votre application lorsque l'utilisateur change le style d'affichage de la fenêtre [!output VIEW_BASE_CLASS]::OnStyleChanged(nStyleType,lpStyleStruct); } [!endif] [!endif]