Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

User32: CloseWindow stopped working in XP

Status
Not open for further replies.

pullingteeth

Programmer
Sep 26, 2003
128
US
Hello, I had a vba script which switched windows between two applications. The code below used to work in Windows 95, but doesn't in Windows XP. I determined using the debugger that it is the closewindow statement which doesn't work. Any idea what's going on here? Thanks

Code:
dim ntsid as long
dim winid as long
dim y as long

' get the NTS id
ntsid = GetForegroundWindow
y = CloseWindow(ntsid)

OpenDatabase:dim ntsid as long
dim winid as long
dim y as long

' get the NTS id
ntsid = GetForegroundWindow
y = CloseWindow(ntsid)

' find the tracking window
y = FindWindow("", "Tracking")   

' minimize all windows until we find the tracking window
winid = getForegroundWindow
if x = 0 then ' this means that the tracking database is not present
    msgbox " WAIT!!  Please verify the Concord Database is open and that you've signed on. Rerun the macro."
    goto EndAndLetThemFigureItOut
else
    y = ShowWindow(x, 3)
    y = ShowWindow(x, 5)
    while (not (winid = x))
        y = CloseWindow(winid)
        winid = getForegroundWindow                      
    wend 
end if
' find the tracking window
y = FindWindow("", "Tracking")   

' minimize all windows until we find the tracking window
winid = getForegroundWindow
if x = 0 then ' this means that the tracking window is not present
    msgbox " (error)"
    goto EndAndLetThemFigureItOut
else
    y = ShowWindow(x, 3)
    y = ShowWindow(x, 5)
    while (not (winid = x))
        y = CloseWindow(winid)
        winid = getForegroundWindow                      
    wend 
end if
 
OK, got it to the stage where the window switching is working. The above code was missing a call to UpdateWindow. My new code is below. However, the window I'm switching too for some reason isn't taking keyboard input (the F5), although if I press F5 myself it works fine. Any idea what's happening now? Thanks

Code:
    dim ntsid as long
    dim y as long, tdbid as long

    ' get the NTS id
    ntsid = GetForegroundWindow
    y = CloseWindow(ntsid)        

    ' get the tracking db window
    tdbid = FindWindow("", "Tracking")   
    ' Maximize the tracking db window
    y = ShowWindow(tdbid, 1)
    ' Bring it to the foreground so it can accept input
    y = SetForegroundWindow(tdbid)
    ' Update it, so it displays itself at the front
    y = UpdateWindow(tdbid)

    ' Pause for one second , so the users can see a message of the day if 
    ' there is one, etc
    pause 1
    sendkeys "{f5}"
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top