|
Hi,
Im trying to make a robot player for a game im playing
so far i have been using a program called JoyTokey which transfers joystick strokes to mouse or keyboard events.
1) i tryed using sendkeys when the window is focused
But i get an error: "The specific module could not be found"
2) i tryed using Sendmessage and no affect,
3) when i right click the application on task manager and click "Go To Process"
i get nothing, and i cant find it in the processes in task manager manualy either.
4) when i try hwnd on it i get a number but dont know what to do with it.
any idea how can i solve the problem ?
if i knew how the program JoyToKey works...
thanks.
|
|
|
|
|
See this[^] C# article.
It's not necessary to be so stupid, either, but people manage it. - Christian Graus, 2009 AD
|
|
|
|
|
Thanks, ill try it as soon as i get home
|
|
|
|
|
Hi,
I tryed the application,
it detected the window i want but when i tryed to send a key stroke
it crashed, I looked in the debugging information and guess what i found,
the same error i recieved :"The specific module could not be found"
so i guess he used Sendkeys too (i didnt look in the code, only runed the app)
and its not working with this specific game.
can anyone help ?
|
|
|
|
|
|
I have a VB.NET (VS 2008) main form that shows a second form. The second form has a listbox that has lines of data added for an amortization table based on global variables set in the main form.
The second form has an exit button as its only user control. If the user clicks the exit button while the data is still being calcualted and added to the listbox, the button executes me.close and frmMain.show.
The problem is that if a loan with many months (each month is a line in the listbox) is being displayed, then after the form closes and shows the main form, the second form's code is still running in the background. If I select a new set of loan parameters on the main form while the second form's code is still running, I get an error.
What I need to do is close the second form such that all code running in the form is also killed.
I have also tried this version and the "dispose" does not seem to make any difference.
Private Sub btnCloseAmort_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnCloseAmort.Click
Me.Dispose()
frmMain.Show()
End Sub
I will apprechiate any help I can get.
William
|
|
|
|
|
1) how are you loading the 2nd form? as a dialog or?
2) how is it that you can say frmMain? you don't have a circular reference do you (gave form2 the pointer to form1)?
'Never argue with an idiot; they'll drag you down to their level and beat you with experience.' ~ anonymous
'Life's real failure is when you do not realize how close you were to success when you gave up.' ~ anonymous
|
|
|
|
|
Welcome!
You need to signal the data add code an exit when form is closing. How is this data add happening? On a separate thread? Also, I'd suggest you to use delegates for communicating between forms.
Probably, you need to show us the code you are using to get more help.
|
|
|
|
|
The code that is running to populate the frmAmort form:
Private Sub frmAmort_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
' Used as the index for the for loop
Dim i As Int32
' We will be resetting the balance as payments are made so we need a starting balance
Dim dBalance As Double = dPrincipal_g
Dim dInterestPaid As Double
Dim dPrincipalPaid As Double = dPayment_g - dInterestPaid
Dim loops As Integer = 0
lblHeading.Text = "Pmnt# Balance Interest Paid Principal Paid"
' Loop for every payment
For i = 1 To iMonths_g
' Calculate the amount of interest paid for that month
dInterestPaid = Math.Round(((dBalance * dInterestRate_g)), 2)
' Calculate the balance after the payment for that month
dBalance = dBalance - dPayment_g + dInterestPaid
' Calculate the amount of principal paid for that month
dPrincipalPaid = dPayment_g - dInterestPaid
loops += 1
' Display the amounts in the listbox
If dBalance > 0 Then
lstAmort.Items.Add(i & Chr(9) & FormatCurrency(CDec(dBalance)) & Chr(9) & _
FormatCurrency(dInterestPaid) & Chr(9) & FormatCurrency((dPrincipalPaid)))
Else
' If the number is too small, it will not tab properly so add an extra tab.
lstAmort.Items.Add(i & Chr(9) & FormatCurrency(CDec(dBalance)) & Chr(9) & Chr(9) & _
FormatCurrency(dInterestPaid) & Chr(9) & FormatCurrency(dPrincipalPaid))
End If
' Cause the form to display the values without waiting until control
' is returned to the form (process all messages in the queue).
Application.DoEvents()
'If we have displayed 36 months of data, then pause
If (loops = 36) Then
'pause the display 2 seconds (2000 milliseconds)
Threading.Thread.Sleep(2000)
' reset the loop counter
loops = 0
End If
lstAmort.SelectedIndex = i - 1
Next
End Sub
Private Sub btnCloseAmort_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnCloseAmort.Click
Me.Close()
frmMain.Show()
End Sub
Thanks again for looking into this for me. the pausing is not an option. USing a gridbox maybe but I am not there yet in my training.
William
|
|
|
|
|
Hi,
first of all:
1) welcome to the CodeProject
2) IMO most replies you've got are not touching the heart of the problem you have.
Here is how I see it: there are basically three problems.
1) you have a potentially slow calculation executed inside the frmAmort_Load() method; this is bad, since it will block normal GUI operations for as long as it takes. A typical GUI guideline says you should make sure the GUI always responds "immediately", meaning no handler should ever take more than say 30 msec to execute. If more work needs to be done, you should delegate that to another thread (and take the required actions to get the data correctly to the GUI Controls).
2) to "remedy" (or really: hide part of) the problem, you have added an Application.DoEvents() call which makes sure some Controls get updated before the handler is done (that is what you wanted), however it also will process whatever other Windows messages it can find, such as the clicking of the close box. That is how you are able to close the form that is still being loaded.
3) you have a Thread.Sleep inside a handler, that is a big no no. You should NEVER do that, for the very same reasons mentioned above.
Here is what you should do as a minimum:
1) remove the Thread.Sleep
2) replace the Application.DoEvents() by either nothing or by lstAmort.Refresh()
(chances are without the Sleep, the entire Load is almost instantaneous, unless you need hundreds of lines in the list)
And here is what a decent approach would be assuming a really long calculation;
1) the above minimum fixes;
2) plus moving most of the Load stuff to a BackgroundWorker, and using Control.Invoke to update the lstAmort Control. See this article[^] of mine, and the BGW documentation.
Luc Pattyn [Forum Guidelines] [My Articles]
The quality and detail of your question reflects on the effectiveness of the help you are likely to get.
Show formatted code inside PRE tags, and give clear symptoms when describing a problem.
|
|
|
|
|
Hmm ... Why would you use a listbox instead of the more powerful, DataGridView.
I would load the datatable first, then bind it to the grid and it would be displayed to the user. By doing this, you are sure that the data is fully loaded before the grid displays. I'm also kind of suprised that there is such a delay in loading an amortization schedule that the user could close the form before it finishes loading. A 30 year mortgage is only 360 lines; you should be able to load that in 1 or 2 seconds.
Give us some more info and we should be able to point you in the right direction.
|
|
|
|
|
If you want to show two different forms, but not both at the same time, the best way to do it, is to define both forms as controls, and put both controls on the one form, switching which one is visible.
Christian Graus
Driven to the arms of OSX by Vista.
Read my blog to find out how I've worked around bugs in Microsoft tools and frameworks.
|
|
|
|
|
Hey..
I really at my wits end on this.
I have a device that i connect to through TCP/IP using an api function call.
Because there could be cases where maybe the router/switch restarted or the network went down or something
and if this happens then the device should connect automatically again.
I need a to check the the connection status of the device,whether it is connected to application or not so then i can reconnect automatically.
I did something like this
Dim information As TcpConnectionInformation
For Each information In IPGlobalProperties.GetIPGlobalProperties.GetActiveTcpConnections
If (information.RemoteEndPoint.Address.ToString = readerIp) Then
state = CInt(information.State)
End If
Next
However this updates the state only after i manually disconnect the device.It the i pull the cable out and plug it back in it still show the same state.
Is there another way to this,to check where a connection is..(not like ping) but if there is an active connection between the device and pc.
|
|
|
|
|
AFAIK, ping[^] is the efficient way for this. Just ping the device and if you are getting acknowledgement, consider it as active.
|
|
|
|
|
i know but ping will only tell if the device is connected to the network..it will not tell me if there is an active connection(ie that there is some data flow between the device & pc).
For instance the device is connected to my application(i can ping it as well)...however if i pull out the cable and plug it in back again..i can still ping it...but it isn't connected to my application anymore...so the ping check is not enough for this..it wont tell me if it is connected or not..is there some way to do this with sockets and ports?
|
|
|
|
|
Hello again,
for those who saw it: I asked the question already some time ago, but I just got answers that couldn't help me solve the problem. Maybe there's someone around who's willing to guide me a bit more detailed?
All I wanna do is show a picture (DPX-File) in a picture box on a form. Unfortunately DPX is not supported from GDI+, so I have to find an uncommon way in VB2008. What I found: The image information in a dpx-file starts after a header of specified length at Address &h2000. Each pixel is represented by a 32-bit-word (4 Bytes) which I would be able to read e.g. using a binary reader.
With which code could I get the information read by a binary reader into my picture box? I read about memorystreams, blobs etc but I can't figure out which way would work and how...
Any advice is very appreciated!
Thank you for you time,
Michael
|
|
|
|
|
Hi,
this is a two-step job:
1. convert your image file to a Bitmap object
2. display the Bitmap
1. may or may not be simple, depending on the image format.
If you're lucky the Bitmap(Int32, Int32, Int32, PixelFormat, IntPtr) constructor is appropriate. If not, you have to:
a. get the dimensions
b. create a Bitmap of that size
c. get each pixel from the file and call bitmap.SetPixel
Luc Pattyn [Forum Guidelines] [My Articles]
The quality and detail of your question reflects on the effectiveness of the help you are likely to get.
Show formatted code inside PRE tags, and give clear symptoms when describing a problem.
|
|
|
|
|
Thank you, Luc.
I'm about digging into information about the Bitmap-Constructor as you recommend... to find out if I'm lucky I'd be glad if you'd help me along with a code example regarding the 'scan0' Parameter.
Public Sub DisplayImage(ByVal PicFile As FileInfo)
Dim width As Integer = (2048 / 10)
Dim height As Integer = (1536 / 10)
Dim stride As Integer = (4 * 2048)
Dim format As PixelFormat = PixelFormat.Canonical
Dim scan0 As IntPtr
Dim DPXBitmap As New Bitmap(width, height, stride, format, scan0)
PictureBox1.Image = DPXBitmap
End Sub
Or would it be possible using a filestream to create the bitmap? Something like
Dim ft As FileStream
ft = New FileStream(PicFile.FullName, FileMode.Open)
ft.Position = 8192
Dim DPXBitmap As New Bitmap(ft)
PictureBox1.Image = DPXBitmap
ft.Close()
|
|
|
|
|
I don't think a stream will work, IIRC new Bitmap(stream) tends to rewind the stream before processing it. What you should consider is this:
declare an array of bytes, fill it with pixel data from the stream; then use the GCHandle class to pin it and get the IntPtr, then use the Bitmap constructor. All this assuming the data is layed out in a way that matches one of the supported pixelformats.
if not, you have to:
- either fill the byte array yourself in an acceptable pixelformat;
- or use SetPixel (which is bound to be slower).
BTW: I'm not sure what the division by 10 is doing in Dim width As Integer = (2048 / 10) ; if you hope to resample the image while loading, that has zero success probability. Load it as is, then do whatever you have to to it.
Luc Pattyn [Forum Guidelines] [My Articles]
The quality and detail of your question reflects on the effectiveness of the help you are likely to get.
Show formatted code inside PRE tags, and give clear symptoms when describing a problem.
|
|
|
|
|
Wow... even reading your advice is a challenge for me novice
I'll try my best to understand what 'use the GCHandle class to pin it' might mean and how I could then get the IntPtr... ? Or would you please be so kind as to show with a few lines of code what you mean?
Thanx again
btw: you were right that I tried to resize the picture for display by dividing the originals width and height by 10. Your advice helps avoiding that additional trap
|
|
|
|
|
So as a novice the first thing you want to do is read some strange image format? Good for you! I won't embarras you with any code samples, I'd rather suggest:
1) you read up on the GCHandle class, it is a little class and you will need it (unless you use the slower way with Bitmap.SetPixel);
2) you read a good tutorial on VB.NET (Here[^] is why).
Luc Pattyn [Forum Guidelines] [My Articles]
The quality and detail of your question reflects on the effectiveness of the help you are likely to get.
Show formatted code inside PRE tags, and give clear symptoms when describing a problem.
|
|
|
|
|
Hey Luc...
too sad you're in a bad mood obviously - your 'read a tutorial' standard answer is not very helpful . Or did you invest in bookshop shares recently?
The task to handle a 'strange' or let's say unsupported (btw the standard for movie interchange!) picture format might be challenging, but that's why I ask in a programming forum even after buying some books, right? Even a good Cessna pilot has to consider himself as a novice when it comes to the F-16, so why do you have to embarras me with such a silly statement instead of guiding me to an advanced technique that you probably know?
Nevertheless, I wish you a nice evening and a good glass of wine... and I'll go read about the GCHandle class, anyway.
|
|
|
|
|
Have a look at this[^]. The source code is available for download, so you should be able to read it and see how they have handled DPX files.
Steve Jowett
-------------------------
Real programmers don't comment their code. If it was hard to write, it should be hard to read.
|
|
|
|
|
Thank you, Steve.
Unfortunately it's all in C++ which I have absolutely no idea of. It's the same with GraphicsMagick / ImageMagick, which I had considered to examine before. So for the moment I'm trying to find a way out with the Bitmap-Constructor how Luc recommended.
|
|
|
|
|
hi all,
I am into a new project to read new mails from a mail server and put into database. i tried pop3 .But in that all mails from sent items and inbox at time . So i decided to use IMAP
I modified the POP3 code which i was using an tried like this
created a TCP object
Dim objTCP As New TcpClient
Dim sslstream As Net.Security.SslStream
Dim reader As StreamReader = Nothing
objTCP.Connect("imap.gmail.com", 143)
sslstream = New Net.Security.SslStream(objTCP.GetStream())
sslstream.AuthenticateAsClient("imap.gmail.com") ' authenticate as client GMAIL
reader = New IO.StreamReader(sslstream) ' Assigned reader to stream
it caught an error on the authentication part "sslstream.AuthenticateAsClient("imap.gmail.com")"
I am pasting the error below
System.IO.IOException = {"Unable to read data from the transport connection: An existing connection was forcibly closed by the remote host."}
InnerException = {"An existing connection was forcibly closed by the remote host"}
Can you point out the error in my code.
If i am wrong Can you help me to get the basic commands running .
I am new to this network level programming
thanks & regards
|
|
|
|