|
-
Jan 23rd, 2006, 08:25 AM
#1
Thread Starter
Member
Why this doesn't work !!!???
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.
-
Jan 28th, 2006, 06:52 PM
#2
Lively Member
Re: Why this doesn't work !!!???
Dont use this code in UserForm_Initialize. This is before form shows up. Use it for example in UserForm_Click().
"bla, bla,... exists number M so for each n > M bla, bla..." Exists? Where is it? (Kronecker said...)
-
Jan 29th, 2006, 05:25 AM
#3
Re: Why this doesn't work !!!???
3 things to change, just give it a try:
firstly: cut the code from under Initialize event and paste it in either UserForm_Load event or Under _click event as suggested by bilm_ks.
second, in VB Dim lhwnd, hdc, mWnd As Long lhwmd and hdc are not of Long type. in VB, they are now Variant type. Use
VB Code:
Dim lhwnd As Long, hdc As Long, mWnd As Long
and Third, hdc is a native variable name, so you cannot use it. instead use
VB Code:
Dim lhwnd As Long, [hl]myhdc[/hl] As Long, mWnd As Long
(replace all hdc with mhdc in your code)
Harsh Gupta
Last edited by Harsh Gupta; Jan 30th, 2006 at 07:58 AM.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|