INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Jobs

Tips -N- Tricks

Having only one instance of App, bring window to top by danceman
Posted: 4 Jun 02

This will not only detect the window, but will bring it forward, making it the active window.  this way the user does not have to look at the task bar.

SET CLASSLIB TO "standards" ADDITIVE
objCheckRun = createobject("checkrun")
if type('objCheckRun') = 'O'
    objCheckRun.windowname = "your app window name"
    if objCheckRun.checkrun()
        release objCheckRun
        quit
    endif
endif
release classlib "standards"


this code is in a class method or it could be a procedure in main.
local WindowName
WindowName = this.windowname

#define GW_OWNER 4
#DEFINE GW_HWNDFIRST 0
#DEFINE GW_HWNDNEXT 2
declare integer SetForegroundWindow in win32api long lnhWnd
declare integer GetWindowText in win32api integer, string, integer
declare integer GetWindow in win32api integer,INTEGER
declare integer IsWindowVisible in win32api integer
declare integer GetActiveWindow in win32api
IsWindEx = .F.
if len(WindowName) < 1
    return IsWindEx
endif
foxhwnd = GetActiveWindow() && get the window handle of this window
hwndNext = GetWindow(foxhwnd,GW_HWNDFIRST) && get the handel of the first window

**** loop thru each window to search the title
DO WHILE hwndNext <> 0
    *** if window is not the foxpro handle and not a child window
    IF (hwndnext <> foxhwnd .AND. GetWindow(hwndnext,GW_OWNER) = 0)

        Stuffer = SPACE(64)
        x = GetWindowText(hwndnext,@Stuffer,64)  && get the window text
*** check to see if this is the specified window.
        IF WindowName $ Stuffer
            IsWindEx = .T.
            =SetForegroundWindow(hwndnext)  && BRING WINDOW TO FRONT
            EXIT
        ENDIF
    ENDIF
    hwndNext = GetWindow(hwndnext,GW_HWNDNEXT)
ENDDO
RETURN IsWindEx

Back to Microsoft: Visual FoxPro FAQ Index
Back to Microsoft: Visual FoxPro Forum

My Archive

Resources

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close