FindWindow

Im having a issue with finding a window. I can use (code below) and find the active notepad window
HWND hc;
hc = GetDlgItem(FindWindow(NULL,"Untitled - Notepad"),15);

When i use (code below) the window is never found. This is the correct class and title names.
HWND hc;
hc = FindWindow("Notepad","Untitled-Notepad");

I am actually looking to send a messages to the external window. I have the class name and the title name, but dont seem to be able to get a handle to it. I used spy and WinID to get the handle and class names. Any suggestions how to solve this. I nice code snippet would be greatly appreciated.


Paul






Comments

  • Umm, what about:
    [code]
    hc = FindWindow("Notepad","Untitled - Notepad");
    [/code]
  • typo, sorry. I have that correct. Using the below code i can make the notepad window active.
    hc = FindWindow("Notepad","Untitled - Notepad");
    ShowWindow(hc,SW_SHOWNORMAL);
    SetForegroundWindow(hc);

    but the hotkeys i registered only work on the notepad window when i use the following?

    hc = GetDlgItem(FindWindow("Notepad","Untitled - Notepad"),15);

    Any suggestions?







  • FOUND THE SOLUTION:
    for some reason sendmesssge would not work even when i had the handle to the window. This code below is actually what i wanted since i needed to send data to any active window. case 7 is for the registered hotkey in my app. Simple solution.
    Thanks so much for your help.

    case 7:
    hc = GetForegroundWindow();
    keybd_event ((CHAR)(SHORT)VkKeyScan('M'), 0, 0, 0 );
    return 0;
  • You can't send messages to windows not belonging to the procedure sending them. There are several ways around this: hooks, inject code in another process, attach dlls to another process etc. All of it are advanced topics that I'm not the right person to explain, as the Win API isn't my forte. Codeproject.com has several examples of how to do things like this.
  • : You can't send messages to windows not belonging to the procedure
    : sending them.

    [color=Blue]Some messages cannot be sent. However, recently, I was involved in a project where two processes are posting (PostMessage) messages to each other and that was working fine. Message IDs were in range WM_USER + xxx.[/color]

    There are several ways around this: hooks, inject code
    : in another process, attach dlls to another process etc. All of it
    : are advanced topics that I'm not the right person to explain, as the
    : Win API isn't my forte. Codeproject.com has several examples of how
    : to do things like this.
Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories