Results 1 to 2 of 2

Thread: Window focussing depending on a timer event

  1. #1

    Thread Starter
    New Member
    Join Date
    Nov 2001
    Location
    Cochin
    Posts
    3

    Angry Window focussing depending on a timer event

    Hello,

    Please help me on the following.


    I want to make a simple program which uses a timer control .
    It may bring to front the program when the timer event occurs on a specified time.


    ie when a particular time occurs if the user is working on a different program, above program will be focussed.


    please help

    [email protected]

  2. #2
    New Member
    Join Date
    Nov 2001
    Location
    South Africa
    Posts
    2

    Hope this helps

    'Add following to module:
    Public Declare Function GetForegroundWindow Lib "user32" () As Long
    Public Declare Function SetWindowPos Lib "user32" (ByVal hWnd As Long, ByVal hWndInsertAfter As Long, ByVal X As Long, ByVal Y As Long, ByVal cx As Long, ByVal cy As Long, ByVal wFlags As Long) As Long
    Public Const SWP_SHOWWINDOW = &H40
    Public Const HWND_TOPMOST = -1

    'Add to timer event:
    Dim lForgrnd as Long
    Dim lRet as Long
    Dim i As Integer
    dim bIsForgrnd as Boolean

    lForgrnd = GetForegroundWindow

    ' Loop through the loaded windows in you app to see if the foreground window is one of the loaded windows, if not then set the form you want in your app as the foreground window
    For i = Forms.Count - 1 To 0 Step -1
    if Forms(i).hWnd = lForgrnd then
    exit sub
    else
    bIsForgrnd = false
    end if
    Next i
    if bIsForgrnd = false then
    lRet = SetWindowPos('FormName' .hWnd, HWND_TOPMOST, X, Y, cx, cy, SWP_SHOWWINDOW)
    end if

    'FormName' = form you want to set as foreground window.
    ' X - Specifies the new position of the left side of the window. ie. 0 for the left most position.
    ' Y - Specifies the new position of the top of the window. ie. 0 for the top most position.
    ' cx - Specifies the new width of the window, in pixels. ie. Dim cx as long, cx = screen.width, for the form width to equal the screen width.
    ' cy - Specifies the new height of the window, in pixels. ie. Dim cy as long, cy = screen.width, for the form width to equal the screen width.

    Very very simple example, but should do the trick.

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