YOU CAN CODE!

 

With The Case Of UCanCode.net  Release The Power OF  Visual C++ !   HomeProducts | PurchaseSupport | Downloads  
Download Evaluation
Pricing & Purchase?
E-XD++Visual C++/ MFC Products
Overview
Features Tour 
Electronic Form Solution
Visualization & HMI Solution
Power system HMI Solution
CAD Drawing and Printing Solution

Bar code labeling Solution
Workflow Solution

Coal industry HMI Solution
Instrumentation Gauge Solution

Report Printing Solution
Graphical modeling Solution
GIS mapping solution

Visio graphics solution
Industrial control SCADA &HMI Solution
BPM business process Solution

Industrial monitoring Solution
Flowchart and diagramming Solution
Organization Diagram Solution

Graphic editor Source Code
UML drawing editor Source Code
Map Diagramming Solution

Architectural Graphic Drawing Solution
Request Evaluation
Purchase
ActiveX COM Products
Overview
Download
Purchase
Technical Support
  General Q & A
Discussion Board
Contact Us

Links

Get Ready to Unleash the Power of UCanCode .NET

 


UCanCode Software focuses on general application software development. We provide complete solution for developers. No matter you want to develop a simple database workflow application, or an large flow/diagram based system, our product will provide a complete solution for you. Our product had been used by hundreds of top companies around the world!

"100% source code provided! Free you from not daring to use components because of unable to master the key technology of components!"


VC++ MFC Example: Clipboard on CF_DIB, CF_METAFILEPICT, OpenClipboard, GetClipboardData, CloseClipboard

 
 

Introduction

If you want to display a bitmap from the clipboard which is in the CF_DIB format in one of my applications.  Also, all the other clipboard articles here had code to write CF_DIB to the clipboard, but not read it. So the following codes will be very useful.

Collapse

// pDC is the DC to draw to
// metafile is a CRect to display the DIB/Metafile in
    CRect    metafile(0, 0, 100, 100);    // example location
    if (IsClipboardFormatAvailable(CF_METAFILEPICT))
    {
        // play a metafile from the clipboard if available
        GLOBALHANDLE    hGMem ;
        LPMETAFILEPICT    lpMFP ;
        OpenClipboard() ;
        hGMem = GetClipboardData(CF_METAFILEPICT) ;
        lpMFP = (LPMETAFILEPICT)GlobalLock(hGMem) ;
        pDC->SaveDC() ;
        pDC->SetMapMode(lpMFP->mm) ;
        pDC->SetViewportExt(metafile.Width(), metafile.Height()) ;
        pDC->SetViewportOrg(metafile.left, metafile.top) ;
        pDC->PlayMetaFile(lpMFP->hMF) ;
        VERIFY(pDC->RestoreDC(-1)) ;
        GlobalUnlock(hGMem) ;
        CloseClipboard() ;
    }
    if (IsClipboardFormatAvailable(CF_DIB))
    {
        // a DIB is in the clipboard, draw it out
        GLOBALHANDLE    hGMem ;
        LPBITMAPINFO    lpBI ;
        void*            pDIBBits;
    
        OpenClipboard() ;
        hGMem = GetClipboardData(CF_DIB) ;
        lpBI = (LPBITMAPINFO)GlobalLock(hGMem) ;
        // point to DIB bits after BITMAPINFO object
        pDIBBits = (void*)(lpBI + 1); 
        ::StretchDIBits(pDC->m_hDC,
            metafile.left, metafile.top, 
            metafile.Width(), metafile.Height(),
            0, 0, lpBI->bmiHeader.biWidth, 
            lpBI->bmiHeader.biHeight,
            pDIBBits, lpBI, DIB_RGB_COLORS, SRCCOPY);
        GlobalUnlock(hGMem) ;
        CloseClipboard() ;
    }

 

Copyright ?1998-2022 UCanCode.Net Software , all rights reserved.
Other product and company names herein may be the trademarks of their respective owners.

Please direct your questions or comments to webmaster@ucancode.net