Jump to content
Xtreme .Net Talk

Riemann

Members
  • Posts

    13
  • Joined

  • Last visited

Everything posted by Riemann

  1. hehehehe, oops. The above code actually works fine. I just had a bug in my target application :) Anyway, if anyone want to know how to fake mouse clicks, here is a working example.
  2. Hello all! I am trying to use SendMessage to fake a mouse click in another application. This is the code I have so far. It takes the Window Caption and/or class name of the target window, gets its HWND and Client Rect (that part works fine) then uses SendMessage to send a mouse click. When I run this I get no errors and both calls to SendMessage return 0. However, the Click event on the target form (for now I am just targeting a small dummy app I wrote to test this) does not fire. Any suggestions? public const uint WM_LBUTTONDOWN = 0x201; public const uint WM_LBUTTONUP = 0x202; [DllImport("user32.dll", EntryPoint = "SendMessageW")] public static extern uint SendMessage(uint Handle, uint wMsg, uint wParam, uint lParam); [DllImport("user32.dll", EntryPoint = "FindWindowW")] public static extern uint FindWindow(IntPtr lpClassName,IntPtr lpWindowName); [DllImport("user32.dll", EntryPoint = "GetClientRect")] public static extern bool GetClientRect(uint hWnd,ref RECT lpRect); [structLayout(LayoutKind.Sequential)] public struct RECT { public int left; public int top; public int right; public int bottom; } private uint PackMessage(Int16 High,Int16 Low) { return((uint)((High * 0x10000) + Low)); } private void cmdSendClick_Click(object sender, System.EventArgs e) { IntPtr ptrCaption,ptrClass; uint hWnd=0; if(txtCaption.Text == "") { ptrCaption = IntPtr.Zero; } else { ptrCaption = Marshal.StringToHGlobalUni(txtCaption.Text); } if(txtClass.Text == "") { ptrClass = IntPtr.Zero; } else { ptrClass = Marshal.StringToHGlobalUni(txtClass.Text); } hWnd = FindWindow(ptrClass,ptrCaption); if(txtCaption.Text != "") { Marshal.FreeCoTaskMem(ptrCaption); } if(txtClass.Text != "") { Marshal.FreeCoTaskMem(ptrClass) } if(hWnd == 0) { lblResult.Text = "Window not found"; return; } RECT ClientRect = new RECT(); GetClientRect(hWnd,ref ClientRect); lblResult.Text = SendMessage(hWnd, WM_LBUTTONDOWN, 0, PackMessage((Int16)(ClientRect.bottom/2),(Int16)(ClientRect.right/2))).ToString(); Application.DoEvents(); lblResult.Text = lblResult.Text + " " + SendMessage(hWnd, WM_LBUTTONUP, 0, PackMessage((Int16)(ClientRect.bottom/2),(Int16)(ClientRect.right/2))).ToString(); Application.DoEvents(); }
  3. I am.. interested. Email me the overview or full spec (if it is a simple project) and how much the contract pays at eigenvector@verizon.net
  4. Re: Developing, building, and testing. How do it the best? Learning from the world leader The truth is that each team at Microsoft is given a great deal of freedom in deciding how they want to manage their projects. This can depend on the size of the project, the timeframe, the budget and even just who is involved. I think this is one of the strengths of the company. Though I can say one common aspect is the general organizational style. On any project there are three basic forces: Development, Test and Program Management. Ideally, these three forces should be roughly equal in importance. The function of PM is to handle all creative decisions and scheduling. Development implements the specs and plans created by PM. And Test ensures the quality of the work of both PM and Dev. As long as no one force assumes too much importance things run pretty smoothly. I think one of the inherent flaws in the current games industry (and why it is about 10 years behind applications in terms of management) is that the Developers pretty much have total control of the whole project. No developer, no matter how long they have been doing their job or how good they are at it, should ever be moved to management unless they actually have good management skills.
  5. If that flash program has input focus, then SendKeys will do it.
  6. If anyone has ever done this please reply! I asssumed one would use SendMessage with the appropriate wparam and lparam but I just cannot seem to get it to work. Please help!
  7. Near as I can tell, you cannot create a complex primary surface (one which has one or more back buffers) in windowed DirectDraw. Is this the case? I have a game I am working on now where going Full-Screen will not be a problem. But in the future there is one I would like to write in windowed mode. In that case will I have to just create a surface to use as a back buffer and Draw it into the primary surface every frame?
  8. Woops! Nevermind. Already got it. Much easier than I thought. Dim Writer As New IO.StreamWriter("c:\Temp.txt", False) Console.SetOut(Writer) That will redirect console output to c:\Temp.txt
  9. Is it possible to make it so that any output in a program via console.writeline is written to a text file instead of to the console?
  10. In my app, I need to process a loop which could take quite some time. It is very important that the other processes running on the system continue normal operation while this loop is executing. (this is because the loop is waiting for something in another process to happen). In VB6 I could just throw in a Do Events. How is this done in .NET?
  11. Well, it is a very simple matter to check which window has input focus and, if it is not the intended one, change that. However, I would much prefer to use SendMessage. The only problem being that it does not seem to work worth a damn. For instance, I wish to send a ENTER keystroke to a given window. Near as I can tell I need to send a WM_KEYDOWN followed by a WM_KEYUP where the wParam is the virtual key code (in this case &H0D for ENTER) and the lParam is zero. The thing is when I use SendKeys in this way it does not work. But when I ensure that the window is the Foreground window and use SendKeys it does. I am all for not making assumptions. Good stuff that. But I prefer my code to work.
  12. Yes, I have come much to the same conclusion myself. I figure I will just create a wrapper class to handle all the transitions to and from unmanged memory. *sigh* As for SendKeys, I was refering to System.Windows.Forms.SendKeys. Since this is the method suggested by the MSDN help files, what is the advantage of using SendMessage instead?
  13. Greetings all, I have recently begun working in .NET (after many years of the Visual Studio 6.0 languages) for the purpose of automating some test processes at work. While many of the tasks involved have turned out to be much simpler in managed code (I am using VB.NET) I have encountered some difficulties. Specificially, I would like to be able to find out what window currently has input focus (and be able to find what process it is attached to). Some other tasks which are also being troublesome in .NET are: Getting information about a window, such as its title, position, size etc... Getting information from a control on a window, such as text out of a text box or the state of a checkbox. Giving a window input focus. Note that all these tasks are for a window running in another process. EG: I use the process class to run another program and I need to manipulate and monitor that program. I know how to do all of these things with the WinAPI in non-managed code. However, if these things can be done with the .NET libraries I would prefer to do so. By the way: I have noticed something very odd about the Process.WaitForExit and Process.WaitForInputIdle methods. The problem with WaitForInputIdle being that it does not seem to do anything at all (it never seems to "wait" when I use it). With WaitForExit I have been getting some very odd behavior indeed. Take the following for example: myProcess.Start() Sendkeys("Weeee") myProcess.CloseMainWindow() myProcess.WaitForExit(10000) myProcess.Close() Assume that myProcess is set to open an instance of Notepad. Now it seems to mee that this should open Notepad, then print "Weeee" into it, then close notepad (waiting up to 10 seconds before proceeding for notepad to close). What is happening for me is that notepad opens, then immediately waits 10 seconds, then when the 10 seconds are up types in "Weee" and closes. EG: The WaitForExit is happening BEFORE the SendKeys and myProcess.CloseMainWindow commands. Very strange.
×
×
  • Create New...