Hi ,
I am trying to draw the image of the NotePad Window on an Excel UserForm DC via the PrintWindow API function But the code below doesn't work
Can anyone spot where the problem is or if I am missing something ?
VB Code:
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 Declare Function ReleaseDC Lib "user32" _
(ByVal hwnd As Long, ByVal hdc As Long) As Long
Private Declare Function GetDC Lib "user32" (ByVal hwnd As Long) As Long
Dim lhwnd, hdc, mWnd As Long
Private Sub UserForm_Initialize()
lhwnd = FindWindow(vbNullString, Me.Caption)
hdc = GetDC(lhwnd)
'KPD-Team 2001
'URL: [url]http://www.allapi.net/[/url]
'launch notepad
Shell "notepad.exe", vbNormalNoFocus
DoEvents
'search the handle of the notepad window
mWnd = FindWindow("Notepad", vbNullString)
If mWnd = 0 Then
MsgBox "NotePad window not found!"
Else
'draw the image of the notepad window on our form
PrintWindow mWnd, hdc, 0
End If
End Sub
Private Sub UserForm_Terminate()
ReleaseDC lhwnd, hdc
End Sub
Any takers ?
Regards.