|
-
May 25th, 2004, 03:08 PM
#1
Thread Starter
New Member
Computer bogs down RESOLVED
Newbie here,
From VB6 I open a project that has a single form.
I run the program that has a timer that has a 100 interval.
Within the timer code I use a getpixel API call and displays the color number on the form.
It seems to bog the computer down.
For example, I autohide my toolbar at the bottom of my screen.
Normally it smoothly popsup when I place my mouse cursor down to it.
When the program has run for awhile, the toolbar posup, but not very smoothly. It's kind of jerky.
After a while it gets real bad. I move the form and it leaves an image of where its been. Numbers appear in the top righthand corners of open windows.
Its really strange.
Any ideas?
Andy
Last edited by ac3100; Jun 1st, 2004 at 02:20 PM.
-
May 25th, 2004, 03:50 PM
#2
Addicted Member
Put a DoEvents in your timer and increase the interval.
-
May 25th, 2004, 04:19 PM
#3
Thread Starter
New Member
Thanks for the response.
I made the changes and it definitely helped.
Is this a type of program that will eventually deteriorate over time regardless of the timer setting?
Even though I wouldn't want to do this, I guess I could close VB and reopen it when it starts to get bad. I wish there was a way I could "reset" the program so that it starts fresh
Does having VB6 open cause this problem?
If I somehow can run this form without having VB6 open might be better?
Just curious
-
May 25th, 2004, 04:26 PM
#4
Fanatic Member
Motto: Anything for a laugh.
Getting second place only means you are the first loser to cross the finish line.
-
May 25th, 2004, 04:34 PM
#5
Thread Starter
New Member
Option Explicit
Private Declare Function GetDC Lib "user32" (ByVal hwnd As Long) As Long
Private Declare Function GetPixel Lib "gdi32" (ByVal hdc As Long, ByVal x As Long, ByVal y As Long) As Long
Private Declare Function GetCursorPos Lib "user32" (lpPoint As POINTAPI) As Long
Private Type POINTAPI
x As Long
y As Long
End Type
Dim iPoint As POINTAPI
Private Sub Form_Load()
Show
Timer1.Interval = 350
End Sub
Private Sub Timer1_Timer()
Dim pt As POINTAPI
Dim hdc As Long
DoEvents
Call GetCursorPos(pt)
hdc = GetDC(0)
Text1.Text = GetPixel(GetDC(0), pt.x, pt.y)
Text2.Text = pt.x
Text3.Text = pt.y
'test for change in color (Black)
If GetPixel(hdc, 636, 186) = 0 Then
Text4.Text = "Hello!"
Else: Text4.Text = ""
End If
End Sub
You need 4 textboxes and a timer control on form1
-
May 25th, 2004, 04:56 PM
#6
Fanatic Member
The code runs smoothly on my computer. I am running a pentium 4 1.3 ghz. Also maybe you do not have enough virtual memory to handle everything.
If you want to try to run the application outside VB you need to first make it an executable. You can do that by having the project open and then go to File->Make Project.exe. Then it will ask you where you want to build the file, the default is the same directory as the project. After that close VB and go to your project folder and run the exe file.
Quick question though why are you checking to see if the pixel at 636,186 is black? I am not sure but I hope you know that regardless of where you mouse cursor is, if that pixel is black it will always come out true, maybe that is what you want.
Last edited by Maldrid; May 25th, 2004 at 04:59 PM.
Motto: Anything for a laugh.
Getting second place only means you are the first loser to cross the finish line.
-
May 25th, 2004, 05:02 PM
#7
Thread Starter
New Member
I will try it on another computer.
Try setting the interval length to 100.
Let it run for a while and see if it deteriorates.
How do I check for virtual memory?
If virtual memory is a problem how would you fix it?
Andy
-
May 25th, 2004, 05:18 PM
#8
Fanatic Member
You know what you are right. The program does start to really mess up after a while. So let me do some more testing.
For virtual memory you could either buy more, which is ram memory. Or you can use some of your harddrive space. The settings are different depending on the OS you are running, but you can try right click on my computer and looking through the properties to see if you can find it in there. Or looking through your settings in control panel, but regardless of how much memory you have it will eventually run out with this app that you have. So it might last longer but it will still go bad after a while.
I am trying to see if you declare your point type and your handle variable as private to the form instead of in the timer function if it fixes the memory problem.
Motto: Anything for a laugh.
Getting second place only means you are the first loser to cross the finish line.
-
May 25th, 2004, 05:25 PM
#9
Fanatic Member
Ok that did not work. I will keep trying to think of something.
Hopefully someone else can solve this problem for you.
Motto: Anything for a laugh.
Getting second place only means you are the first loser to cross the finish line.
-
May 25th, 2004, 06:18 PM
#10
I believe you've created a memory leak.
Try adding:
Code:
Public Declare Function ReleaseDC Lib "user32" (ByVal hwnd As Long, ByVal hdc As Long) As Long
And then use ReleaseDC before you exit the sub
-
May 25th, 2004, 06:37 PM
#11
The picture isn't missing
Would it be better if you bitblt the pixel, then use getdibits to get what the colour of the pixel is?
Remember, if someone's post was not helpful, you can always rate their post negatively  .
-
May 25th, 2004, 06:58 PM
#12
Just noticed something.
You're calling GetDC twice when you only need it once
Change"
Code:
hdc = GetDC(0)
Text1.Text = GetPixel(GetDC(0), pt.x, pt.y)
to
Code:
hdc = GetDC(0)
Text1.Text = GetPixel(hdc, pt.x, pt.y)
Those DC's will getcha if you don't watch out
-
May 26th, 2004, 10:38 AM
#13
Thread Starter
New Member
Thanks for catching the GetDC twice Longwolf
I am not too familiar with using the ReleaseDC in my code.
I put the ReleaseDC API call in a module
I put ReleaseDC (hdc) in the timer1_timer sub but It wouldn't work.
I think I need another argument in there, but I don't know what it would be?
The bltbit looks like c+ programming in which I no experience whatsoever. Thanks though.
I really appreciate the help so far. It is helping me learn this stuff.
Andy
-
May 26th, 2004, 12:14 PM
#14
Fanatic Member
RelaseDC is delcare like this.
VB Code:
Public Declare Function ReleaseDC Lib "user32" (ByVal hwnd As Long, ByVal hdc As Long) As Long
As you can see you need a handle to the window that the device context is to be released. I guess since you use 0 as your handle to get the device context you can use that as your first parameter. I am not positive because anytime I got a device context I always had a window handle, but in your case you don't.
VB Code:
'So you can write you code like this.
ReleaseDC 0, hdc
Motto: Anything for a laugh.
Getting second place only means you are the first loser to cross the finish line.
-
May 26th, 2004, 02:13 PM
#15
Thread Starter
New Member
Thats it!!
I even set the timer interval to 1 and no leaks!
Thank you very much for your insight.
I've learned a lot more about API programming through VB.
It is very powerful because it looks like you can program outside the normal VB environment.
I still need to get a HANDLE on the hwnd stuff.
Thanks again to all.
Andy
-
May 26th, 2004, 02:21 PM
#16
Fanatic Member
Just to make things a little more clear for you on what a handle is.
A handle is just a long integer value given to a object such as a window, command button, textbox, etc. by the operating system to keep track of all the objects that are currently in memory. You use that handle to reference the object through API calls. So when you make an API call to get/set a property to an object in your application or some other application you need the handle (long integer value) so that the OS knows which object your talking about.
The handle will change each time you run your application since the OS gives the value to each object at runtime.
Also here is a website where you can d/l an API guide with a lot of examples on how to use them in code for VB.
http://www.mentalis.org/
Motto: Anything for a laugh.
Getting second place only means you are the first loser to cross the finish line.
-
May 26th, 2004, 04:02 PM
#17
Originally posted by ac3100
Thats it!!
I even set the timer interval to 1 and no leaks!
Thank you very much for your insight.
I've learned a lot more about API programming through VB.
It is very powerful because it looks like you can program outside the normal VB environment.
I still need to get a HANDLE on the hwnd stuff.
Thanks again to all.
Andy
To help others save time, please edit the subject of the original post and add Resolved.
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
|