|
You probably can fix the timing problem (before sending Alt/F4) by using a loop that gets and checks the WindowText of the current foreground window. Make sure to waste some time too, say 33 msec, on each iteration.
|
|
|
|
|
Thanks for your reply. Alt/F4 is the very last thing I want to use.
In VB6 we had DoEvents. We no longer have this with vb.net. I looked at Sleep.Thread (not sure of syntax right now) and this appears to have problems as well when it comes to allowing other threads to process while in a loop.
There must be a way to use API's to accomplish what I need to do.
|
|
|
|
|
drh6558 wrote: In VB6 we had DoEvents. We no longer have this with vb.net
Application.DoEvents() is available; it seldom is the correct way to solve any problem.
drh6558 wrote: I looked at Sleep.Thread (not sure of syntax right now) and this appears to have problems
Thread.Sleep() works just fine for me; it needs to be used correctly, i.e. in some thread, and not inside an event handler.
|
|
|
|
|
Again, thanks for your reply.
I tried the "Alt/F4" senario this morning and found another problem that I was not aware of. If there is any data missing when the "Print" button is pressed, the application will open another window letting the user know that there is data missing.
Unfortunately, this brings me back to detecting the Toobar button click and destroying the subsequent messages. Doing it this way prevents any further surprise windows from opening.
So how do I enumerate the Toolbar child windows (enumerate the buttons to find the hWnd)?
|
|
|
|
|
You'll probably need to look around a lot. I assume you already have a handle to the main window, if not one way of getting it is by enumerating all top-level windows (EnumWindows[^]); for each window you can enumerate all child windows (EnumChildWindows[^]); doing this hierarchically will in the end lead to each and every window.
Using SPY++ may help you in identifying which ChildWindow it is you want.
If your button is a real Windows button, that should do it; if it is just a rectangle drawn by an app, which also reacts on that area being clicked, then nothing you try may help you.
|
|
|
|
|
If it creates a new process then Kill that process
SOFTDEV
If you have knowledge, let others light their candles at it. [ Let's work to help developers, not make them feel stupid ]
|
|
|
|
|
Yes, this is what I want to do but I'm having trouble finding the Toolbar Button to do this.
When I use Spy++ and select the button, the whole toolbar becomes selected. So when I try and enumerate the child windows no children are returned.
In order to return any real messages, I’ve ended up selecting the Main Window, “All windows in System” and “Non-Client” message group.
Yesterday, just before I started driving, (btw, I'm a commercial truck driver in this life. In my last life I was a vb6 programmer), I was trying different things using Spy++. I clicked on a toolbar button then moved off the button before releasing the left mouse button (button down only), I think I was able to see each toolbar buttons window. However, I don't know which child is which. Each button uses a bmp and contains no identifiable text. I will try and replicate this again and see if it can be of use.
Any ideas would be help and greatly appreciated.
|
|
|
|
|
My point of view was that when that message appears does it creates any new process in CPU tasks , if so then kill that task or use send keys if that task is running
SOFTDEV
If you have knowledge, let others light their candles at it. [ Let's work to help developers, not make them feel stupid ]
|
|
|
|
|
This is a Windows Print Preview window that gets loaded from the Main window/app. When I end the process in the Task manager, task manager responds with application not responding for both the main app and the print preview. Task manager then shut both down, main app and print preview.
|
|
|
|
|
I want to pick a value from a DateTimePicker in 'MM/dd/yyyy hh:mm tt' format, add 00 as second with it, store it in a DateTime variable and save it to database. Suppose if I pick the value 05/28/2010 9:25 AM or 05/28/2010 9:25:34 AM from the DateTimePicker, it'll be stored in the variable and saved to database as 05/28/2010 9:25:00 AM irrespective of what value is chosen from the DateTimePicker for second. I'm using the following statement but it's getting failed during the format conversion while storing it in the DateTime variable generating an error.
Dim dtmReminderTime As DateTime
dtmReminderTime = DateTime.Parse(Format(dtpReminderTime.Value, "MM/dd/yyyy hh:mm") + ":00 " + Format(dtpReminderTime.Value, "tt"))
I tried the other way but failed:
dtmReminderTime = Convert.ToDateTime(Format(dtpReminderTime.Value, "MM/dd/yyyy hh:mm") + ":00 " + Format(dtpReminderTime.Value, "tt"))
I have also tried using culture specific information but of no avail. Please help.
|
|
|
|
|
Don't convert datetimes (or floats or anything that isn't really a string) to strings just for performing some operation on it, there always is a better way.
If your DateTime holds some seconds, and you want to get rid of them, try this (example is C# code, VB is similar):
DateTime dt1=myDateTimePicker.Value;
DateTime dtWithoutSeconds=dt1.AddSeconds(-dt1.Second);
Warning: if the initial DateTime holds fractions of a millisecond (e.g. when it comes from DateTime.Now) then this technique won't work, as there is no easy way to get the amount of ticks that corresponds to that fraction of a millisecond.
|
|
|
|
|
Dim dtmReminderTime As Date = Nothing
With dtpReminderTime.Value
dtmReminderTime = New Date(.Year, .Month, .Day, .Hour, .Minute, 0)
End With
Debug.Writeline(dtmReminderTime.ToString)
I don't speak Idiot - please talk slowly and clearly
'This space for rent'
Driven to the arms of Heineken by the wife
|
|
|
|
|
I'm trying to match a certain DateTime value with the current system DateTime. I have a timer and a label on a form. Timer interval is set to 1000. When the form loads, the timer starts ticking. As soon as the current DateTime matches the value of the variable, it shows a message in the label.
When I'm writing the following code, the values don't match even if the current system DateTime is equal to the variable. Label1 isn't showing 'Times Matched':
Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
Dim dtmNow As DateTime
dim dtmVar as DateTime=#04/28/2010 03:25:00 AM#
dtmNow = Now
If dtmVar = dtmNow Then Label1.Text = "Times Matched"
End Sub
But when I'm writing the same code by parsing 'Now' into DateTime it's working fine.
Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
Dim dtmNow As DateTime
dim dtmVar as DateTime=#04/28/2010 03:25:00 AM#
dtmNow = DateTime.Parse(Now.ToString)
If dtmVar = dtmNow Then Label1.Text = "Times Matched"
End Sub
Why is it so? The default format of 'Now' is the same as I have stored in dtmVar variable. So there's no question of format mismatch. Does that mean 'Now' is not actually a DateTime property?
Provided, my O.S. is Windows Vista Ultimate and all date/time settings are set to default.
Regards.
|
|
|
|
|
DateTime has a resolution of 1 tick, i.e. one 10 millionth of a second.
DateTime.ToString() shows time to some resolution, probably up to a second or so; this means two DateTimes that look the same (as they produce the same ToString result) may be actually quite different.
It is in general a bad idea to compare two DateTimes for equality.
Have you ever done floating point calculations? There too it is a bad idea to test for equality.
Either you need to allow some tolerance, as in If value1 < value2+somethingSmall (pretty common in floating-point algorithms), or you really need an inequality test, as in if Now>=alarmTime
|
|
|
|
|
Hi:
I have an application, which I can only change via script. I need to find a way to clean the keyboard buffer and then block it, because sometimes press the keys too fast and run events in the application that should not run. I can not change the hard code. Hopefully I can help
|
|
|
|
|
What do you mean "only change via script"? Are you saying that this application has it's own scripting language? Are yousaying that you can only use VBScript? What?
|
|
|
|
|
Is there a simple way to convert a decimal to an hexidecimal?
|
|
|
|
|
Since everything is represented internally in Binary, the only "hexadecimal conversion" you're going to get would be when it's formatted into a string for display or some other human-readable purpose. That would be String.Format("{0:X}", value) .
|
|
|
|
|
In VB.Net...
dim string hex = Convert.ToString(i, 16);
Or in VB6...
use a textbox and three labels:
Private Sub Text1_KeyPress(KeyAscii As Integer)
If KeyAscii = 13 Then
KeyAscii = 0
Label1.Caption = Hex$(Text1.Text)
If Len(Label1.Caption) < 4 Then
Label2.Caption = "00"
Label3.Caption = Label1.Caption
Else
Label2.Caption = Left$(Label1.Caption, 2)
Label3.Caption = Right$(Label1.Caption, 2)
End If
End If
End Sub
Run the program, type any integer legal number value and press ENTER.
------------------------------------
I will never again mention that I was the poster of the One Millionth Lounge Post, nor that it was complete drivel. Dalek Dave
modified on Friday, April 30, 2010 10:27 AM
|
|
|
|
|
Dalek Dave wrote: Label1.Caption
That looks very vb6 to me...........in fact it all does.
Are you crossing to the dark side?
|
|
|
|
|
Shhh!
------------------------------------
I will never again mention that I was the poster of the One Millionth Lounge Post, nor that it was complete drivel. Dalek Dave
|
|
|
|
|
|
Thanks for the help guys
|
|
|
|
|
I have a project that I'm working on and my boss wants me to add the buttons to the tool strip at runtime based on different things (those I'll worry about later). I've gotten pretty far on my own but am now stuck on the "click event". I can get the buttons to display but can't get them to do anything once they are there other than look good. I'm in the testing stage now so it's nothing impressive but as I said it works up to the point of displaying in the manner I need it to.
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
'Create a button for the tool strip
Dim btnSomething As New ToolStripButton
btnSomething.Text = "Test 1"
btnSomething.Image = Image.FromFile("F:\VisualBasic\ToolStripTest\images\eventlog.ico")
btnSomething.TextImageRelation = TextImageRelation.ImageAboveText
btnSomething.ToolTipText = "This is Just a Test"
Dim btnSomething2 As New ToolStripButton
btnSomething2.Text = "Test 2"
btnSomething2.Image = Image.FromFile("F:\VisualBasic\ToolStripTest\images\eventlog.ico")
btnSomething2.TextImageRelation = TextImageRelation.ImageAboveText
btnSomething2.ToolTipText = "This is Just a Test again"
'Display a separator with followed by the two created buttons followed by another separator
ToolStrip1.Items.Add(New System.Windows.Forms.ToolStripSeparator)
ToolStrip1.Items.Add(btnSomething)
ToolStrip1.Items.Add(btnSomething2)
ToolStrip1.Items.Add(New System.Windows.Forms.ToolStripSeparator)
End Sub
Thank you all in advance...
modified on Friday, April 30, 2010 12:37 PM
|
|
|
|
|
AddHandler btnSomething.Click, AddressOf ClickRoutine 'add handler here
where click Routine is some predefined subroutine
Thanks for taking the time, now go away and grow up and return in a newer, more polite and less shouty and ignorant form. - Dalek Dave
|
|
|
|