dbTalk Databases Forums  

Dump a subform to paint

comp.databases.ms-access comp.databases.ms-access


Discuss Dump a subform to paint in the comp.databases.ms-access forum.



Reply
 
Thread Tools Display Modes
  #1  
Old   
Phil
 
Posts: n/a

Default Dump a subform to paint - 04-05-2011 , 05:02 AM






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

Reply With Quote
  #2  
Old   
zuckermanf@gmail.com
 
Posts: n/a

Default Re: Dump a subform to paint - 04-05-2011 , 09:55 AM






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:
Quote:
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

Reply With Quote
  #3  
Old   
The Frog
 
Posts: n/a

Default Re: Dump a subform to paint - 04-05-2011 , 10:29 AM



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

Reply With Quote
  #4  
Old   
Phil
 
Posts: n/a

Default Re: Dump a subform to paint - 04-05-2011 , 12:00 PM



On 05/04/2011 16:29:16, The Frog wrote:
Quote:
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 to the
clipboard. I don't want the surrounding main form or Access window Phil

Reply With Quote
  #5  
Old   
Phil
 
Posts: n/a

Default Re: Dump a subform to paint - 04-05-2011 , 12:04 PM



On 05/04/2011 15:55:26, "zuckermanf (AT) gmail (DOT) com" wrote:
Quote:
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

Thanks, but I am trying to prevent an operator messing around with cropping
etc. Just want to copy my subform to the clipboard, paste it into paint, and
probably print it, all automatically. Phil

Reply With Quote
  #6  
Old   
The Frog
 
Posts: n/a

Default Re: Dump a subform to paint - 04-06-2011 , 02:25 AM



Hi Phil,

Have you tried getting the sub forms handle by using something like
this:

Private Sub Form_Load()
dim h as Long
h=Me.hWnd
End Sub

I would swap out the h variable with something a little more easily
accessable like a global var that you can play with, as long as it is
declared as a Long. When the sub form loads the variable is set, and
you substitute that variable in place of the Access.hWnd result (which
you no longer need). Its a simple fix that might just do the job.
Looking briefly at the code you have it should most likely work
without issue (I think - I am not a GDI expert by any stretch but my
understanding is ok and the logic in your code seems pretty clear for
doing a simple bit blit screen grab).

The trick here will be to set the globally available variable with the
handle that you obtain during the subforms load event. Once that is
done you should be able to use the rest of the code (substituting out
the Access handle) without issue.

Cheers

The Frog

Reply With Quote
  #7  
Old   
imb
 
Posts: n/a

Default Re: Dump a subform to paint - 04-06-2011 , 03:08 AM



On Apr 5, 7:00*pm, "Phil" <p... (AT) stantonfamily (DOT) co.uk> wrote:
Quote:
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 -
Hi Phil,

Just a thought. Can you start the Subform3 on its own instead as a
subform of Form2?


Imb.

Reply With Quote
  #8  
Old   
JHB
 
Posts: n/a

Default Re: Dump a subform to paint - 04-06-2011 , 07:15 AM



Hi Phil.

If you have a button on the Form2, you have to change the code from
AccessHwnd = GetActiveWindow()
to
AccessHwnd = Me.Controls("Form3").Form.Hwnd

Regards
Jørn

"Phil" <phil (AT) stantonfamily (DOT) co.uk> skrev i en meddelelse
news:inepcg$6ud$1 (AT) speranza (DOT) aioe.org...
Quote:
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

Reply With Quote
  #9  
Old   
Phil
 
Posts: n/a

Default Re: Dump a subform to paint - 04-06-2011 , 09:00 AM



On 06/04/2011 13:15:27, "JHB" wrote:
Quote:
AccessHwnd = Me.Controls("Form3").Form.Hwnd
Thanks to you and The Frog who both came up with the same solution.
Perfect
It now means I have a form with transparent labels at all sorts of angles
that I can drag around the form, rotate them, doesn't matter if they overlap
all in form view.

Thanks 10^9

Phil

Reply With Quote
Reply




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.3
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.