Results 1 to 10 of 10

Thread: SetForegroundWindow API not working

Hybrid View

  1. #1

    Thread Starter
    Member
    Join Date
    Jun 2005
    Location
    Portland, OR
    Posts
    47

    SetForegroundWindow API not working

    Hey, i know there have been a lot of posts on this topic but i can't seem to find the answer to this question. I have an excel spreadsheet with cells full of visio shapes. When a double click is made on a cell, the shape is found and set to blink in visio. However, i am having trouble getting the visio window to pop up infront of the excel window

    I am using SetForegroundWindow API by calling this:
    VB Code:
    1. 'g_ovAppVisio is the Visio Application object
    2. SetForegroundWindow g_ovAppVisio.WindowHandle32

    this however, only causes the visio window to flash 3 times in the task bar, and not pop up. What else do I need to do to make it pop up in front of the excel window? Thanks!

  2. #2
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333

    Re: SetForegroundWindow API not working

    Is this VB6 or VB.NET?

  3. #3

    Thread Starter
    Member
    Join Date
    Jun 2005
    Location
    Portland, OR
    Posts
    47

    Re: SetForegroundWindow API not working

    I'm developing in VB6

  4. #4
    Super Moderator manavo11's Avatar
    Join Date
    Nov 2002
    Location
    Around the corner from si_the_geek
    Posts
    7,171

    Re: SetForegroundWindow API not working

    Find the handle yourself with the FindWindow API? Just a thought...


    Has someone helped you? Then you can Rate their helpful post.

  5. #5

    Thread Starter
    Member
    Join Date
    Jun 2005
    Location
    Portland, OR
    Posts
    47

    Re: SetForegroundWindow API not working

    It's the right handle, the window reacts, it just doesn't pop up. I think i need to use SetWindowPos but i'm not sure how to set the flags, or if there is a better procedure for doing that.

  6. #6
    Frenzied Member mar_zim's Avatar
    Join Date
    Feb 2004
    Location
    Toledo Cebu City.
    Posts
    1,416

    Re: SetForegroundWindow API not working

    Quote Originally Posted by Vhati
    It's the right handle, the window reacts, it just doesn't pop up. I think i need to use SetWindowPos but i'm not sure how to set the flags, or if there is a better procedure for doing that.
    same case as mine. What I did is use the IsIconic function,setforeground and showwindow.

    IsIconic use to check if the window is minimize or not if it's not minimize then use the setforeground then if it's minimize then use the showwindow.

  7. #7
    Super Moderator manavo11's Avatar
    Join Date
    Nov 2002
    Location
    Around the corner from si_the_geek
    Posts
    7,171

    Re: SetForegroundWindow API not working

    Is it maybe minimized?


    Has someone helped you? Then you can Rate their helpful post.

  8. #8
    Super Moderator manavo11's Avatar
    Join Date
    Nov 2002
    Location
    Around the corner from si_the_geek
    Posts
    7,171

    Re: SetForegroundWindow API not working



    Has someone helped you? Then you can Rate their helpful post.

  9. #9
    Addicted Member
    Join Date
    May 2004
    Location
    Nagpur, India
    Posts
    228

    Re: SetForegroundWindow API not working

    Windows 98/Me, Windows 2000/XP: The system restricts which processes can set the foreground window. A process can set the foreground window only if one of the following conditions is true:

    The process is the foreground process.
    The process was started by the foreground process.
    The process received the last input event.
    There is no foreground process.
    The foreground process is being debugged.
    The foreground is not locked (see LockSetForegroundWindow).
    The foreground lock time-out has expired (see SPI_GETFOREGROUNDLOCKTIMEOUT in SystemParametersInfo).
    Windows 2000/XP: No menus are active.

    Check MSDN for more

  10. #10
    Registered User
    Join Date
    Dec 2016
    Location
    Australia
    Posts
    56

    Re: SetForegroundWindow API not working

    Quote Originally Posted by mayurvb View Post
    Windows 98/Me, Windows 2000/XP: The system restricts which processes can set the foreground window. A process can set the foreground window only if one of the following conditions is true:

    The process is the foreground process.
    The process was started by the foreground process.
    The process received the last input event.
    There is no foreground process.
    The foreground process is being debugged.
    The foreground is not locked (see LockSetForegroundWindow).
    The foreground lock time-out has expired (see SPI_GETFOREGROUNDLOCKTIMEOUT in SystemParametersInfo).
    Windows 2000/XP: No menus are active.

    Check MSDN for more
    In 2019, the main difference in MSDN to above is:
    The foreground process is not a Modern Application or the Start Screen.
    Makes sense. Necro reason being that given A is the start up form and unloaded, C is then number crunching_ hourglass_busy modally over another form B with a title bar. In multiple tests of the same operation, when borderless C (no ControlBox) is no longer busy, B sometimes pops up in front of C.
    This behaviour has come about in Windows 10, and is possibly attributed to the OS handling of HUNGAPPTIMEOUT or WAITTOKILLTIMEOUT in our Modern Application.
    Last edited by lmstearn; Feb 21st, 2019 at 07:13 AM.

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