![]() | |
![]() |
| | Thread Tools | Display Modes |
#1
| |||
| |||
|
#2
| |||
| |||
|
|
I need to save a subform to MS paint. Background. I want to be able to print transparent images (with writing on them). I can create the transparent images on a form OK, and also on a report in Design view. However, due to a bug??? in Access 2010, when the report is in print preview the images become opaque. So I have partially got out of the problem by dumping the picture to the Clipboard, and pasting it into paint. Prints perfectly from there. My problem is that I am saving the whole screen to the clipboard, whereas I want to save just a subform which has all the images on it. Sorry - lot of code, much of which I don't understand. Can anyone suggestthe modifications to save only Subform3 which is a sub form of Form2 Thanks Phil 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 lare Sub GetWindowRect Lib "User32" (ByVal Hwnd As Long, lpRect As RECT_Type) Declare Function GetDC Lib "User32" (ByVal Hwnd As Long) As Long Declare lare 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 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 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 Private Sub Output_Click() * * Dim Paint As Integer * * On Error GoTo Output_Click_Error * * ScreenDump * * * * * * * * *' Dump form to clipboard * * * ' Paint * * Paint = Shell("C:\Windows\System32\MSPaint.Exe", vbNormalFocus) * * DoEvents Activate: * * Call apWait(1, True) * * AppActivate Paint, False * * DoEvents * * SendKeys "^v" * * Exit Sub Output_Click_Error: * * If Err = 5 Then * * * * * * * * * * ' Invalid procedure call or argument * * * * Resume Activate * * Else MsgBox MsgBox "Error " & Err.Number & " (" & Err.Description & ") in procedure Output_Click of VBA Document Form_Form3" * * End If End Sub |
#3
| |||
| |||
|
#4
| |||
| |||
|
|
Hi Phil, When you say images, are you referring to pictures displayed on the subform that you have previously stored in the database and are dynamically retrieving on a per record basis (ie/ stored BLOB's)? Or is this a fixed set of images like a company logo and such that doesnt change? I am trying to work through the problem you are having and thinking that if they are stored images then it might simply be easier to copy the picture to an iPicture object and then just paste that into MS Paint. The way I see it, the only shortcut you might be able to find would be if you can get the handle to the subform, figure out its position, and grab screen from there. All API stuff but you seem OK handling that. At the moment you are using the Access handle to generate your GDI handle, which in theory would provide a window size that is the same as whatever Access is currently using as screen real-estate. I havent tried this but perhaps by acquiring the subforms handle it could be done. So how do you get the subforms handle? I would have to have a play with that and see as I have not tried it directly. GDI can be a tricky little beast at times...... Cheers The Frog |
#5
| |||
| |||
|
|
Don't forget that the Paint software lets you crop the image and remove the screen edges (including the taskbar, toolbars, etc). You can even enlarge the image. Fred On Apr 5, 3:02*am, "Phil" <p... (AT) stantonfamily (DOT) co.uk> wrote: I need to save a subform to MS paint. Background. I want to be able to print transparent images (with writing o n them). I can create the transparent images on a form OK, and also on a re port in Design view. However, due to a bug??? in Access 2010, when the report is in print preview the images become opaque. So I have partially got out of the problem by dumping the picture to the Clipboard, and pasting it into paint. Prints perfectly from there. My pro blem is that I am saving the whole screen to the clipboard, whereas I want to save just a subform which has all the images on it. Sorry - lot of code, much of which I don't understand. Can anyone suggest the modifications to save only Subform3 which is a sub form of Form2 Thanks Phil |
#6
| |||
| |||
|
#7
| |||
| |||
|
|
On 05/04/2011 16:29:16, The Frog wrote: Hi Phil, When you say images, are you referring to pictures displayed on the subform that you have previously stored in the database and are dynamically retrieving on a per record basis (ie/ stored BLOB's)? Or is this a fixed set of images like a company logo and such that doesnt change? I am trying to work through the problem you are having and thinking that if they are stored images then it might simply be easier to copy the picture to an iPicture object and then just paste that into MS Paint. The way I see it, the only shortcut you might be able to find would be if you can get the handle to the subform, figure out its position, and grab screen from there. All API stuff but you seem OK handling that. At the moment you are using the Access handle to generate your GDI handle, which in theory would provide a window size that is the same as whatever Access is currently using as screen real-estate. I havent tried this but perhaps by acquiring the subforms handle it could be done. So how do you get the subforms handle? I would have to have a play with that and see as I have not tried it directly. GDI can be a tricky little beast at times...... Cheers The Frog Thanks for coming back. The subform contains up to 120 images which are generated using a program called imagemagick. The subform displays all the images after the OnCurrent event. The routine I described in the original posting saves the whole Access window to the Clipboard which I then paste to paint. As you suggest, I need the handle to the Subform as is, complete with images which I can save tothe clipboard. I don't want the surrounding main form or Access window Phil- Hide quoted text - - Show quoted text - |
#8
| |||
| |||
|
|
I need to save a subform to MS paint. Background. I want to be able to print transparent images (with writing on them). I can create the transparent images on a form OK, and also on a report in Design view. However, due to a bug??? in Access 2010, when the report is in print preview the images become opaque. So I have partially got out of the problem by dumping the picture to the Clipboard, and pasting it into paint. Prints perfectly from there. My problem is that I am saving the whole screen to the clipboard, whereas I want to save just a subform which has all the images on it. Sorry - lot of code, much of which I don't understand. Can anyone suggest the modifications to save only Subform3 which is a sub form of Form2 Thanks Phil 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 lare Sub GetWindowRect Lib "User32" (ByVal Hwnd As Long, lpRect As RECT_Type) Declare Function GetDC Lib "User32" (ByVal Hwnd As Long) As Long Declare lare 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 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 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 Private Sub Output_Click() Dim Paint As Integer On Error GoTo Output_Click_Error ScreenDump ' Dump form to clipboard ' Paint Paint = Shell("C:\Windows\System32\MSPaint.Exe", vbNormalFocus) DoEvents Activate: Call apWait(1, True) AppActivate Paint, False DoEvents SendKeys "^v" Exit Sub Output_Click_Error: If Err = 5 Then ' Invalid procedure call or argument Resume Activate Else MsgBox MsgBox "Error " & Err.Number & " (" & Err.Description & ") in procedure Output_Click of VBA Document Form_Form3" End If End Sub |
#9
| |||
| |||
|
|
AccessHwnd = Me.Controls("Form3").Form.Hwnd |
![]() |
| Thread Tools | |
| Display Modes | |
| |