Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. How do I write to another window through a C# form [modified]

How do I write to another window through a C# form [modified]

Scheduled Pinned Locked Moved C#
helpquestioncsharpalgorithms
2 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • D Offline
    D Offline
    Deresen
    wrote on last edited by
    #1

    Hello everyone, I'm making a program, but I'm (obviously) stuck with a problem. I want to write a message to the current topscreen through a C# application. For instance: when you open Microsoft Word and you type 'hello' it will double the word like this 'hheelllloo'. The application allready knows when a key is pushed, now the only thing that will have to be done is write a message to the current top window (like word or notepad or whatever window is open and where you are typing in). I guess that this is possible with something like PostMessage and GetTopWindow. But it won't work. Can anybody tell me what I'm doing wrong? Or can someone tell me what will work? Thank you allready. This is what I have:

        \[DllImport("user32.dll")\]
        public static extern int GetTopWindow(int hwnd);
        \[DllImport("user32.dll")\]
        public static extern int PostMessage(int hWnd, uint Msg, int wParam, uint lParam);
        
        //..code
        const int VK\_KEY = 0x41;
        const int WM\_CHAR = 0x0102;
              
        int WindowToFind = GetTopWindow(0);
        Console.WriteLine(WindowToFind);
        int result = PostMessage(WindowToFind, WM\_CHAR, VK\_KEY, 0);
        Console.WriteLine(result);
    

    The output for result is always 1. The output for WindowToFind is different, sometimes it gives the same value at different windows. Sometimes a different value. One of the outcome of WindowToFind is 131138 edit: Allright... finaly I found out the anwser to my problem (after hours of searching :P). I just had to use the SendKeys class.

    SendKeys.SendWait("");

    modified on Wednesday, March 5, 2008 5:42 AM

    V 1 Reply Last reply
    0
    • D Deresen

      Hello everyone, I'm making a program, but I'm (obviously) stuck with a problem. I want to write a message to the current topscreen through a C# application. For instance: when you open Microsoft Word and you type 'hello' it will double the word like this 'hheelllloo'. The application allready knows when a key is pushed, now the only thing that will have to be done is write a message to the current top window (like word or notepad or whatever window is open and where you are typing in). I guess that this is possible with something like PostMessage and GetTopWindow. But it won't work. Can anybody tell me what I'm doing wrong? Or can someone tell me what will work? Thank you allready. This is what I have:

          \[DllImport("user32.dll")\]
          public static extern int GetTopWindow(int hwnd);
          \[DllImport("user32.dll")\]
          public static extern int PostMessage(int hWnd, uint Msg, int wParam, uint lParam);
          
          //..code
          const int VK\_KEY = 0x41;
          const int WM\_CHAR = 0x0102;
                
          int WindowToFind = GetTopWindow(0);
          Console.WriteLine(WindowToFind);
          int result = PostMessage(WindowToFind, WM\_CHAR, VK\_KEY, 0);
          Console.WriteLine(result);
      

      The output for result is always 1. The output for WindowToFind is different, sometimes it gives the same value at different windows. Sometimes a different value. One of the outcome of WindowToFind is 131138 edit: Allright... finaly I found out the anwser to my problem (after hours of searching :P). I just had to use the SendKeys class.

      SendKeys.SendWait("");

      modified on Wednesday, March 5, 2008 5:42 AM

      V Offline
      V Offline
      V 0
      wrote on last edited by
      #2

      maybe GetDlgItem and GetWindowText or SetWindowText can help ? just an idea.

      V.
      Stop smoking so you can: Enjoy longer the money you save. Moviereview Archive

      1 Reply Last reply
      0
      Reply
      • Reply as topic
      Log in to reply
      • Oldest to Newest
      • Newest to Oldest
      • Most Votes


      • Login

      • Don't have an account? Register

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • World
      • Users
      • Groups