Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
How to track the instance in process under task manager
Message
 
 
To
29/01/2004 19:05:08
General information
Forum:
Visual FoxPro
Category:
Other
Miscellaneous
Thread ID:
00872120
Message ID:
00872482
Views:
17
Hope the next code help you. Just drop the cursor and make it a function.

More info about window handling APIs http://msdn.microsoft.com/library/default.asp?url=/library/en-us/winui/winui/windowsuserinterface/windowing/windows.asp?frame=true
#Define GW_HWNDLAST  1
#Define GW_HWNDNEXT  2
#Define GW_CHILD     5
#Define WM_CLOSE   0x10
#Define WS_BORDER   0x800000
#Define WS_CAPTION   0xC00000
*   WS_BORDER Or WS_DLGFRAME
#Define WS_CHILD   0x40000000
#Define WS_CLIPCHILDREN   0x2000000
#Define WS_CLIPSIBLINGS   0x4000000
#Define WS_DISABLED   0x8000000
#Define WS_DLGFRAME   0x400000
#Define WS_EX_ACCEPTFILES   0x10
#Define WS_EX_DLGMODALFRAME   0x1
#Define WS_EX_NOPARENTNOTIFY   0x4
#Define WS_EX_TOPMOST   0x8
#Define WS_EX_TRANSPARENT   0x20
#Define WS_GROUP   0x20000
#Define WS_HSCROLL   0x100000
#Define WS_MAXIMIZE   0x1000000
#Define WS_MAXIMIZEBOX   0x10000
#Define WS_MINIMIZE   0x20000000
#Define WS_MINIMIZEBOX   0x20000
#Define WS_OVERLAPPED   0x0
#Define WS_POPUP   0x80000000
#Define WS_SYSMENU   0x80000
#Define WS_TABSTOP   0x10000
#Define WS_THICKFRAME   0x40000
#Define WS_VISIBLE   0x10000000
#Define WS_VSCROLL   0x200000
#Define GWL_EXSTYLE   (-20)
#Define GWL_HINSTANCE   (-6)
#Define GWL_HWNDPARENT   (-8)
#Define GWL_ID   (-12)
#Define GWL_STYLE   (-16)
#Define GWL_USERDATA   (-21)
#Define GWL_WNDPROC   (-4)

Declare Integer GetDesktopWindow In user32
Declare Integer GetWindow In user32 Integer HWnd, Integer wFlag
Declare Integer GetWindowRect In user32 Integer HWnd, String @lpRect
Declare Integer IsWindowVisible In user32 Integer HWnd
Declare Integer GetWindowText In user32;
  INTEGER HWnd, String @lpString, Integer cch
Declare Integer GetClassName In user32;
  INTEGER HWnd, String lpClassName, Integer nMaxCount
Declare Integer GetWindowLong In user32 Long HWnd, Long nIndex
Declare SHORT PostMessage In user32;
  INTEGER   HWnd,;
  INTEGER   Msg,;
  STRING  @ wParam,;
  INTEGER   Lparam

Create Cursor csResult (nnHWnd N(12), isvisible N(1),;
  leftpos I, toppos I, rightpos I, botpos I, HasMax I, HasMin I, HasTitle I, wincap C(64), classname C(64))

Local hDesktop, hFirstChild, hLastChild, cRect, cWinCap, cWinClass,;
  nVisible, nLeft, nTop, nRight, nBottom, nHasMax, nHasMin, nHasTitle

hDesktop = GetDesktopWindow()
hFirstChild = GetWindow(hDesktop, GW_CHILD)
hLastChild = GetWindow(hFirstChild, GW_HWNDLAST)

hCurrent = hFirstChild

Do While .T.
  cWinCap = GetWinText(hCurrent)
  cWinClass= GetClsName(hCurrent)
  nVisible = IsWindowVisible(hCurrent)
  nHasMax = HasMax(hCurrent)
  nHasMin = HasMin(hCurrent)
  nHasTitle = HasTitleBar(hCurrent)

  cRect = Repli(Chr(0),16)
  GetWindowRect(hCurrent, @cRect)
  nLeft = buf2dword(Substr(cRect, 1,4))
  nTop = buf2dword(Substr(cRect, 5,4))
  nRight = buf2dword(Substr(cRect, 9,4))
  nBottom = buf2dword(Substr(cRect, 13,4))

  Insert Into csResult Values (hCurrent, nVisible,;
    nLeft, nTop, nRight, nBottom, nHasMax, nHasMin, nHasTitle, cWinCap, cWinClass)

  * Example how to close a window
  * IF ALLTRIM(UPPER(cWinClass)) == "IEFRAME" AND ;
  *  ("Deal of the Day" $ cWinCap OR ;
  *  "Advanced Web search"  $ cWinCap)
  *  PostMessage(hCurrent, WM_CLOSE, 0, 0)
  * Endif
  * RAJ use above same principle to check if app is running

  If hCurrent = hLastChild
    Exit
  Endif
  hCurrent = GetWindow(hCurrent, GW_HWNDNEXT)
Enddo

Go Top
* BROWSE NORMAL FOR ALLTRIM(UPPER(classname)) == "IEFRAME" NOWAIT
Browse Normal Nowait

Clear Dlls ;
  GetDesktopWindow, ;
  GetWindow, ;
  GetWindowRect, ;
  IsWindowVisible, ;
  GetWindowText, ;
  GetClassName, ;
  GetWindowLong, ;
  PostMessage

* end of main

Function GetClsName(hWindow)
  Local nBufsize, cBuffer
  cBuffer = Repli(Chr(0), 250)
  nBufsize = GetClassName(hWindow, @cBuffer, Len(cBuffer))
  Return Substr(cBuffer, 1, nBufsize)

Function GetWinText(hWindow)
  * returns window title bar text -- Win9*/Me/XP/2000
  Local cBuffer, nResult
  cBuffer = Space(250)
  nResult = GetWindowText(hWindow, @cBuffer, Len(cBuffer))
  Return Substr(cBuffer, 1, nResult)

Function buf2dword(lcBuffer)
  Return Asc(Substr(lcBuffer, 1,1)) + ;
    BitLShift(Asc(Substr(lcBuffer, 2,1)),  8) +;
    BitLShift(Asc(Substr(lcBuffer, 3,1)), 16) +;
    BitLShift(Asc(Substr(lcBuffer, 4,1)), 24)

Function HasMax(nhwnd)
  Local ;
    nStyle, ;
    lHasMax

  nStyle = GetWindowLong(nhwnd, GWL_STYLE)
  If (Bitand(nStyle,WS_MAXIMIZEBOX) = WS_MAXIMIZEBOX)
    lHasMax = .T.
  Else
    lHasMax = .F.
  Endif
  Return Iif(lHasMax,1,0)

Function HasMin(nhwnd)
  Local ;
    nStyle, ;
    lHasMin

  nStyle = GetWindowLong(nhwnd, GWL_STYLE)
  If (Bitand(nStyle,WS_MINIMIZEBOX) = WS_MINIMIZEBOX)
    lHasMin = .T.
  Else
    lHasMin = .F.
  Endif
  Return Iif(lHasMin,1,0)

Function HasTitleBar(nhwnd)
  Local ;
    nStyle, ;
    lHasTitleBar

  nStyle = GetWindowLong(nhwnd, GWL_STYLE)
  If (Bitand(nStyle,WS_DLGFRAME) = WS_DLGFRAME)
    lHasTitleBar = .T.
  Else
    lHasTitleBar = .F.
  Endif
  Return Iif(lHasTitleBar,1,0)
To test above code just cut and paste it to PRG and run it.

AT
Previous
Reply
Map
View

Click here to load this message in the networking platform