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 / C++ / MFC
  4. Sending text to chat via Edit

Sending text to chat via Edit

Scheduled Pinned Locked Moved C / C++ / MFC
helplounge
3 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.
  • T Offline
    T Offline
    tansey4
    wrote on last edited by
    #1

    I have a 3rd party program which contains a chat area. I am trying to create a function which sends a message to that chat. I have the handle to the parent window and the handle to the Edit window where you type. I am not having any trouble setting the text in the Edit window, my issue is sending the text. All I want to do is be able to send the box a simulated Return key press, but I'm having a lot of issues with it and can't seem to get it to work. I spied the window and when a real Return is pressed, it generates two messages: P WM_KEYDOWN nVirtKey:VK_RETURN cRepeat:1 ScanCode:1C fExtended: 0 fAltDown: 0 fRepeat: 0 fUp: 0 P WM_KEYUP nVirtKey:VK_RETURN cRepeat:1 ScanCode:1C fExtended: 0 fAltDown: 0 fRepeat:1 fUp:1 For KEYDOWN, the parameters are: wParam: 0000000D lParam: 001C0001 For KEYUP, the parameters are: wParam: 0000000D lParam: C01C0001 Given all this information, my current function looks like: void say( const char* toSay ) { HWND tempa = SetActiveWindow( hwnd ); HWND tempw = SetFocus( chatBox ); Sleep(500); SendMessage( chatBox, WM_SETTEXT, (WPARAM)0, (LPARAM)toSay ); Sleep(1000); PostMessage( chatBox, WM_KEYDOWN, VK_RETURN, 0x001C0001 ); Sleep(2000); PostMessage( chatBox, WM_KEYUP, VK_RETURN, 0xC01C0001 ); Sleep(2000); SetFocus( tempw ); SetActiveWindow( tempa ); } I have had very little success with this method. It will sometimes send the first message it gets but then will no longer send anything. It seems like this should be much simpler, as I'm sure it's a common need. Any help is greatly appreciated.

    V 1 Reply Last reply
    0
    • T tansey4

      I have a 3rd party program which contains a chat area. I am trying to create a function which sends a message to that chat. I have the handle to the parent window and the handle to the Edit window where you type. I am not having any trouble setting the text in the Edit window, my issue is sending the text. All I want to do is be able to send the box a simulated Return key press, but I'm having a lot of issues with it and can't seem to get it to work. I spied the window and when a real Return is pressed, it generates two messages: P WM_KEYDOWN nVirtKey:VK_RETURN cRepeat:1 ScanCode:1C fExtended: 0 fAltDown: 0 fRepeat: 0 fUp: 0 P WM_KEYUP nVirtKey:VK_RETURN cRepeat:1 ScanCode:1C fExtended: 0 fAltDown: 0 fRepeat:1 fUp:1 For KEYDOWN, the parameters are: wParam: 0000000D lParam: 001C0001 For KEYUP, the parameters are: wParam: 0000000D lParam: C01C0001 Given all this information, my current function looks like: void say( const char* toSay ) { HWND tempa = SetActiveWindow( hwnd ); HWND tempw = SetFocus( chatBox ); Sleep(500); SendMessage( chatBox, WM_SETTEXT, (WPARAM)0, (LPARAM)toSay ); Sleep(1000); PostMessage( chatBox, WM_KEYDOWN, VK_RETURN, 0x001C0001 ); Sleep(2000); PostMessage( chatBox, WM_KEYUP, VK_RETURN, 0xC01C0001 ); Sleep(2000); SetFocus( tempw ); SetActiveWindow( tempa ); } I have had very little success with this method. It will sometimes send the first message it gets but then will no longer send anything. It seems like this should be much simpler, as I'm sure it's a common need. Any help is greatly appreciated.

      V Offline
      V Offline
      VikramDelhi i
      wrote on last edited by
      #2

      watch out this http://www.codeproject.com/dialog/keystroke.asp[^]

      T 1 Reply Last reply
      0
      • V VikramDelhi i

        watch out this http://www.codeproject.com/dialog/keystroke.asp[^]

        T Offline
        T Offline
        tansey4
        wrote on last edited by
        #3

        Thanks for the link Vikram, however it seems that there is a bug with that engine (and the user comments seem to confirm) that creates problems with XP. From what I saw in the source of that project, I thought that this would work: void say( const char* toSay ) { if( !SetForegroundWindow( chatBox ) ){ cout << "COULD NOT SET CHATBOX TO ACTIVE" << endl; } Sleep(500); UINT scan = MapVirtualKey( VK_RETURN, 0 ); Sleep(500); SendMessage( chatBox, WM_SETTEXT, (WPARAM)0, (LPARAM)toSay ); Sleep(2000); keybd_event(VK_RETURN, scan, KEYEVENTF_EXTENDEDKEY | 0, 0 ); Sleep(2000); keybd_event(VK_RETURN, scan, KEYEVENTF_EXTENDEDKEY | KEYEVENTF_KEYUP, 0); } However, that doesn't seem to work. As in my previously posted function, the chatBox is set with the text and when VK_RETURN is sent it does clear, but it does not show up in the chat, it just gets cleared. I'm not sure why this is. -- modified at 3:43 Saturday 17th December, 2005

        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