Click here to Skip to main content
16,016,500 members
Home / Discussions / C#
   

C#

 
GeneralProblems with PAINT program Pin
Luc Pattyn19-Dec-07 5:21
sitebuilderLuc Pattyn19-Dec-07 5:21 
GeneralSession Pin
anupamwb19-Dec-07 3:38
anupamwb19-Dec-07 3:38 
GeneralRe: Session Pin
DotNetXenon19-Dec-07 9:57
DotNetXenon19-Dec-07 9:57 
GeneralRe: Session Pin
anupamwb20-Dec-07 3:02
anupamwb20-Dec-07 3:02 
GeneralGenerics - How to implement Compare Methods Pin
gunner_uk200019-Dec-07 2:27
gunner_uk200019-Dec-07 2:27 
GeneralRe: Generics - How to implement Compare Methods Pin
OsoreWatashi19-Dec-07 2:52
OsoreWatashi19-Dec-07 2:52 
GeneralRe: Generics - How to implement Compare Methods Pin
LongRange.Shooter19-Dec-07 11:18
LongRange.Shooter19-Dec-07 11:18 
QuestionCapturing messeges from other program Pin
OsoreWatashi19-Dec-07 2:14
OsoreWatashi19-Dec-07 2:14 
I am working with Visual Studio 2008, .NET Framework 3.5 and C#.

I have my own Console Application that needs some functionality. Currently it is able to change the Windowtitles, read it's location on the screen, read it's width and height, send mouse-events and send key-events. This can be done to any open window, as long as I have the handle for it (which normally never is the problem).

The only thing I am missing is how to capture the messages that are send to this handle. With Spy++ I am able to see all the messages send to a window, I want the same functionality in my Console Application.

A simple example of such message will be: WM_MOUSEMOVE fwKeys:0000 xPos:10 yPos10

To make everything clear what I exactly want:
My Console Application has to read all messages send to a handle that is not created by the Console Application, for instance a window like Internet Explorer or Notepad. Those messages have to be captured.


So far I have tried both GetMessage and PeekMessage. The code I used for that is as follows
<br />
//Get the messages send to the window<br />
[DllImport("User32.dll", CharSet = CharSet.Auto)]<br />
private static extern bool PeekMessage(out MSG msg, IntPtr hWnd, uint messageFilterMin, uint messageFilterMax, uint flags);<br />
<br />
//Get the messages send to the window<br />
[DllImport("User32.dll", CharSet = CharSet.Auto)]<br />
private static extern bool GetMessage(out MSG msg, IntPtr hWnd, uint messageFilterMin, uint messageFilterMax);<br />
<br />
[StructLayout(LayoutKind.Sequential)]<br />
public struct MSG<br />
{<br />
    public IntPtr hWnd;<br />
    public uint Message;<br />
    public uint WParam;<br />
    public uint LParam;<br />
    public uint Time;<br />
    public System.Drawing.Point Point;<br />
}<br />
<br />
static void Main(string[] args)<br />
{<br />
    System.Threading.Thread.Sleep(2000);<br />
    <br />
    MSG msg;<br />
    while (PeekMessage(out msg, new IntPtr(0x000A053A), 0, 0, 0))<br />
    {<br />
        //Bla<br />
        System.Threading.Thread.Sleep(2000);<br />
    }<br />
    <br />
    while (GetMessage(out msg, new IntPtr(0x000A053A), 0, 0, 0))<br />
    {<br />
        //Bla<br />
        System.Threading.Thread.Sleep(2000);<br />
    }<br />
}<br />

For me, this always results a false value for both the PeekMessage and GetMessage methods and thus no value in msg. Does anybody know how to solve my problem?

Thank you very much in advance!
AnswerRe: Capturing messeges from other program Pin
TJoe20-Dec-07 3:11
TJoe20-Dec-07 3:11 
GeneralRe: Capturing messeges from other program Pin
OsoreWatashi28-Dec-07 3:45
OsoreWatashi28-Dec-07 3:45 
General[Message Deleted] Pin
eyeseetee19-Dec-07 1:02
eyeseetee19-Dec-07 1:02 
GeneralRe: strange problem with stored procedure Pin
Pete O'Hanlon19-Dec-07 1:18
mvePete O'Hanlon19-Dec-07 1:18 
GeneralRe: Deleted Message Pin
Paul Conrad24-Dec-07 19:44
professionalPaul Conrad24-Dec-07 19:44 
QuestionC#:Doubt in event handler? Pin
kssknov19-Dec-07 0:14
kssknov19-Dec-07 0:14 
GeneralRe: C#:Doubt in event handler? Pin
Giorgi Dalakishvili19-Dec-07 0:25
mentorGiorgi Dalakishvili19-Dec-07 0:25 
GeneralRe: C#:Doubt in event handler? Pin
Xmen Real 19-Dec-07 3:41
professional Xmen Real 19-Dec-07 3:41 
GeneralEntering null values from ComboBox Pin
AndrusM18-Dec-07 23:57
AndrusM18-Dec-07 23:57 
QuestionC#: How to change the color of a disabled textbox? Pin
kssknov18-Dec-07 22:45
kssknov18-Dec-07 22:45 
GeneralRe: C#: How to change the color of a disabled textbox? Pin
Pete O'Hanlon18-Dec-07 23:02
mvePete O'Hanlon18-Dec-07 23:02 
GeneralRe: C#: How to change the color of a disabled textbox? Pin
kssknov19-Dec-07 0:12
kssknov19-Dec-07 0:12 
GeneralRe: C#: How to change the color of a disabled textbox? Pin
Paul Conrad24-Dec-07 19:47
professionalPaul Conrad24-Dec-07 19:47 
GeneralRe: C#: How to change the color of a disabled textbox? Pin
Pete O'Hanlon19-Dec-07 0:51
mvePete O'Hanlon19-Dec-07 0:51 
GeneralRe: C#: How to change the color of a disabled textbox? Pin
Kalvin @ Work19-Dec-07 3:17
Kalvin @ Work19-Dec-07 3:17 
GeneralRe: C#: How to change the color of a disabled textbox? Pin
Xmen Real 19-Dec-07 3:47
professional Xmen Real 19-Dec-07 3:47 
GeneralRe: C#: How to change the color of a disabled textbox? Pin
V.19-Dec-07 4:26
professionalV.19-Dec-07 4:26 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.