Bild in SDI-Anwendung laden



  • Tag,

    ich habe noch eine Frage für heute:

    void CDispBmpDoc::Serialize(CArchive& ar)
    {
    	if (ar.IsStoring())
    	{
    		// TODO: add storing code here
    	}
    	else
    	{
            if (m_hBitmap != NULL)
                ::DeleteObject(m_hBitmap);
    		stringstream name;
    
    		name << ORDNER << "/bild0001.bmp";
            m_hBitmap = (HBITMAP)::LoadImage(0,ar.m_strFileName,
                                            IMAGE_BITMAP,0,0,LR_LOADFROMFILE);
            if (m_hBitmap==NULL) AfxMessageBox(_T("Kann Bitmap nicht öffnen!"),MB_OK);
    	}
    }
    

    Dieser Code funktioniert ok. Nun will ich aber keine User-Abfrage machen, sondern das Programm soll automatisch das Bild in 'name' hochladen, ohne dass das Eingabefenster erscheint.

    Wie funktioniert das?

    DANKE.
    H.W.


  • Mod

    Was meinst Du damit?
    Eine "User-Abfrage" nach dem Namen der zu speichernden Datei oder was?

    Du müsstest einfach OnFileSave überschreiben.



  • Martin Richter schrieb:

    Was meinst Du damit?
    Eine "User-Abfrage" nach dem Namen der zu speichernden Datei oder was?

    Ich meine, dass das Bild in 'name' automatisch hochgeladen werden soll, ohne dass der User darauf einen Einfluß hat. So wie es jetzt ist, ist zu Beginn der Hintergrund weiss. Erst wenn ich in meiner SDI-Anwendung auf 'File Open' gehe, dann kann der User irgendein BMP auswählen. Das brauche ich aber für meine Anwendung nicht.

    Vielen Dank.
    H.W.



  • schau mal hier nach:
    http://www.functionx.com/visualc/views/DisplayBitmap.htm

    void CShowPicture1View::OnDraw(CDC* pDC)
    {
    	CShowPicture1Doc* pDoc = GetDocument();
    	ASSERT_VALID(pDoc);
    	if (!pDoc)
    		return;
    
    	strFilename = "C:/IRGENDWO/img0000.bmp";
    
    	if(strFilename != "" )
    	{
    		BITMAP bmpProperties;
    
    		// Create a bitmap handle using the name of the file
    		HBITMAP bmpHandle = (HBITMAP)LoadImage(NULL,strFilename,IMAGE_BITMAP,0,0,LR_LOADFROMFILE);
    
    		CBitmap bmpPicture;
    		CDC mdcPicture;
    
    		// Convert the Win32 bitmap handle into an MFC bitmap object
    		CBitmap *bmpFromHandle = bmpPicture.FromHandle(bmpHandle);
    		bmpPicture.Attach(bmpHandle);
    
    		// Call the Win32 GetObject() function to get the properties of the bitmap and store them in a BITMAP structure
    		::GetObject(bmpPicture,sizeof(bmpProperties),&bmpProperties);
    
    		// Create a compatible device context
    		mdcPicture.CreateCompatibleDC(pDC);
    		// Select the bitmap into the device context
    		CBitmap * bmpPrevious = mdcPicture.SelectObject(bmpFromHandle);
    
    		// Using the dimensions store in the BITMAP object, // display the picture
    		pDC->BitBlt(0, 0,bmpProperties.bmWidth, bmpProperties.bmHeight, &mdcPicture, 0, 0, SRCCOPY);
    
    		// Get the dimensions of the new picture
    		SIZE sizeTotal;
    		sizeTotal.cx = bmpProperties.bmWidth;
    		sizeTotal.cy = bmpProperties.bmHeight;
    		// Change the scrolling area/dimensions of the view
    		SetScrollSizes(MM_TEXT, sizeTotal);
    
    		// Restore the bitmap
    		pDC->SelectObject(bmpPrevious);
    		// Delete the Win32 bitmap handle
    		DeleteObject(bmpHandle);
    	}
    }
    

  • Mod

    Dann platziere doch in OnFileNew den entsprechenden Code. Oder wenn das Dein leeres Dokument ist verwende DeleteContents obwohl das schon wieder unsinnig scheint.


Anmelden zum Antworten