|
On a 32-bit processor, GetForegroundWindow will return a 32-bit unsigned integer, guaranteed. Using a 64-bit interger just corrupts the stack, so don't do it, unless, of course, you're running 64-bit Windows. If you have to ask how you can tell which version your running, your running 32-bit.
GetForegroundWindow CAN return 0, such as, how you've found, when a window is losing it's activation, like when you minimize the foreground window or its no longer visible. This is normal operation as described in the documentation for GetForegroundWindow[^].
Dave Kreskowiak
Microsoft MVP - Visual Basic
|
|
|
|
|
Right, and I understand that. However, when I do it in VB6 i have absolutely no problem with capturing the handle by placing a doevents between the minimize/visible call and the GetForegroundWindow call.
I tried application.doevents but it didnt seem to work either.
Does anyone think that calling the waitforsingleobject api call may work in this case, or what is the api call for a doevents.
By the way, thanks for helping me. The swap from VB6 to .net is a slow one.
Brent
|
|
|
|
|
I finally made a workaround, and i hate workarounds but here it is unless someone else has a better idea...
<br />
Do<br />
wndHWND = (GetForegroundWindow)<br />
Application.DoEvents<br />
Loop Until wndHWND <> 0<br />
I works but man I hate looping just to get a value..
Brent
|
|
|
|
|
Well, you have to account for the fact that, sometimes, there is no ForegroundWindow!
Dave Kreskowiak
Microsoft MVP - Visual Basic
|
|
|
|
|
DoEvents doesnt have an API call. All it does is release control so your application's message pump can process it's pending messages. But, this call is only for the application that calls DoEvents. It doesn't have any effect on the rest of the system.
As far as a workaround - you found it. Your VB6 code ignored the possibility of the call returning NULL. Just because it happened to work before doesn't make it a correct implementation of calling GetForegroundWindow.
Dave Kreskowiak
Microsoft MVP - Visual Basic
|
|
|
|
|
|
it is working fine I had no problem in displaying it. You have used vbCrlf in right place.
What a curious mind needs to discover knowledge is noting else than a pin-hole.
|
|
|
|
|
If your label in for an asp.net application you need to put in a which the the HTML version of vbCrLf.
So if this is an asp.net app then your code would look like:
lblScore.Text = "Well done, you got " & intScoreTop & " out of 10"
If this is a windows app it should work fine.
Ben
|
|
|
|
|
hi guys?
I am making a POS - Point of sale System - project. I want to read from a barcode reader and match the barcode against a barcode already in the database. I'm really stumped on how to go about it. How can I save a barcode to the database and then match what is in the database to what has been read from the barcode reader.
Please help
Moseti
|
|
|
|
|
A bar code represents a string of characters and numbers. So your bar code reader should scan the bar code and convert it into the string representation. This is the value you would save in the database. Once in string form it should be very easy to compare it with other items in the database.
Mike Lasseter
|
|
|
|
|
Hello,
This is very simple. The input of scanning in a barcode is the same as the keyboard input.
If you want to input a barcode value, you just put the cursor in a text box, read in the barcode and the value will be there. Once you have it you can do what you like if it. input into a database, compare with another value etc.
Once the barcode scanner is connected to the computer, you don't have to do anything else.
Hope this help,
Steve
|
|
|
|
|
How can I import data from a Foxpro database to an access databse using VB.Net Code
|
|
|
|
|
In my software when I'm in a textbox(big and multilined), and press Ctrl+T a textbox(small box)
must appear beside the cursor(not the mouse pointer).
(I don't want a code for the entire screen just in the big textbox)
pls Help very urgent.
|
|
|
|
|
Well it is quite bit intrique. I am still working on it but having hard time to display the textbox next to cursor inside the big textbox. Here is the code it displays the text box according to form's cursor (X and Y) coordinates.
Public Class Form1
Private Sub TextBox1_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles TextBox1.KeyPress
If e.KeyChar = Chr(65) Then 'Define CTRL-T instead of chr(65) "A"
Dim tbox As New TextBox
Dim tx As Int32 = Windows.Forms.Cursor.Position.X
Dim ty As Int32 = Windows.Forms.Cursor.Position.Y
Me.Controls.Add(tbox)
tbox.Location = tbox.PointToClient(New Point(tx, ty))
tbox.BringToFront()
End If
End Sub
End Class
What a curious mind needs to discover knowledge is noting else than a pin-hole.
|
|
|
|
|
The problem with this is that a Textbox cannot contain other controls, like another Textbox. You can have a Textbox appear OVER another Textbox, but that's about it.
Getting the cursor position inside the TextBox is identical to gett it for the form. You just ask the Textbox to convert the coordinates using its PointToClient method. Just replace Me with the name of your instance of the Textbox.
Dave Kreskowiak
Microsoft MVP - Visual Basic
|
|
|
|
|
Dave Kreskowiak wrote: The problem with this is that a Textbox cannot contain other controls, like another Textbox. You can have a Textbox appear OVER another Textbox, but that's about it.
I've never had a problem with this. Am I missing something here? As far as I can tell a textbox can contain other controls.
**EDIT**
I see the child control doesn't scroll with the textbox like it would under a form or other such container. It just sits on top. Now I get it.
|
|
|
|
|
TwoFaced wrote: It just sits on top. Now I get it.
Most people expect it to scroll with the Text. Unfortunately, they don't understand that the child textbox isn't part of the text at all.
Dave Kreskowiak
Microsoft MVP - Visual Basic
|
|
|
|
|
No.. No.. I didn't want the small textbox to come in the big textbox at all, I just wanted the small textbox to come beside the cursor(I say again not the mouse pointer ) that is in the big textbox.
|
|
|
|
|
The cursor is the mouse pointer. The "caret" is the little binking line in the textbox.
You can get the position of the caret using this:
Dim caretPosition As Point = TextBox1.GetPositionFromCharIndex(TextBox1.SelectionStart)
Dave Kreskowiak
Microsoft MVP - Visual Basic
|
|
|
|
|
My mistake, But the code doesn't work.
(it says "GetPositionFromCharIndex" is not a member of System.Windows.Forms.TextBox")
|
|
|
|
|
GetPositionFromCharIndex is in the .NET 2.0 Framework and above. This means that your using VB.NET 2003 (.NET Framework 1.1) There is no equivilent in .NET 1.1 and below.
.
Dave Kreskowiak
Microsoft MVP - Visual Basic
|
|
|
|
|
How do I minimuise my program into the system tray.
|
|
|
|
|
|
|
kubben wrote: I wrote an article that minimizes the windows app to the tray and also using a notify icon. It is in .net 2.0. The part of the code that minimizes the form is pretty much the same.
http://www.codeproject.com/dotnet/notifyiconcontrol20.asp[^]
Hope that helps.
Ben
Thanks for your reply, it got me started in the right direction..
instead of Form1_Closing i used Form1_Move and works a.o.k.
|
|
|
|