Results 1 to 6 of 6

Thread: show form on top of other prog

  1. #1

    Thread Starter
    Junior Member
    Join Date
    Mar 2005
    Posts
    23

    show form on top of other prog

    Hello Everyone
    I have a VB6 program that accepts rtc calls from other PC. I minimize that form in system tray and wheneve a call comes in that form pops us from system tray and shows on the destop. The problem with this is that if I have any window open like for example windows explorer my forms comes behind it. I want to have this form on the top so that user can easily answer incomming call.
    Can some pls help me with this.
    The followin is the code I use to maximize and minimize form:
    Private Sub Minimize_Click()
    'Add an icon. This procedure uses the icon specified in
    'the Icon property of frmmain. This can be modified as desired.

    Dim i As Integer
    Dim s As String
    Dim nid As NOTIFYICONDATA

    s = "RIVA Answer Station"
    nid = setNOTIFYICONDATA(frmMain.hwnd, vbNull, NIF_MESSAGE Or NIF_ICON Or NIF_TIP, WM_MOUSEMOVE, frmMain.Icon, s)
    i = Shell_NotifyIconA(NIM_ADD, nid)

    WindowState = vbMinimized
    Visible = False

    End Sub
    Private Function setNOTIFYICONDATA(hwnd As Long, ID As Long, Flags As Long, CallbackMessage As Long, Icon As Long, Tip As String) As NOTIFYICONDATA
    Dim nidTemp As NOTIFYICONDATA

    nidTemp.cbSize = Len(nidTemp)
    nidTemp.hwnd = hwnd
    nidTemp.uID = ID
    nidTemp.uFlags = Flags
    nidTemp.uCallbackMessage = CallbackMessage
    nidTemp.hIcon = Icon
    nidTemp.szTip = Tip & Chr$(0)

    setNOTIFYICONDATA = nidTemp
    End Function

    Private Sub maximize()

    WindowState = vbNormal
    Visible = True
    Dim hProcess As Long
    GetWindowThreadProcessId hwnd, hProcess
    AppActivate hProcess


    End Sub

    Declarations
    ' To Minimize app in system tray
    Private Type NOTIFYICONDATA
    cbSize As Long
    hwnd As Long
    uID As Long
    uFlags As Long
    uCallbackMessage As Long
    hIcon As Long
    szTip As String * 64
    End Type

    Const NIM_ADD = 0
    Const NIM_MODIFY = 1
    Const NIM_DELETE = 2
    Const NIF_MESSAGE = 1
    Const NIF_ICON = 2
    Const NIF_TIP = 4

    Const WM_MOUSEMOVE = &H200
    Const WM_LBUTTONDOWN = &H201
    Const WM_LBUTTONUP = &H202
    Const WM_LBUTTONDBLCLK = &H203
    Const WM_RBUTTONDOWN = &H204
    Const WM_RBUTTONUP = &H205
    Const WM_RBUTTONDBLCLK = &H206
    Const WM_MBUTTONDOWN = &H207
    Const WM_MBUTTONUP = &H208
    Const WM_MBUTTONDBLCLK = &H209

    Private Declare Function GetWindowThreadProcessId Lib "user32" (ByVal hwnd As Long, lpdwProcessId As Long) As Long
    Private Declare Function Shell_NotifyIconA Lib "SHELL32" (ByVal dwMessage As Long, lpData As NOTIFYICONDATA) As Integer
    ' minimize system tray ends here

  2. #2
    Oi, fat-rag! bushmobile's Avatar
    Join Date
    Mar 2004
    Location
    on the poop deck
    Posts
    5,592

    Re: show form on top of other prog

    Use the SetForegroundWindow API:
    VB Code:
    1. Declare Function SetForegroundWindow Lib "user32" Alias "SetForegroundWindow" (ByVal hwnd As Long) As Long
    call it:
    VB Code:
    1. SetForegroundWindow Me.hWnd

  3. #3

    Thread Starter
    Junior Member
    Join Date
    Mar 2005
    Posts
    23

    Re: show form on top of other prog

    Thanks for the reply. I tried pasting SetForeground declaration and it doesnt take the alias value. I am able to run the code but when I place a windows explorer on top of it the form runs in background.
    Am I doing something wrong?

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

    Re: show form on top of other prog

    Quote Originally Posted by shoazib
    I tried pasting SetForeground declaration and it doesnt take the alias value.
    Doesn't take the alias?

    You could alias a API declare as BananaSplit if you wanted to, and it should still work. What error message are you getting?

  5. #5
    Oi, fat-rag! bushmobile's Avatar
    Join Date
    Mar 2004
    Location
    on the poop deck
    Posts
    5,592

    Re: show form on top of other prog

    the alias will dissappear if the function name is an exact match.

    where are you calling SetForegroundWindow?

  6. #6

    Thread Starter
    Junior Member
    Join Date
    Mar 2005
    Posts
    23

    Re: show form on top of other prog

    I am calling the function here:
    Private Sub maximize()

    WindowState = vbNormal
    Visible = True
    Dim hProcess As Long
    GetWindowThreadProcessId hWnd, hProcess
    AppActivate hProcess
    SetForegroundWindow Me.hWnd


    End Sub

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