Thread: Findwindow Sendmessage Help

  1. #1
    Registered User
    Join Date
    Jul 2003
    Posts
    110

    Findwindow Sendmessage Help

    Hello all.

    Ok im making a macro program...

    I got this...



    Code:
    #include <windows.h>
    
    int main(void)
    {
    	int i;
    	char test;
    	HWND hwndEdit = 0;
    	HWND hwnd = 0;
    	i = 0;
    	//Get main notepad handle
    	while(hwnd==0)
    		hwnd = FindWindow("Notepad","a - Notepad");
    
    	while(hwndEdit==0)
    		hwndEdit = FindWindowEx(hwnd,0,"Edit",0);
    
    	//write an 'a'
    	
    	test = 97;
    
    	for(i=0;i<10;i++)
    	SendMessage(hwnd,WM_CHAR,test,0);
    
    	return 0; 
    }

    All that I want to do, is send a message to the notepad and display 'a' 10 times to it while its up.

    I used spy++ to check if the handles were right for each window and everything checked out OK in debugger.

    Does anyone notice whats wrong with this?

  2. #2
    Registered User
    Join Date
    Jul 2003
    Posts
    110
    I GOT IT


    I LEFT SENDMESSAGE AS HWND AND DINT CHANGE IT TO HWNDEDIT!!!!

  3. #3
    Registered User
    Join Date
    Jul 2003
    Posts
    110
    Hmm, this program doesnt take in the enter key for some reason.

    I sent it (ASCII 13) but it doesnt respond to it.

    does anyone know how to send the F1-F12 keys using SendMessage ?

  4. #4
    Registered User
    Join Date
    Feb 2002
    Posts
    329
    Have you tried sending a WM_KEYDOWN message?

  5. #5
    Registered User
    Join Date
    Jun 2003
    Posts
    245
    You can send F1 - F12 as virtual keys.

  6. #6
    Registered User
    Join Date
    Jul 2003
    Posts
    110
    Yeah I tried WM_KEYDOWN.

    Is it possiable a program can block incoming enter keys?

    Before i test something, I test it in notepad and it works fine.

    For some reason the program just doesnt let me send the enter key to execute a chat.

    Example. I send aaaaa then the enter key then aaaaa.

    In notepad it looks like this.

    aaaaaa
    aaaaaa

    In the program it just goes aaaaaaaaaaaa so it ignores the enter key...

    im actually using 13 carraige return but im guessing thats the enter key.
    Coder

  7. #7
    Yes, my avatar is stolen anonytmouse's Avatar
    Join Date
    Dec 2002
    Posts
    2,544
    An enter in windows equals carriage return followed by newline.
    ie. crlf = "\r\n"
    printf, etc convers \n to the return character(s) for the operating system.

  8. #8
    It's full of stars adrianxw's Avatar
    Join Date
    Aug 2001
    Posts
    4,829
    You should also be aware that some applications react to the WM_KEYUP rather than down. It will do no harm to send both since that is what a user would do.
    Wave upon wave of demented avengers march cheerfully out of obscurity unto the dream.

  9. #9
    Registered User
    Join Date
    Jul 2003
    Posts
    110

    Ok

    i have sent it

    SendMessage(hwnd,WM_CHAR,13,0);
    SendMessage(hwnd,WM_KEYDOWN,VK_RETURN,0);
    SendMessage(hwnd,WM_KEYUP,VK_RETURN,0);
    SendMessage(hwnd,WM_KEYUP,13,0);
    SendMessage(hwnd,WM_KEYDOWN,13,0);
    SendMessage(hwnd,WM_CHAR,'\r\n',0);
    SendMessage(hwnd,WM_CHAR,'\r',0);
    SendMessage(hwnd,WM_CHAR,'\n',0);
    SendMessage(hwnd,WM_CHAR,VK_RETURN,0);
    SendMessage(hwnd,WM_KEYDOWN,'\r\n',0);
    SendMessage(hwnd,WM_KEYUP,'\r\n',0);
    SendMessage(hwnd,WM_KEYDOWN,'\n',0);
    SendMessage(hwnd,WM_KEYUP,'\n',0);
    SendMessage(hwnd,WM_KEYDOWN,'\r\n',0);
    SendMessage(hwnd,WM_KEYUP,'\r\n',0);


    all of those, and still no enter key is being pressed.

    I can send characters to it, but it wont execute the enter key.

  10. #10
    Registered User
    Join Date
    Jun 2003
    Posts
    245
    Sending more than one character in keyup/keydown/etc is a bad idea as the function will ignore both (it only supports one keypress at a time, so will take your doubles as an invalid key and ignore).

  11. #11
    Registered User
    Join Date
    Jul 2003
    Posts
    110
    How do i make a program think that the enter key has been pressed?

  12. #12
    Registered User
    Join Date
    Feb 2002
    Posts
    329
    Try this:
    Code:
    SendMessage(hwnd,WM_CHAR,'\r',0);
    SendMessage(hwnd,WM_CHAR,'\n',0);

  13. #13
    Registered User
    Join Date
    Jul 2003
    Posts
    110
    Hmm

    Is it possiable that a program has blocked out keys that are sent in.

    Example.

    I can send in any key and it will be put on the chat bar. most ANSI keys. For some reason if I make a key like 'a' a macro that performs a task it does nothing when i send it with sendmessage.
    I know its sending in the key 'a' i see it in the chat bar but it does no actions.

    Does anyone know how I make sure that the program thinks a key was pressed?

  14. #14
    Programming is fun, mkay?
    Join Date
    Oct 2001
    Posts
    490

    Lightbulb I think this is how ...

    Try this:

    keybd_event(VK_RETURN, 0, KEYEVENTF_EXTENDEDKEY, 0);
    keybd_event(VK_RETURN, 0, KEYEVENTF_KEYUP, 0);
    Website(s): http://www16.brinkster.com/trifaze/

    E-mail: [email protected]

    ---------------------------------
    C++ Environment: MSVC++ 6.0; Dev-C++ 4.0/4.1
    DirectX Version: 9.0b
    DX SDK: DirectX 8.1 SDK

  15. #15
    Registered User
    Join Date
    Jul 2003
    Posts
    110
    With that, the window has to be ontop, is there anyway I can send that and the window not be ontop?

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. SendMessage
    By reefa in forum Windows Programming
    Replies: 15
    Last Post: 07-18-2005, 03:36 PM
  2. Combobox problem
    By gargamel in forum Windows Programming
    Replies: 2
    Last Post: 05-06-2005, 01:37 PM
  3. WM_KEYDOWN and SendMessage
    By Unregistered in forum Windows Programming
    Replies: 4
    Last Post: 07-13-2002, 05:23 PM
  4. FindWindow()
    By face_master in forum Windows Programming
    Replies: 2
    Last Post: 05-27-2002, 11:53 AM
  5. SendMessage causes an exception in release.
    By DS in forum Windows Programming
    Replies: 1
    Last Post: 11-27-2001, 11:34 AM