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:
  1. Private Declare Function PrintWindow Lib "user32" _
  2. (ByVal hwnd As Long, ByVal hdcBlt As Long, ByVal nFlags As Long) As Long
  3.  
  4. Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" _
  5. (ByVal lpClassName As String, ByVal lpWindowName As String) As Long
  6.  
  7. Private Declare Function ReleaseDC Lib "user32" _
  8. (ByVal hwnd As Long, ByVal hdc As Long) As Long
  9.  
  10. Private Declare Function GetDC Lib "user32" (ByVal hwnd As Long) As Long
  11.  
  12. Dim lhwnd, hdc, mWnd As Long
  13.  
  14.  
  15. Private Sub UserForm_Initialize()
  16.  
  17.     lhwnd = FindWindow(vbNullString, Me.Caption)
  18.     hdc = GetDC(lhwnd)
  19.  
  20.     'KPD-Team 2001
  21.     'URL: [url]http://www.allapi.net/[/url]
  22.     'E-Mail: [email][email protected][/email]
  23.     'launch notepad
  24.     Shell "notepad.exe", vbNormalNoFocus
  25.     DoEvents
  26.  
  27.     'search the handle of the notepad window
  28.     mWnd = FindWindow("Notepad", vbNullString)
  29.     If mWnd = 0 Then
  30.        MsgBox "NotePad window not found!"
  31.     Else
  32.         'draw the image of the notepad window on our form
  33.         PrintWindow mWnd, hdc, 0
  34.     End If
  35.  
  36.  
  37. End Sub
  38.  
  39. Private Sub UserForm_Terminate()
  40.  
  41.     ReleaseDC lhwnd, hdc
  42.  
  43. End Sub

Any takers ?

Regards.