473,320 Members | 1,858 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

Rectangle Survey

Atran
319 100+
Hello Everybody:
In Windows, when you press left-Mouse button and drag the mouse, you see a rectangle create, so I need to the rectangle survey, I mean to string the rectangle survey, Can anyone help me with this.
Thanks for your help.
Jun 11 '07 #1
11 1651
TRScheel
638 Expert 512MB
Hello Everybody:
In Windows, when you press left-Mouse button and drag the mouse, you see a rectangle create, so I need to the rectangle survey, I mean to string the rectangle survey, Can anyone help me with this.
Thanks for your help.
The application itself draws that rectangle.

Perhaps you could describe your problem a bit better? I think I understand it, that you want to capture the range of the rectangle, but I am not quite sure of your implementation, environment, etc.
Jun 11 '07 #2
Atran
319 100+
The application itself draws that rectangle.

Perhaps you could describe your problem a bit better? I think I understand it, that you want to capture the range of the rectangle, but I am not quite sure of your implementation, environment, etc.
Hello:
I dont want draw that, I want to capture the rectangle survey, the rectangle I talk about is the rectangle when you press left-Mouse button and drag the mouse in the desktop (windows explorer).
IF cant solve this, give me the rectangle position(x, y).
Thanks.....
Jun 11 '07 #3
TRScheel
638 Expert 512MB
Hello:
I dont want draw that, I want to capture the rectangle survey, the rectangle I talk about is the rectangle when you press left-Mouse button and drag the mouse in the desktop (windows explorer).
IF cant solve this, give me the rectangle position(x, y).
Thanks.....
When I did it, I just grabbed the mousedown and mouseup events. Their mouse event args have the location of the mouse at the time.

But that would only work if YOUR program held the focus. If it does not, you will need a workaround, in which the only way I know how to do so would be with DirectX.

If you want that workaround, tell me and I will post some code for it.
Jun 11 '07 #4
Atran
319 100+
When I did it, I just grabbed the mousedown and mouseup events. Their mouse event args have the location of the mouse at the time.

But that would only work if YOUR program held the focus. If it does not, you will need a workaround, in which the only way I know how to do so would be with DirectX.

If you want that workaround, tell me and I will post some code for it.
Yes I want it.
Now I installing "DirectX 9.0b Software Development Kit (SDK) for C#" and Downloading DirectX 9.0b SDK Developer Runtime.
Thanks very much.
Jun 11 '07 #5
Plater
7,872 Expert 4TB
You can do it with a Global Hook
You can get mouse informations (x,y, button presses) as well as your standard keyboard presses even when your program does not have focus.
Jun 11 '07 #6
Atran
319 100+
You can do it with a Global Hook
You can get mouse informations (x,y, button presses) as well as your standard keyboard presses even when your program does not have focus.
Thanks very much for your help, the way was cool.....
But if you can help me with Rectangle Survey using DirectX.
Thanks...
Jun 11 '07 #7
TRScheel
638 Expert 512MB
Yes I want it.
Now I installing "DirectX 9.0b Software Development Kit (SDK) for C#" and Downloading DirectX 9.0b SDK Developer Runtime.
Thanks very much.
I think 9.0c is the newest runtime kit

Well first things first, make sure you reference Microsoft.DirectX.DirectInput and Microsoft.DirectX

Well this was something I threw up for you, its REALLY dirty, so take it for its functionality.

Oh and good luck reading the output. Its PURELY an example, to show how to use it. Also, the X and Y are relative to the last poll position.

Left Mouse button = 0
Right mouse button = 1

and the rest depends on your mouse.

Also, you can adjust the thread.sleep(#) to suite your needs. I wouldnt go lower than 10 though, because it is in an infinite loop and there is nothing to stop that thing from sucking all your processing power. 100 should actually do fine, although if you want finer control, go down to 20 or 30. 10 is pretty extreme.

The last bit hides the form (Just because its an ugly grey box) and we are only using it for the hook.

And finally, there is yet ANOTHER method I forgot about. Windows hooks. You can hook into the message hook and take out the information. Its a little bit uglier then this, if thats possible.

Well, enjoy!

Expand|Select|Wrap|Line Numbers
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Text;
  4. using Microsoft.DirectX;
  5. using Microsoft.DirectX.DirectInput;
  6. using System.Windows.Forms;
  7. using System.Threading;
  8.  
  9. namespace DXInput
  10. {
  11.     class Program
  12.     {
  13.         static void Main(string[] args)
  14.         {
  15.             using(MyForm MainForm = new MyForm())
  16.             {
  17.                 MouseController MSController = new MouseController(MainForm);
  18.                 Thread mouseThread = new Thread(MSController.CheckForInput);
  19.                 MSController.MouseClicked += new MouseController.MouseButtonClicked(MSController_MouseClicked);
  20.                 mouseThread.Start();
  21.                 Application.Run(MainForm);
  22.             }
  23.         }
  24.  
  25.         static void MSController_MouseClicked(MouseController.MouseClickInformation CurrentMouseClickInformation)
  26.         {
  27.             Console.WriteLine(CurrentMouseClickInformation.ButtonOrdinal);
  28.             Console.WriteLine(CurrentMouseClickInformation.CurrentState);
  29.             Console.WriteLine(CurrentMouseClickInformation.X_Position);
  30.             Console.WriteLine(CurrentMouseClickInformation.Y_Position);
  31.         }
  32.     }
  33.  
  34.     public class MouseController
  35.     {
  36.         public struct MouseClickInformation
  37.         {
  38.             public enum ButtonState
  39.             {
  40.                 Down,
  41.                 Up
  42.             }
  43.  
  44.             public int ButtonOrdinal, X_Position, Y_Position;
  45.             public ButtonState CurrentState;
  46.         }
  47.  
  48.         private MouseObject _MouseObject;
  49.         public delegate void MouseButtonClicked(MouseClickInformation CurrentMouseClickInformation);
  50.         public event MouseButtonClicked MouseClicked = new MouseButtonClicked(EmptyMouseHandler);
  51.  
  52.         public MouseController(MyForm Parent)
  53.         {
  54.             _MouseObject = new MouseObject(Parent);
  55.         }
  56.  
  57.         public void CheckForInput()
  58.         {
  59.  
  60.             while (true)
  61.             {
  62.                 MouseState CurrentState;
  63.  
  64.                 _MouseObject.Poll();
  65.                 CurrentState = _MouseObject.State();
  66.  
  67.                 for (int i = 0; i < CurrentState.GetMouseButtons().Length; i++)
  68.                 {
  69.                     MouseClickInformation MCI = new MouseClickInformation();
  70.                     MCI.ButtonOrdinal = i;
  71.                     if (CurrentState.GetMouseButtons()[i] == 0)
  72.                         MCI.CurrentState = MouseClickInformation.ButtonState.Up;
  73.                     else
  74.                         MCI.CurrentState = MouseClickInformation.ButtonState.Down;
  75.  
  76.                     MCI.X_Position = CurrentState.X;
  77.                     MCI.Y_Position = CurrentState.Y;
  78.  
  79.                     MouseClicked.Invoke(MCI);
  80.                 }
  81.  
  82.                 Thread.Sleep(10);
  83.             }
  84.         }
  85.  
  86.         private static void EmptyMouseHandler(MouseClickInformation CurrentMouseClickInformation)
  87.         { }
  88.     }
  89.  
  90.     public class MouseObject
  91.     {
  92.         private Microsoft.DirectX.DirectInput.Device _MasterDevice;
  93.  
  94.         public MouseObject(MyForm Parent)
  95.         {
  96.             _MasterDevice = new Device(SystemGuid.Mouse);
  97.             _MasterDevice.SetCooperativeLevel(Parent, CooperativeLevelFlags.Background | CooperativeLevelFlags.NonExclusive);
  98.             try
  99.             {
  100.                 _MasterDevice.Acquire();
  101.             }
  102.             catch(Exception e)
  103.             {
  104.                 Console.WriteLine(e.Message);
  105.             }
  106.         }
  107.  
  108.         public void Poll()
  109.         {
  110.             _MasterDevice.Poll();
  111.         }
  112.  
  113.         public MouseState State()
  114.         {
  115.             return _MasterDevice.CurrentMouseState;
  116.         }
  117.     }
  118.  
  119.     public class MyForm : System.Windows.Forms.Form
  120.     {
  121.         public MyForm() : base()
  122.         {
  123.             // Add code here to hide the form if need be
  124.             this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.Fixed3D;
  125.             this.ShowInTaskbar = false;
  126.             this.WindowState = FormWindowState.Minimized;
  127.             this.Hide();
  128.         }
  129.     }
  130. }
Jun 11 '07 #8
TRScheel
638 Expert 512MB
Oh ya, one more thing...

There is an Z axis to your mouse. No, it does not register if it is flying or on the table. Its the scroll wheel.
Jun 11 '07 #9
TRScheel
638 Expert 512MB
You can do it with a Global Hook
You can get mouse informations (x,y, button presses) as well as your standard keyboard presses even when your program does not have focus.

Wow, I feel like I took a bazooka to a job requiring a pin.
Jun 11 '07 #10
Atran
319 100+
Oh ya, one more thing...

There is an Z axis to your mouse. No, it does not register if it is flying or on the table. Its the scroll wheel.
Thanks TRScheel, you are a prefect programmer.
Jun 11 '07 #11
TRScheel
638 Expert 512MB
Thanks TRScheel, you are a prefect programmer.
oO

Sarcasm is hard to show through text... hehe, no problem.

If you want some more DirectX stuff, I could point you at a couple sites I like.
Jun 12 '07 #12

Sign in to post your reply or Sign up for a free account.

Similar topics

1
by: GTF | last post by:
PHP Web Survey Idea.. I have been given an opportunity to create a web based survey. This is a fairly lengthy survey of 60 pages on paper (various multiple choice and free form). These are...
15
by: Steven T. Hatton | last post by:
The following may strike many of you as just plain silly, but it represents the kind of delelima I find myself in when trying to make a design decision. This really is a toy project written for...
1
by: Nico Baumgarten | last post by:
Dear Madam/Sir, You are invited to participate in an international research study. This research project is headed and led by Cambridge student Nico Baumgarten. What is it all about? It is a...
3
by: | last post by:
I am having a hard time understanding the logic behind the Rectangle object. My problem has to do with the way the rectangle treats the "Width" property. For example, take the following rectangle...
4
by: RobinS | last post by:
I am drawing a rectangle on a picture that has already been drawn on the graphics area (a user control). It works something like this: //in the MouseDown event m_isDragging = true; m_oldX =...
0
by: Janet93 | last post by:
If you are involved in the development of scientific computing software, you are invited to participate in a survey on developing this kind of software. If you have already received this request, I...
1
by: kummu4help | last post by:
hi, i want to draw rectangle based on mousedrag event. if user dragging the mouse, then the rectangle on the applet should increase or decrease basing on current mouse coordinates. i have the...
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
0
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.