CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 5 of 5
  1. #1
    Join Date
    Oct 2006
    Posts
    21

    GetActiveWindow always fails

    Hi, I tried to read as most topics here as I could, but still haven't found the answer. I try to get handle of PowerPoint from my applivation. PowerPoint has different titles (depending on opened file), so I can't use FindWindow. I also tried EnumWindows, but didn't work (probably my mistake). I have console application and in my situation, it doesn't matter on time when I switch PowerPoint to be active. After PowerPoint is active, I start manualy sending WM_KEYDOWN messages over serial port. Most easy way for me can be something like this:

    HWND prog = GetActiveWindow();
    if (!prog) printf("next time...");

    I can't understand why, but "next time..." appears every time, doesn't matter on which window is active. Any ideas what I'm doing wrong?

  2. #2
    Join Date
    Aug 2005
    Posts
    478

    Re: GetActiveWindow always fails

    http://msdn.microsoft.com/library/de...tivewindow.asp

    GetActiveWindow Function

    The GetActiveWindow function retrieves the window handle to the active window attached to the calling thread's message queue.

    ...

    Remarks

    To get the handle to the foreground window, you can use GetForegroundWindow.
    So, the GetActiveWindow function will fail if it is a console, but it doesn't matter because that probably isn't the API you wanted in the first place.
    Windows XP, Visual Studio 2008, SVN

  3. #3
    Join Date
    Oct 2006
    Posts
    21

    Re: GetActiveWindow always fails

    Thank you... when I use GetForegroundWindow(), no error appears. After few hours of searching, I didn't see my fault. When I send message to my "help" programm, in which I defined WM_KEYDOWN and VK_DOWN, everything works exactly as I want. But when I send the same message and PowerPoint is active, nothing happens :-( (I need next slide)

    PostMessage(prog, WM_KEYDOWN, VK_DOWN, NULL);

  4. #4
    Join Date
    Aug 2005
    Posts
    478

    Re: GetActiveWindow always fails

    I would dok something more like, when you want to change a slide, getforegroundwindow (error check: if window class of foreground window == window class of power point), then use sendinput/keybd_event to synthesize a down keystroke (instead of wm_keydown).

    http://msdn.microsoft.com/library/de.../sendinput.asp
    http://msdn.microsoft.com/library/de...eybd_event.asp
    Windows XP, Visual Studio 2008, SVN

  5. #5

    Re: GetActiveWindow always fails

    I think using PowerPoint COM interface is the right way.
    Best Api Monitor tool.
    Trace the target program automatically and monitor the parameters of all API and COM interfaces.

    Auto Debug for Windows 4.0
    Auto Debug for .Net
    http://www.autodebug.com/

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured