Sure hope your still around Ancient Dragon your a life saver, and a great teacher

What I'm after-->I am trying to send a message to a button on the parent window--

Ok here's my problem. I am trying to automate an install for various applications.
For my first automation process. I am installing Lumension a security package.
The first window appears and it's title is "Lumension Security Client".

So I set an HWND to the title like so HWND Lumension = FindWindows(0,"Lumension Security Client");
I created a device context HDC Ldc = GetDC(Lumension);
I can paint to the program using setpixel, and if I send Lumension a WM_CLOSE message it will close out.
I downloaded winID to try and help myself out even though I'm a bit clueless to using WinID but know it's similar to spy++.
Since I know the HWND to the Lumension window ... how can I send a key to the button.
When I spy++ the button it's title is "&Next >" so I tried setting an HWND button1 = FindWindow(0,"&Next >");
Then tried sending SendMessage(button1,WM_KEYDOWN,VK_SPACE,0); but nothing happens.

I'll post some code, but any help on how this winID(Spy++ like program) can help me do this would be great.

I also tried broadcasting VK_SPACE to all windows etc.. nothings working!

Operating system: Windows 7 Enterprise edition 64bit OS
here is my install lumension function.

int InstallLumension()
{

    //Map drive A for automation

    system("net use a: \"\\\\172.19.34.33\\software dumps\\balaji\\altrix\" /PERSISTENT:YES && exit");
    system("start a:\\Lumension\\4.4.1003NoAddRemove\\setup.exe && exit");
    Sleep(15000);
    HWND Lumension = FindWindow(0,"Lumension Endpoint Security Client");
    HWND Lb1 = FindWindow(0,"&Next >");
    if(Lumension == 0)
    {
        MessageBox(0,
                        "Lumension Handle Error",
                        "Lumension HWND not defined",
                        MB_ICONINFORMATION);
    };

    //SendMessage(Lumension,WM_CLOSE,0,0);
    MessageBox(0,
                        "Testing Lumension Closed",
                        "Close",
                        MB_ICONINFORMATION);
    //Create Device Context\Brush to paint color zone in for automation troubleshooting
    HDC LumDC = GetDC(Lumension);
    int mousePosX;
    int mousePosY;
    SetFocus(Lumension);
    SetWindowPos(Lumension,HWND_TOPMOST, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE );
    Sleep(200);
    SendMessage(Lb1,WM_KEYDOWN,VK_SPACE,0);
    Sleep(200);
    SendMessage(Lb1,WM_KEYUP,VK_SPACE,0);
    //for(;;)
       // {
    for(mousePosY = 330; mousePosY <= 335;mousePosY++)
    {
        for(mousePosX = 320; mousePosX <= 330; mousePosX++)
        {
            SetPixel(LumDC,mousePosX,mousePosY,redzone);
        SendMessage(Lumension,WM_LBUTTONDBLCLK,0, MAKELPARAM(mousePosX, mousePosY));
        };
    }
    PostMessage(HWND_BROADCAST,WM_KEYDOWN,0x20,0);
    PostMessage(HWND_BROADCAST,WM_KEYUP,0x20,0);
   // }// end forever loop

    Sleep(300);

    PostMessage(Lumension,WM_KEYDOWN,0x20,0);
    PostMessage(Lumension,WM_KEYUP,0x20,0);
    Sleep(300);

    //SendMessage(Lumension,WM_LBUTTONDBLCLK,0, MAKELPARAM(mousePosX, mousePosY));

    return 0;
};

First get the handle to the window that has the button, then enumerate the child windows, something like this example. This code is clicking a button named "&Say Hello" on a VB.NET program whose window is named "Form1"

#include <Windows.h>


BOOL CALLBACK GetButtonHandle(HWND handle, LPARAM prm)
{

    char label[100];
    int size = GetWindowTextA(handle,label,sizeof(label));
    if(strcmp(label,"&Say Hello") == 0)
    {
        HWND *ButtonHandle = (HWND*)prm;
        *ButtonHandle = handle;
        return false;
    }
    return true;
}


int main()
{
    HWND wnd;
    HWND ButtonHandle = NULL;
    if( (wnd = FindWindow(0, "Form1")) )
    {   
        EnumChildWindows(wnd,GetButtonHandle,(LPARAM)&ButtonHandle);
        if( ButtonHandle != NULL)
        {
            PostMessage(ButtonHandle,BM_CLICK,0,0);
        }
    }
}

AD, having problems with that button. I see the typecast from ButtonHandle to an HWND*prm. I was curious about the breakdown of this callback function.
I tried running this code as a stand alone execution, and it didnt click the button. The button title in showed in spy++(WinID) displayed "&Next >".
Here's an odd thing though too. If I click my mouse on this installation window in the body of the window, and not on the button (set it as focus), and I hit spacebar on my keyboard it presses the next button, but when I SendMessage to all top level windows and send a space nothing happens. This one has me stumped. I think maybe I am using your code incorrectly. They have photobucket blocked here at work, or I would link a screen shot. I will try and do this later this evening to give yo ua visual of what I'm seeing.

#include <windows.h>

BOOL CALLBACK GetButtonHandle(HWND handle, LPARAM prm)
{

    char label[100];
    int size = GetWindowTextA(handle,label,sizeof(label));
    if(strcmp(label,"&Next >") == 0)
    {
        HWND *ButtonHandle = (HWND*)prm;
        *ButtonHandle = handle;
        return false;
    }
    return true;
}


int main()
{
    HWND wnd;
    HWND ButtonHandle = NULL;
    if( (wnd = FindWindow(0, "Lumension Endpoint Security Client")) )
    {
        EnumChildWindows(wnd,GetButtonHandle,(LPARAM)ButtonHandle);
        if( ButtonHandle != NULL)
        {
            PostMessage(ButtonHandle,BM_CLICK,0,0);
        }
        else
        {

            MessageBox(0,"ERROR","ERROR WITH HANDLE",MB_ICONINFORMATION);
        }
    }
}

Btw I still use this code you helped me with 2 years ago.
http://www.daniweb.com/software-development/cpp/threads/362240/wininet-and-internetopen-always-gives-compiler-error

To upload a picture to my personal host account for my website I tried downloading FileZilla, but our network here blocked it, and no good proxies to do this either. So I'll code my own ftp, upload the screen shot, and link you in just a little while if possible. First I must see if this Antivirus doesn't gripe at my code.

Ancient Dragon here's a screen shot. If you could help me make sense of what I am looking at here. The winID(spy++) is providing information about the button I am trying to send the spacebar command too. Once again human to human I value the time you spend to pass your knowedge and assistance in helping me. Time of life you will never get back, but can only be paid for with my appreciation and a "Thank You AD".

http://i463.photobucket.com/albums/qq354/codyoebel/lumension_zps28474f46.jpg

"&Next >"

The screenshot doesn't look like there's a space between 't' and '>'

I see the typecast from ButtonHandle to an HWND*prm. I was curious about the breakdown of this callback function.

LPARM one line 3 is the second parameter on line 24. Windows just passes it along to the callback function.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.