Solved

Save view as Bitmap

Posted on 2003-12-08
2
250 Views
Last Modified: 2013-12-03
Does anyone know how to capture the view in a SDI application and save it as a bitmap?

Thank you.
  Mazen
0
Comment
Question by:Mazen
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 86

Accepted Solution

by:
jkr earned 500 total points
ID: 9896973
See http://www.codeguru.com/bitmap/window_to_file.shtml ("Writing a window image to a BMP file")
0
 
LVL 44

Expert Comment

by:AndyAinscow
ID: 9897021
I found this in the help files - its a basic routine.  It should be easy enough to understand (and convert to MFC).  All you need to do is not paste to clipboard but to put it into a bitmap (selected into the memoryDC) and then save that to disk.

Option Compare Database
   Option Explicit
 
   Type RECT_Type
 
      left As Long
      top As Long
      right As Long
      bottom As Long
 
   End Type

   'The following declare statements are case sensitive.

   Declare Function GetActiveWindow Lib "User32" () As Long
   Declare Function GetDesktopWindow Lib "User32" () As Long
   Declare Sub GetWindowRect Lib "User32" (ByVal Hwnd As Long, _
                                       lpRect As RECT_Type)
   Declare Function GetDC Lib "User32" (ByVal Hwnd As Long) As Long
   Declare Function CreateCompatibleDC Lib "Gdi32" (ByVal hdc As Long) _
                                       As Long
   Declare Function CreateCompatibleBitmap Lib "Gdi32" (ByVal hdc _
                                       As Long, ByVal nWidth As Long, _
                                       ByVal nHeight As Long) As Long
   Declare Function SelectObject Lib "Gdi32" (ByVal hdc As Long, _
                                       ByVal hObject As Long) As Long
   Declare Function BitBlt Lib "Gdi32" (ByVal hDestDC As Long, _
                                       ByVal X As Long, ByVal Y _
                                       As Long, ByVal nWidth As Long, _
                                       ByVal nHeight As Long, _
                                       ByVal hSrcDC As Long, _
                                       ByVal XSrc As Long, _
                                       ByVal YSrc As Long, _
                                       ByVal dwRop As Long) As Long
   Declare Function OpenClipboard Lib "User32" (ByVal Hwnd As Long) As Long
   Declare Function EmptyClipboard Lib "User32" () As Long
   Declare Function SetClipboardData Lib "User32" (ByVal wFormat As Long, _
                                       ByVal hMem As Long) As Long
   Declare Function CloseClipboard Lib "User32" () As Long
   Declare Function ReleaseDC Lib "User32" (ByVal Hwnd As Long, _
                                       ByVal hdc As Long) As Long
   Declare Function DeleteDC Lib "Gdi32" (ByVal hdc As Long) As Long
 
   Global Const SRCCOPY = &HCC0020
   Global Const CF_BITMAP = 2
Code for the ScreenDump() Function:

   Function ScreenDump()
      Dim AccessHwnd As Long, DeskHwnd As Long
      Dim hdc As Long
      Dim hdcMem As Long
      Dim rect As RECT_Type
      Dim junk As Long
      Dim fwidth As Long, fheight As Long
      Dim hBitmap As Long
 
 
      DoCmd.Hourglass True
 
      '---------------------------------------------------
      ' Get window handle to Windows and Microsoft Access
      '---------------------------------------------------
      DeskHwnd = GetDesktopWindow()
      AccessHwnd = GetActiveWindow()
 
      '---------------------------------------------------
      ' Get screen coordinates of Microsoft Access
      '---------------------------------------------------
      Call GetWindowRect(AccessHwnd, rect)
      fwidth = rect.right - rect.left
      fheight = rect.bottom - rect.top
 
      '---------------------------------------------------
      ' Get the device context of Desktop and allocate memory
      '---------------------------------------------------
      hdc = GetDC(DeskHwnd)
      hdcMem = CreateCompatibleDC(hdc)
      hBitmap = CreateCompatibleBitmap(hdc, fwidth, fheight)
 
      If hBitmap <> 0 Then
         junk = SelectObject(hdcMem, hBitmap)
 
         '---------------------------------------------
         ' Copy the Desktop bitmap to memory location
         ' based on Microsoft Access coordinates.
         '---------------------------------------------
         junk = BitBlt(hdcMem, 0, 0, fwidth, fheight, hdc, rect.left, _
                       rect.top, SRCCOPY)
 
         '---------------------------------------------
         ' Set up the Clipboard and copy bitmap
         '---------------------------------------------
         junk = OpenClipboard(DeskHwnd)
         junk = EmptyClipboard()
         junk = SetClipboardData(CF_BITMAP, hBitmap)
         junk = CloseClipboard()
      End If
 
      '---------------------------------------------
      ' Clean up handles
      '---------------------------------------------
      junk = DeleteDC(hdcMem)
      junk = ReleaseDC(DeskHwnd, hdc)
 
      DoCmd.Hourglass False
 
   End Function


0

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Introduction: Ownerdraw of the grid button.  A singleton class implentation and usage. Continuing from the fifth article about sudoku.   Open the project in visual studio. Go to the class view – CGridButton should be visible as a class.  R…
If you use Adobe Reader X it is possible you can't open OLE PDF documents in the standard. The reason is the 'save box mode' in adobe reader X. Many people think the protected Mode of adobe reader x is only to stop the write access. But this fe…
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…

759 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question