Question : Need to find a Button on an application and monotor it's text

I have using VB6sp6 been able to locate a Button and monitor it's Text/Caption Change Using API Calls. Now I am tasked with updating my program to VB.NET (I am using VS2008). I ahve converted my app to VB.NET using the wizard in VS2008 but as you can image just learning VB.NET I am a little confused. I like to understand what it doing different and learn as I am self taught.

Let me mention the Button is on an application I need to monitor, and send a flag once that button been in that state for 90 seconds. I was able to do this in VB6 but can;t seem to get it working in VB.NET

I am able to find the window but unable to get past that point and find the Button on the Application.

Here is what I have so far;

Here is the API functions I am using.
Public Declare Function FindWindow Lib "user32.dll"  Alias "FindWindowA"(ByVal lpClassName As String, ByVal lpWindowName As String) As Integer

Public Declare Function EnumWindows Lib "user32.dll" (ByVal lpEnumFunc As Integer, ByVal lParam As Integer) As Integer

Public Declare Function EnumChildWindows Lib "user32.dll" (ByVal hWndParent As Integer, ByVal lpEnumFunc As Integer, ByVal lParam As Integer) As Integer


This is what I use for the finding the window....
'Set what Window to look for
vHwnd = FindWindow("ClassName", vbNullString)

I can supply more if need but... I think once I get past the above get then call on EnumChildWindows with the following code
During the conversion it gave me this warning during Upgrade and to be honest I am having trouble getting my mind around the concept...
"Add a delegate for AddressOf EnumChildProc"

Public Function FIND_RELEASE() As Boolean
Dim FoundRelease As Object
Dim OKButtonHwnd As Object
Dim i As Object
HwndCount = 0 'initialize the handle counter
FoundReleaseButton = False 'Sets button to not found
RetVal = EnumChildWindows(VoipHwnd, AddressOf EnumChildProc, CInt(0))
            
'Looks for the Reconnect button (Hold Button)
For i = 0 To HwndCount - 1
'Search Eng to look for the Reconnect button
If Mid(AppClass(i), 1, 6) = "Button" And Mid(AppText(i), 1, 9) = "Reconnect" And FoundRelease = False Then 'search for the ok button
OKButtonHwnd = AppHwnd(i) 'store the ok button handle
FoundRelease = True 'flip the switch button found
End If
Next i
Dim FlashForm As frmFlash
If FoundRelease = True Then
FoundReleaseButton = True
timHold.Enabled = True
ChangeTrayIcon(Me, (Me.Image3.Image))
'Seeing
If exHoldTime = CDbl("90") Then
ChangeTrayIcon(Me, (Me.Image4.Image))
FlashForm = New frmFlash
FlashForm.ShowDialog()
FlashForm = Nothing
End If
Exit Function
End If
End Function


 Any help or pointers to what i need to read would be great...been searching now for a couple of days.


                  

Answer : Need to find a Button on an application and monotor it's text

First thing I'd recommend is moving your executor service outside of the loop.  You really only need to create that once.  Depending on your implementation, you may be able to make it a class variable, either a static that is shared by all instances of this class or a private member if each class needs its own thread pool.  Either way, as long as you don't shut the service down, you'll be able to reuse those threads instead of incurring the overhead of starting them every time.  If multiple calls to this method will need to run simultaneously, move the executor service creation back into the method, but outside of the loop.

It also looks like you're creating 10 thread pools, with 10 threads each to process each order.  The code I've attached is reworked to process all provided orders with 10 threads.
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
41:
42:
43:
44:
45:
46:
47:
48:
49:
50:
51:
52:
public class ClearDownService {
    private int threads;
    private ExecutorService executorService;

    public ClearDownService(int threads) {
        if (threads < 1) {
            throw new IllegalArgumentException("Threads must be >= 1.");
        }
        this.threads = threads;
        this.executorService = Executors.newFixedThreadPool(this.threads);
    }

    // I modified your iteration code to assume you have some Collection of OrderModel objects
    // that you are using to get the iterator.  Since you are using JDK 1.5+, its much more
    // readable and maintainable to use Generics instead of casting the return of iterator.next().
    // I also modified your iteration code to use the built-in foreach construct.
    public void checkOrders(Collection<OrderModel> orders) {
        // Initialize latch for the total number of orders, instead of threads.
        // This ensures all orders are processed before this method completes
        final CountDownLatch startLatch = new CountDownLatch(orders.size());

        // since you are using JDK 1.5+, easier to read and maintain if you use generics
        // and the built-in foreach instead of the iterator
        for (final OrderModel model : orders) {
            executorService.submit(new Runnable() {
                public void run() {
                    try {
                        Calendar now = Calendar.getInstance(TimeZone.getTimeZone("Europe/London"));
                        if (isEligibleForClearDown(model, master.getCleardownFields().getClearDownReqFrom(), now)) {
                            if (model.getOrderFields().hasParentOrderId()) {
                                // add all Child orders to final result
                                results.add(model);
                            } else {
                                // add parent orders to the parent list
                                parentOrders.add(model);
                            }
                        }
                    } finally {
                        // putting this in a finally block ensures it gets called regardless
                        // of any exceptions that occur in the body of the method
                        startLatch.countDown();
                    }
                }
            });
        }
        try {
            startLatch.await(); // wait for all objects to complete processing
        } catch (InterruptedException e) {
            LOGGER.error("Interrupted Exception while waiting for the countdown latch to end.");
        }
    }
}
Random Solutions  
 
programming4us programming4us