Indice del forum Olimpo Informatico
I Forum di Zeus News
Leggi la newsletter gratuita - Attiva il Menu compatto
 
 FAQFAQ   CercaCerca   Lista utentiLista utenti   GruppiGruppi   RegistratiRegistrati 
 ProfiloProfilo   Messaggi privatiMessaggi privati   Log inLog in 

    Newsletter RSS Facebook Twitter Contatti Ricerca
[C++] - Caricare Form figlio in un form Padre MDI
Nuovo argomento   Rispondi    Indice del forum -> Programmazione
Precedente :: Successivo  
Autore Messaggio
Emi81
Comune mortale
Comune mortale


Registrato: 21/05/07 09:45
Messaggi: 1

MessaggioInviato: 21 Mag 2007 09:58    Oggetto: [C++] - Caricare Form figlio in un form Padre MDI Rispondi

Ciao a tutti,
ho trovato un esempio dal supporto microsoft per un programmino che si basa sul MDI.

questo programma apre dei documenti figlio.

Io utilizzo Visual 6 C++, e vorrei aprire un form figlio con pulsanti e checkbox..

qualcuno sa aiutarmi ?

Vi posto il codice sotto :


Questo crea il form padre
Codice:


BOOL CFramerApp::InitApplication(LPCSTR pszCmdLine, int nCmdShow)
{
    CLIENTCREATESTRUCT clientcreate;

 // 1. Register window classes...
    if (!RegisterWindowClasses()) return FALSE;
    InitCommonControls();

 // 2. Load Menu resources...
   //_hMenuOrg = LoadMenu(g_hInstance, MAKEINTRESOURCE(IDR_MAIN_MENU));
    _hMenuOrg = LoadMenu(g_hInstance, MAKEINTRESOURCE(IDR_MENU));
    if (NULL == _hMenuOrg) return FALSE;

   _phMenus = new HMENU[FEX_MENUCOUNT];
    if (NULL == _phMenus) return FALSE;
   for (UINT uTemp=0; uTemp < FEX_MENUCOUNT; uTemp++)
      _phMenus[uTemp] = GetSubMenu(_hMenuOrg, uTemp);

 // 3. Load accelerators...
    _hAccel = LoadAccelerators(g_hInstance, MAKEINTRESOURCE(IDR_ACCELERATORS));
    if (NULL == _hAccel) return FALSE;

 // 4. Create the main window and client-area window
    _hwndApp = CreateWindow("FrameWndClass", "   Prova",
                          WS_OVERLAPPEDWINDOW | WS_CLIPCHILDREN,
                    CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT,
                          NULL, _hMenuOrg, g_hInstance, NULL);
    if (NULL == _hwndApp) return FALSE;

    clientcreate.hWindowMenu = _phMenus[FEX_WINDOWPOPUPMENU];
    clientcreate.idFirstChild = 6000;

    _hwndMDI = CreateWindow("MDICLIENT", NULL, WS_CHILD | WS_CLIPCHILDREN | WS_VISIBLE,
                        0, 0, 0, 0, _hwndApp, NULL, g_hInstance, (LPSTR)&clientcreate);
    if (NULL == _hwndMDI) return FALSE;

//    _hwndStatus = CreateStatusWindow(SBARS_SIZEGRIP | WS_CHILD | WS_CLIPCHILDREN | WS_VISIBLE, "Ready...", _hwndApp, 2);
   _hwndStatus = CreateStatusBar(_hwndApp);
    if (NULL == _hwndStatus) return FALSE;

 // 5. Make us all visible.
    ShowWindow(_hwndApp, nCmdShow);
    UpdateWindow(_hwndApp);

    return TRUE;
}



Poi quando dal menu uno seleziona "New File" :

Codice:

STDMETHODIMP_(BOOL) CFramerApp::NewFile(WORD wDocType)
{
   CLSID clsid = {0};
   BOOL fHaveCLSID =FALSE;

 // Create a new document object to host embedded object...
    CFramerDocument* pv = new CFramerDocument(_dwNumDocs++);
    if (pv == NULL) return FALSE;

 // If the user chooses New from toolbar, we'll try to create a new
 // object of the same type the user is currently working with, so
 // get the CLSID for the active object...
   if ((wDocType == IDM_FILENEW) && (_pipaobj))
   {
      IPersist* ppst = NULL;
      if (SUCCEEDED(_pipaobj->QueryInterface(IID_IPersist, (void**)&ppst)))
      {
         ppst->GetClassID(&clsid);
         ppst->Release();
         fHaveCLSID = TRUE;
      }
   }

 // If we can create the child window to the MDI frame...
    if (pv->CreateDocWindow(_hwndMDI))
    {
      BOOL bSuccess = TRUE;
        switch (wDocType)
        {
        case IDM_FILENEW_EXCEL:
            bSuccess = pv->CreateNewDocObject(CLSID_EXCELWORKBOOK);
            break;

        case IDM_FILENEW_EXCELCHART:
            bSuccess = pv->CreateNewDocObject(CLSID_EXCELCHART);
            break;

        case IDM_FILENEW_PPT:
            bSuccess = pv->CreateNewDocObject(CLSID_PPTPRESENTATION);
            break;

        case IDM_FILENEW_WORD:
            bSuccess = pv->CreateNewDocObject(CLSID_WORDDOCUMENT);
            break;

        case IDM_FILENEW:
         if (fHaveCLSID)
            bSuccess = pv->CreateNewDocObject(clsid);

      // fall through to default - create debug window...
        }

     // If we have a doc object, show the window and return TRUE...
        if (bSuccess)
        {
            pv->ShowDocWindow();
            return TRUE;
        }

    }

  // If here, we failed for some reason - notify the user...
    MessageBox(_hwndApp, "Cannot create a new object!", "New", MB_ICONHAND);
   pv->CloseDocWindow();
    return FALSE;

}



STDMETHODIMP_(BOOL) CFramerDocument::CreateDocWindow(HWND hwndMDIClient)
{
    //TRACE1("CFramerDocument[%d]::CreateDocWindow()\n", _dwDocId);

   MDICREATESTRUCT mdic; ZeroMemory(&mdic, sizeof(MDICREATESTRUCT));
    CHAR szDocName[50];
    wsprintf(szDocName, "Document%d", _dwDocId);

    HRESULT hr = CreateBindCtx(0, &_pbctx);
    if (FAILED(hr)) return FALSE;

    hr = StgCreateDocfile(NULL, STGM_TRANSACTED | STGM_READWRITE | STGM_SHARE_EXCLUSIVE |
                                STGM_CREATE | STGM_DELETEONRELEASE, 0, &_pstgfile);

    if (FAILED(hr)){_pbctx->Release(); return FALSE;}

    mdic.szClass = "SingleDocHandle";
    mdic.szTitle = szDocName;
    mdic.hOwner  = g_hInstance;
    mdic.lParam = (LPARAM)this;

    _hwndMDI = hwndMDIClient;

    _hwndDoc = (HWND)SendMessage(_hwndMDI, WM_MDICREATE, 0, (LPARAM)(LPMDICREATESTRUCT)&mdic);
    if (NULL == _hwndDoc) return FALSE;

    ShowWindow(_hwndDoc, SW_HIDE);

    _bstrDocName = ConvertToBSTR(szDocName);

   return TRUE;
}



STDMETHODIMP_(BOOL) CFramerDocument::ShowDocWindow()
{
  // If we have an OLE object, but haven't yet gone
  // inplace active, go inplace first...
    if ((_poleobj) && (!_pipobj))
        IPActivateView();

  // If the window is hidden, make it visible...
    if (!_fVisible)
    {
        ShowWindow(_hwndDoc, SW_SHOWNORMAL);
        _fVisible = TRUE;
    }

  // Update windows...
    RedrawWindow(_hwndDoc, NULL, NULL, RDW_INVALIDATE | RDW_FRAME);
    InvalidateRect(_hwndMDI, NULL, TRUE);
    UpdateWindow(_hwndMDI);

  // Set the window name for the MDI child window...
    UpdateTitleBar();

    return TRUE;
}



In questo modo mi apre un documento vuoto di testo..
io invece vorrei caricare un form che ho gia creato, che sia figlio del form principale e che però mi permetta di caricare anche un secondo form figlio



Se qualcuno sa darmi un mano mi fa un grandissimo piacere, vanno bene anche dei link..


Grazie a tutti!
Top
Profilo Invia messaggio privato
Mostra prima i messaggi di:   
Nuovo argomento   Rispondi    Indice del forum -> Programmazione Tutti i fusi orari sono GMT + 1 ora
Pagina 1 di 1

 
Vai a:  
Non puoi inserire nuovi argomenti
Non puoi rispondere a nessun argomento
Non puoi modificare i tuoi messaggi
Non puoi cancellare i tuoi messaggi
Non puoi votare nei sondaggi