CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 2 of 2
  1. #1
    Join Date
    Apr 2014
    Posts
    61

    [RESOLVED] Receiving strangers strings in target window from PostMessage api

    I have a Remote Administration Tool, and I'm with a trouble when receives strings in any window with PostMessage api. The strings are sent through of TextBox component in Server application.

    For example, the word Coder in StackOverflow window stays like this:

    Name:  Screenshot_1.jpg
Views: 154
Size:  10.4 KB

    and my code that I'm using is this:

    Server application

    Code:
    private void tEnviarTexto_Click(object sender, EventArgs e)
            {
    
                String message = String.Format("<|MSG|>{0}", tEnviarMSG.Text);
                ListViewItem item = listView_clients.FocusedItem;
                String clientId = item.Name;
                RemoteClient client = this.remoteClientManager.GetClientById(clientId);
                if (client != null)
                {
                    try
                    {
                        client.mreMessage.WaitOne();
                        client.queueMessage.AddMessage(message);
                        tEnviarMSG.Text = "";
                    }
    
                    catch (Exception ex) { MessageBox.Show(ex.ToString()); }
                }
            }
    Client application

    Code:
     public void EnviatextoHWND(string texto)
            {
                foreach (char caractere in texto)
                {
                    int charValue = caractere;
                    string hexValue = charValue.ToString("X");
                    IntPtr val = new IntPtr((Int32)caractere);
    
                    string valor = val.ToString();
    
                    if (valor == "66") // Letra B no Operador
                    {
                        PostMessage(WindowHandle, WM_KEYDOWN, new IntPtr(VK_BACK), new IntPtr(0));
                        PostMessage(WindowHandle, WM_KEYUP, new IntPtr(VK_BACK), new IntPtr(0));
    
                    }
                    else if (valor == "83") // Letra S no Operador
                    {
                        PostMessage(WindowHandle, WM_KEYDOWN, new IntPtr(VK_SPACE), new IntPtr(0));
                        PostMessage(WindowHandle, WM_KEYUP, new IntPtr(VK_SPACE), new IntPtr(0));
    
                    }
                    else
                    {
    
                        PostMessage(WindowHandle, WM_KEYDOWN, val, new IntPtr(0));
                        PostMessage(WindowHandle, WM_CHAR, val, new IntPtr(0));
                        PostMessage(WindowHandle, WM_KEYUP, val, new IntPtr(0));
    
                    } 
                }
            }

    and usage:


    Code:
    public void CommunicationProc()
        {
    
          while (this.Connected)
            {
             else if (message.IndexOf("<|MSG|>") == 0)
              {
                String[] strSplit = value.Split(MenuRemoteClient.separator, StringSplitOptions.None);
                string msg = strSplit[0]; // content from a TextBox on Server application
    
                       if (this.remotedNav)
                         {
                           Thread SendTextoHWND = new Thread(() => EnviatextoHWND(msg));
                               SendTextoHWND.Start();
                                }
                            }
                    }
                 }
    So, how solve it?

    Any suggestions or guidance here is appreciated.

  2. #2
    Join Date
    Apr 2014
    Posts
    61

    Re: Receiving strangers strings in target window from PostMessage api

    Fixed:

    Code:
                     //   PostMessage(WindowHandle, WM_KEYDOWN, val, new IntPtr(0));
                        PostMessage(WindowHandle, WM_CHAR, val, new IntPtr(0));
                    //    PostMessage(WindowHandle, WM_KEYUP, val, new IntPtr(0));

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured