Thread: newbie question: SendMessage

  1. #1
    Registered User
    Join Date
    Aug 2003
    Posts
    22

    newbie question: SendMessage

    Does the following code make any sense at all or am I way off?
    Code:
    wnd=FindWindow(NULL,"target window");
    SendMessage(wnd,WM_RBUTTONDOWN,0,LPARAM(100,100));
    The idea is to simulate a mouseclick in another window.
    But it doesn't do anything.
    Maybe I'm obtaining window handle wrong? The string "target window" is in target windows name. I have no idea how to get handle in a better way than findwindow.


    Thanks.

    *edit*
    Tried what I saw in other thread here:
    Code:
    wnd=FindWindow(NULL,"Notepad");
    SendMessage(wnd,WM_CHAR,97,0);
    Still nothing happened.
    Could it be because I'm using C++ builder?
    Last edited by freedik; 08-17-2003 at 08:42 AM.

  2. #2
    Registered User
    Join Date
    Jun 2003
    Posts
    245
    If you know the other application, then include the class name as well. Also validate against NULL to make sure the window was actually found.

    And no, it's not because you are using C++ Builder.

  3. #3
    Registered User
    Join Date
    Aug 2003
    Posts
    22
    Getting smarter...
    Looked up at WinSight that notepads class is "Notetab" and used wnd = FindWindow("Notepad",NULL); instead. Also found out that I have to target it's child window ("Edit") instead.
    I'll be a messaging guru in no time

    Finding right window among those 100 in WinSight(Borland) can be a pain, if not impossible. I wonder why there isn't "search" feature...
    Can anyone advise a better program for tracking down windows?

    *edited*

    Found some handy program called SPY, it tells me every windows class, title, index and handle. I have no idea what this index means.
    Heres the code I'm trying to make work:
    Code:
    wnd = FindWindow("Parent win classname",NULL);
    if(wnd==NULL){
        sprintf(s,"Failed to find handle");
        StatusBar1->Panels->Items[0]->Text = s;
        return;
        }
    
    ewnd=FindWindowEx(wnd,NULL,"Child win class name",NULL);
    if(ewnd==NULL){
        sprintf(s,"Failed to find child handle");
        StatusBar1->Panels->Items[0]->Text = s;
        return;
        }
    It finds parent but not child. What could be wrong?
    Last edited by freedik; 08-17-2003 at 11:04 AM.

  4. #4
    Registered User
    Join Date
    Dec 2002
    Posts
    162
    If you’re only looking for a program that will show you all child/controls of a parent window then use the "famous" Spy++ program, if you don’t have it then just search on it. There are thousands of window spy programs out there. You can also write your own enumerating window program.
    We haven't inherited Earth from our parents; instead we have borrowed her from our children - old Indian saying.

  5. #5
    Registered User
    Join Date
    Aug 2003
    Posts
    22
    Oh my god! I just found out that the window I want to use is over 10 levels lower than its topmost parent. Does that mean that I have to write over 10 FindWindowEx's to finally get my handle?
    The parent relations are something like this:
    Main->win1->win2->...->win10->mywindow

    Couldn't I just get the handle regardless what parents this window has?

  6. #6
    Registered User
    Join Date
    Jun 2003
    Posts
    245
    If you have the class name and window title, a single call will get your window handle regardless of how many levels "deep" it is.

    As for a spy program, I use this one:

    WinSpy++ 1.5 for Windows XP/NT/2000/9x/ME
    Copyright (c) 2001-2002 J Brown
    www.catch22.uk.net

    It even comes with source code (in Visual C++ 6) which comes in very handy for tweaking it.

  7. #7
    Registered User
    Join Date
    Aug 2003
    Posts
    22
    Originally posted by _Elixia_
    If you have the class name and window title, a single call will get your window handle regardless of how many levels "deep" it is.
    Thats what I thought too. But windows cant find this window simply by class name(it has no title). Could it have anything to do with this "index" attribute that spy program showed me about this window?

    Originally posted by _Elixia_

    As for a spy program, I use this one:

    WinSpy++ 1.5 for Windows XP/NT/2000/9x/ME
    Copyright (c) 2001-2002 J Brown
    www.catch22.uk.net

    It even comes with source code (in Visual C++ 6) which comes in very handy for tweaking it.
    Thanks, I'll check it out. For now I used some prog called simply SPY. As for tweaking it, I don't think it's a good thing to do for a noob like me

    *edit*

    It appears that _Elixia_ was actually wrong. When I went down level after level, I finally got the handle. Even if I tried to skip one level, it failed. So it does matter "how deep" that window is...
    Last edited by freedik; 08-18-2003 at 11:36 AM.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Stupid Newbie question
    By TimL in forum C++ Programming
    Replies: 4
    Last Post: 07-22-2008, 04:43 AM
  2. Newbie with Very Newbie Question
    By Jedi_Mediator in forum C++ Programming
    Replies: 18
    Last Post: 07-01-2008, 08:00 AM
  3. C prog newbie question
    By Draginzuzu in forum C Programming
    Replies: 1
    Last Post: 02-03-2003, 06:45 PM
  4. a stupid question from a newbie
    By newcomer in forum C++ Programming
    Replies: 4
    Last Post: 01-11-2003, 04:38 PM
  5. newbie class templates question
    By daysleeper in forum C++ Programming
    Replies: 2
    Last Post: 09-18-2001, 09:50 AM