Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Capture Image from WMP to Image Control 1

Status
Not open for further replies.

porto99

Technical User
Nov 1, 2004
96
GB
In my VB program I have a WindowsMediaPlayer1 object and an Image1 control and a button that executes the following command:-

Private Sub Scan_Click()

Image1.Picture = Clipboard.GetData(vbCFBitmap)

End Sub

So basically what I want to do is press the <b>Print Scrn</b> button and then press the scan push button on my form to copy the Clipboard onto the Image control.

Now the problem is all I want the clipboard to contain is the image at that instance on the Media Player.

Currently I get the whole desktop.

Are they anyway I can limit the clipboard to just capture the WMP image.

The next step would be the have the Scan button 'press' the <b>Print Scrn</b> button and then

Image1.Picture = Clipboard.GetData(vbCFBitmap)

Many thanks,

Porto.
 
You can use the PrintWindow API function. (Windows XP and later.)
___
[tt]
Option Explicit
Private Declare Function PrintWindow Lib "user32" (ByVal hWnd As Long, ByVal hdcBlt As Long, ByVal nFlags As Long) As Long
Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long
Private Sub Form_Load()
Dim hWndWMP As Long
Me.AutoRedraw = True
hWndWMP = FindWindow("WMPlayerApp", "Windows Media Player")
PrintWindow hWndWMP, Me.hDC, 0
End Sub[/tt]
____

For other windows, you can use the following code.
___
[tt]
Option Explicit
Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long
Private Declare Function GetWindowRect Lib "user32" (ByVal hwnd As Long, lpRect As RECT) As Long
Private Declare Function GetWindowDC Lib "user32" (ByVal hwnd As Long) As Long
Private 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
Private Declare Function ReleaseDC Lib "user32" (ByVal hwnd As Long, ByVal hdc As Long) As Long
Private Type RECT
Left As Long
Top As Long
Right As Long
Bottom As Long
End Type
Private Sub Form_Load()
Dim hWndWMP As Long, hDCWMP As Long, rc As RECT
Me.AutoRedraw = True
hWndWMP = FindWindow("WMPlayerApp", "Windows Media Player")
hDCWMP = GetWindowDC(hWndWMP)
GetWindowRect hWndWMP, rc
BitBlt Me.hdc, 0, 0, rc.Right - rc.Left, rc.Bottom - rc.Top, hDCWMP, 0, 0, vbSrcCopy
ReleaseDC hWndWMP, hDCWMP
End Sub[/tt]
___

Note that the PrintWindow function has a big advantage that it does not require the Windows Media Player to be visible on screen.
Also, you don't need to press the Print Screen key for both cases.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top