I have an application in VB6 for which I am implementing the Autologout functionality. Whenever the application is in the idle state for some time, the user will be logedout by closing all the forms that user has loaded.
I am using a FormStack and unloading all the forms that has been loaded. Inorder to close the forms in a proper way we are using SendKeys ESC and the form will unload with ESC key.
It is working fine in most of the cases, but the problem is if there is something like Keyboard, then with the ESC key the keyboard is getting unloaded, but once all the forms are unloaded, the code next to Keyboard is getting executed which has a reference to forms control and loading the form.
I can do the reference checks, but this functionality is implemented in many places, and it takes time to check everywhere.
I also thought to wait for some time around 500 ms to close every form, but felt it is not good to rely on timers.
Could anyone suggest a better idea to unload all the forms smoothly.
i used to do
dim i as integer
for i = forms.count -1 to 0 step -1
unload forms(i)
next
also you can create a interface an implement that in the form
IDispose
sub Close()
dim miclazz as IDispose
form each miclazz in forms
miclazz.Close()
next
Related
How can you tell if a VB6 user control is done loading? Is there a custom UserControl_Loaded event or something?
What do you mean by loading? A UserControl has an Initialize event which you should use to set initial values. VB itself will then load in property values. In any of the other events you can assume the control is set up and ready to go.
You can read about the order of events a UserControl goes through here: https://msdn.microsoft.com/en-us/library/aa242140%28v=vs.60%29.aspx
I tend to put "load" logic into the InitProperties and ReadProperties event handlers. The first one gets called when a UserControl instance is added to a container (Form, another UserControl) within the IDE. The second one gets called on all subsequent "creations" within the IDE and at run time.
You can check Ambient.UserMode to determine whether a subsequent creation's ReadProperties event is due to editing operations vs. an IDE or compiled run.
Initialize events always occur, and before the other two. At that time Ambient and other context objects are not available yet.
See that fine manual: Understanding Control Lifetime and Key Events
I have a windows application which has several sub-forms. i have to navigate through 5 or 6 forms to reach the form i need. this is time consuming since i have to open it several times through the day and i do it daily.
my need: i dont have the source project for this application, i got it as an executable program, but i need to create some application that does these steps for me automatically. In other words i need to find a way to automatically click the buttons that navigate through the forms and opens the form i need from step one.
is there any way i can do this ?
There is indeed, though generic solutions already exist to perform just this kind of function to arbitrary programs.
You can use Spy++ or a resource-editor, like ResHack or ResEdit to look at the program and get the control ids of the navigation buttons.
Once done, you can get a handle to the program itself and then send messages to it's WindowProcedure that would be generated if the user clicked the controls with a mouse,
Another alternative, is to get the position of the running target application, after you've got it's HWND, by using the GetWindowRect function. You could then use this position along with vert/horiz distances to generate mouse events.
The two have more-or-less the same result, though some applications won't work with approach #1.
In one instance, you need to use Spy++ to get the control IDs.
In the other instance, you need to use an image editor to get the pixel offsets of the controls.
In both instances, you'll need to use FindWindow, along with the window's title-text in order to get a HWND handle.
You could use a combination of the two - asking the program itself with GetDlgItem for the handle of the controls you need to click. You could then query the control for its position, before using mouse_event to position the mouse above it and again to click it.
Quite a few ways to skin this cat, actually.
Pre-existing solutions like AutoIt are said to be very easy to use and will be much easier than coding a new program for each target.
To prevent users from clicking in my main_window when a MessageBox appears I have used:
EnableWindow(main_window,FALSE);
I got a sample MessageBox:
EnableWindow(main_window,FALSE);
MessageBox(NULL,"some text here","About me",MB_ICONASTERISK);
EnableWindow(main_window,TRUE);
The problem is that when I press "OK" on my MessageBox it closes and my main_window is send to back of all other system windows. Why this is happening?
I tried to put:
SetFocus(main_window);
SetActiveWindow(main_window);
after and before : EnableWindow(main_window,TRUE) the result was strange: it worked 50/50. Guess I do it the way it shouldn't be.
Btw.
Is there a better solution to BLOCK mouse click's on specific window than:
EnableWindow(main_window,FALSE);
Displaying modal UI requires that the modal child is enabled and the owner is disabled. When the modal child is finished the procedure has to be reversed. The code you posted looks like a straight forward way to implement this.
Except, it isn't.
The problem is in between the calls to MessageBox and EnableWindow, code that you did not write. MessageBox returns after the modal child (the message box) has been destroyed. Since this is the window with foreground activiation the window manager then tries to find a new window to activate. There is no owning window, so it starts searching from the top of the Z-order. The first window it finds is yours, but it is still disabled. So the window manager skips it and looks for another window, one that is not disabled. By the time the call to EnableWindow is executed it is too late - the window manager has already concluded that another window should be activated.
The correct order would be to enable the owner prior to destroying the modal UI.
This, however, is only necessary if you have a reason to implement modality yourself. The system provides a standard implementation for modal UI. To make use of it pass a handle to the owning window to calls like MessageBox or CreateDialog (*), and the window manager will do all the heavy lifting for you.
(*): The formal parameter to CreateDialog is unfortunately misnamed as hWndParent. Parent-child and owner-owned relationships are very different (see About Windows).
THE SITUATION
I am developing a VB6 application where all i need to do is to sync some files from a server location to the local workstation on a command click. There are two types of operations i am performing, in one m doing a complete sync, in the other i am doing a partial sync. Now when the sync is in progress i am displaying a screen which has a stop button on it. This stop is meant to stop the copying of media if the user wants to do so.
Now, this stop button is only visible when i am performing full sync. There is no option to stop the sync when partial sync is being performed.
The functions performing full sync and partial sync are written in a different class.
THE PROBLEM :
I have implemented all other functions but i having a problem in making this stop button dynamic..i.e. it is visible when full sync is bein called and invisible when partial sync is called.
Hope somebody helps
Thanks in advance
Set the Visible property to False to hide the button.
If I am understanding correctly, since the stop button is on a separate form it is not the case that there are other buttons on top of it- I had similar case myself.
What I can suggest is to check is whether both of the sync buttons are enabling the stop's button visibility when pressed.
I'd do it something like this:
Private sub cmdFullSync_Click()
'run existing code for a full sync
cmdStop.visible = true
end Sub
Private sub cmdPartialSync_Click()
'run existing partial sync code
cmdstop.visible = false
end Sub
How can I programatically trigger the tab key functionality in a VB.Net windows application?
Currently in my application I am using one splitter when I press the tab key, and the focus is moving in the right order.
However I need to use arrow keys to move the focus to next controls, in the same way that the focus is going when the user presses the tab keys.
Thanks in Advance
You can simulate the SendKeys.Send(string) method (in the Systems.Windows.Forms namespace). To simulate a tab keypress you would call SendKeys.Send("{TAB}").
To see all the key codes, check out http://msdn.microsoft.com/en-us/library/system.windows.forms.sendkeys.aspx
Better late, than never, since i found this post looking for a solution to a similar problem.
Windows Form type has ContainerControl somewhere in its chain of inheritance and that has a method ProcessTabKey(Boolean trueForForward) . It does exactly what you need, inside your form instance this.ProcessTabKey(true) will move focus forward along the tab index and this.ProcessTabKey(false) will move it backward.
Very simple code
Write Down this in KeyDown Event of Datagridview
If e.KeyCode = Keys.Enter Then
' Your code here
SendKeys.Send("{TAB}")
e.Handled = True
End If