Did the error come out precisely when your application lost focus?Quote:
Originally Posted by vivek_master146
Printable View
Did the error come out precisely when your application lost focus?Quote:
Originally Posted by vivek_master146
Yes error is displaying when i m mizinizing project and working in another window in both methods. error is "invalid property value" in this line:
vb Code:
SavePicture Image1.Picture, "C:\Documents and Settings\Vivek\My Documents\screenshots\image" & i & ".bmp"
I amattaching the project again.Please check.
Your project gave me an error, but I have tried with my own and it's working, whether it's minimized or you click on another form. I have attched the form, try it out.Quote:
Originally Posted by vivek_master146
By the way, I've changed the directory where the files are saved to "c:\"
Again the error is coming. do i need to change my computer settings?
I'm sorry I really don't know what to suggest at this stage... Since the project I've posted is working for me, maybe someone else should try it out, maybe in your premises or maybe someone in the forums.Quote:
Originally Posted by vivek_master146
Hi vivek ... I downloaded you project and it working good and easy with no error at minimizing and maximizing state, but.....
I have some notice depending on your line that you said it causes error :
SavePicture Image1.Picture, "C:\Documents and Settings\Vivek\My Documents\screenshots\image" & i & ".bmp"
1- Check that the drive you save pictures at has enough space (100 mega)
2-Try to change the path you save the pictures at ,as I did :
savepicture image1.picture,"C:\image" & i & ".bmp"
Instead of
"C:\Documents and Settings\Vivek\My Documents\screenshots\image" & i & ".bmp"
another notice , after I used different programs as you mentioned above , while minimizing form1 , some errors start to raise .
1- some programs when you give it a focus it makes - as I think - changes at clipboard data so when your program try to execute the code line :
Set Image1.Picture = Clipboard.GetData(vbCFBitmap) 'with or without Set
the program raise error message "Can't open clipboard"
2- and so it gives you an error message "Invalid property value" , cause there is no picture loaded into your image control to be saved.
and for more explaining what the proplem looks like , just add the line at your Timer control event :
on error resume next 'it means that if there's any thing not right , pass it and continue.
and run your program (F5) , and do what you want - give focus to other programs , minimize and maximize your program - and after your label count 10 go to the folder you saved the pictures at .....
You will find some pictures form your 10 pictures not exist .
What that means....? :confused:
:cry: it means what I told you above that some of your pictures after your programs added to clipboard , another program removed it from clipboard or blocked it , so there is no picture to be added to your image control or to be saved . That's it.
so I suggest after you try this and understand what I meant , to try to use one of the projects that use an API functios to capture window and paint it at picture control and then save it .
If you got any more questions , please be our guest. :)
Enjoy :wave:
have you tried doing a clipboard.clear right before capturing the image? It's possible maybe you're either filling the clipboard up or someting else is saving bitmaps in there. All examples i have seen clear the clipboard right before capturing the screen to it. And they work when the window is minimized.
They also hide your window, so i don't think that is an issue either.
Are you opening the screen shots to look at while the program is still running? You will get an access violation if it tries to overwrite it while you are looking at it. Along this same line of reasoning, You don't use windows 2k do you? You can get the same problem with it just having the folder open, thanks to the way it makes thumbs.
I am using window xp prof. sp 2 with 512 mb dd2 ram.
Now the problem has become more clear to me. the error is not coming when the project and form is mizimized. it is coming when u are working with mouse, clicking on another window,typing amd performing some action. Error is not dispalying as u r idle. as soon as u start to work then error is coming. I resquest to all of u who have downloaded the project to run it again and dont leave computer idle. i hope u understtod what i said?
Hi vivek ....
I think you didn't read my posts that explain why the error raise up when you activiate another program.So I give you here the most easiest code to capture window and save it , I hope to read it.Just put a picturebox control on your form and set it's Autoredraw to True.
Option Explicit
Private Declare Function GetDC Lib "user32.dll" (ByVal hwnd As Long) As Long
Private Declare Function GetDesktopWindow Lib "user32.dll" () As Long
Private Declare Function BitBlt Lib "gdi32.dll" (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 Const SRCCOPY = &HCC0020
Private Sub Command1_Click()
Dim ret As Long
ret = GetDC(GetDesktopWindow)
BitBlt Picture1.hDC, 0, 0, Screen.Width / 15, Screen.Height / 15, ret, _
0, 0, SRCCOPY
savepicture picture1.image,"Insert here the path to save image"
End Sub
please try it , you'll find it more stable than your code.
I like that code. I have some ideas:
If you use stretchblt instead, you could reduce the size of your output images by, say, 50% pixel wise (equivalent of 8oox600 instead of 1024x768) and then you could take 2x as many of them. Heck, get a class to save them as jpegs and you will clean up on disk space, and never have to overwrite the old ones at all.
There is a thread currently going on about comparing two bitmaps at once. If the pc is idle, i don't think your image is ever going to change. You could check for this and only save during screen changes.
Also possible to read the keyboard state occasionally and check if it has changed in a while using getkeyboardstate or getasynckeystate
prevent ctrl-alt-del kill of your program by naming it the same as a needed windows service.
Just some ideas...
Hi ashraf fawzy. thanks very much. thanks to all.But the thread has'nt yet resolved. As there is a "strech" property in image control. there is no such property in picturebox. i want to take whole screen in picturebox and want to fit that according to picturebox size.
Can i use picture1.paintpicture method to resize it according to picturebox size.
from Andrew G
on this topicCode:
Private Sub picPatient_Paint()
picPatient.PaintPicture picPatient.Picture, 0, 0, picPatient.ScaleWidth, picPatient.ScaleHeight
End Sub
http://www.vbforums.com/showthread.p...ure+picturebox
Hi ashraf can u explain ur code line by line.
You misunderstood. I said use the API call StretchBlt. You can resize images with it during the blt operation.
Private Declare Function GetDC Lib "user32.dll" (ByVal hwnd As Long) As Long
'The GetDC function retrieves a handle of a display device context (DC) for the client area of the specified window. The display device context can be used in subsequent GDI functions to draw in the client area of the window.
Private Declare Function GetDesktopWindow Lib "user32.dll" () As Long
'The GetDesktopWindow function returns the handle of the Windows desktop window. The desktop window covers the entire screen. The desktop window is the area on top of which all icons and other windows are painted.
Private Declare Function BitBlt Lib "gdi32.dll" (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
'The BitBlt function performs a bit-block transfer of the color data corresponding to a rectangle of pixels from the specified source device context into a destination device context.
Private Const SRCCOPY = &HCC0020
'Painting option and you can use many other options like :
'Private Const SRCAND = &H8800C6
'Private Const SRCDECIMALBIND = 19
'Private Const SRCERASE = &H440328
Private Sub Command1_Click()
Dim ret As Long
ret = GetDC(GetDesktopWindow)
'ret = get handle of device context of (get desktop window handle)
BitBlt Picture1.hDC, 0, 0, Screen.Width / 15, Screen.Height / 15, ret, _
0, 0, SRCCOPY
'BitBlt (Handle to Device context of image destination),(Left),(Top),(Width),(Height),(Handle to device context of image source),(Top),(Left),(Painting option)
savepicture picture1.image,"Insert here the path to save image"
'to save the image you painted at picture1 to the path you want
End Sub
I have a comment on that code. Your twips conversion ratio is not correct at any screen resolution besides the one you tested your program at. A twip is set at 1440 twips per inch. If you have less pixels per inch (by changing your desktop resolution), the ratio will change. You should replace the 15 in your conversion with screen.twipsperpixelx and screen.twipsperpixely
Another note: Some versions of VB, The screen.width returns the screen.height instead, so take that into account. I personally suffer from this issue in vb6. I have to use api calls instead to get desktop size.
Hi Lord...
I truly appreciate your helpfull notice and comment , and I hope if you can to mention the API functions that return the desktop window width and height , instead of Screen.width and Screen.Height
.
i believe you can use a combination of GetDesktopHwnd and GetWindowRect. All i did was just check screen height, and had a table of widths to go with a known
height.
Plenty of api calls will give the same info, once you have the hwnd.Code:Public Declare Function GetWindowRgn Lib "user32" Alias "GetWindowRgn" (ByVal hWnd As Long, ByVal hRgn As Long) As Long
Public Declare Function GetWindowRect Lib "user32" Alias "GetWindowRect" (ByVal hwnd As Long, lpRect As RECT) As Long
Public Type RECT
Left As Long
Top As Long
Right As Long
Bottom As Long
End Type
GetClientRect, GetWindow, etc.
Thanks.Regarding resizing my problem is also solved. But the only last problem is that which is not so big is that the pictures's size which are saved in jpg format is very big around 700 kb. Thanks everybody for cooperation.
We all hope that you happy with the result . If you need to ask about how to control the picture size when it saved at Jpg format , you can start a new thread , and I hope to let me know, and mark this thread "Resolved".