Need help getting form window to top and active-VBForums
Results 1 to 20 of 20

Thread: Need help getting form window to top and active

  1. #1

    Thread Starter
    Member
    Join Date
    Dec 2010
    Posts
    37

    Need help getting form window to top and active

    I'm self-taught in VB macros in Word and Excel, and I dabble a bit in VB6 (Classic, not NET). I'm not at all up on APIs, relying on slurping from the internet.

    I have a one-form program that works fine. I use it at church to pull up songs. I can type in the name or the first line of a song, and it searches a folder and pulls up the song as Word doc. At that point, the form is resized to about height of a Title bar and about 2" wide.

    After opening the Word doc, I can use Me.SetFocus and Me.Text1.SetFocus to bring the form back on top and deactivate the Word window. This does two things: it allows me to close the Word doc by simply typing a 0, and it keeps me from accidentally typing in the doc.

    But if the mouse gets clicked and the Word doc gets the focus, I'm kinda dead! I can get the form window on top of the Word window, but I can't make the form or VB the active application. I've got a timer in the form that keeps checking to see if there's an active Word doc object (just in case the doc gets accidentally closed); if not, it restores the form to full size. I'm trying to get it so if there is a doc object, then ensure VB and the form are on top and active.

    Any help with this?
    Ed

  2. #2
    PowerPoster
    Join Date
    Feb 2012
    Location
    West Virginia
    Posts
    6,995

    Re: Need help getting form window to top and active

    Here is some old code I used to use back in VB5 should do the trick

    You will need to add this code to a module in your project or create a new module for it.
    Code:
    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 HWND_TOP = 0
    Public Const HWND_TOPMOST = -1
    Public Const HWND_NOTOPMOST = -2
    Public Const SWP_NOMOVE = &H2
    Public Const SWP_NOSIZE = &H1
    Public Const FLAGS = SWP_NOMOVE Or SWP_NOSIZE
    
    Public Sub StayOnTop(the As Form)
    Dim setwinontop
    setwinontop = SetWindowPos(the.hwnd, HWND_TOPMOST, 0, 0, 0, 0, FLAGS)
    
    
    End Sub
    The in your form code you will need something like
    Code:
    StayOnTop(Me)

  3. #3
    VBaholic & Loving It LaVolpe's Avatar
    Join Date
    Oct 2007
    Location
    GetWindowRect()
    Posts
    11,938

    Re: Need help getting form window to top and active

    You may want to add a check box or menu item to toggle the functionality. Here is a simple example, just copy the API declarations to the top of your form, then copy the subroutine towards bottom of your form. No Timers needed
    Code:
     ' API declaration
    Private Declare Function SetWindowPos Lib "user32.dll" (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
    
    ' the subroutine
    Private Sub MakeTopMost(bSet As Boolean)
    
        Const SWP_NOSIZE As Long = &H1
        Const SWP_NOMOVE As Long = &H2
        Const HWND_TOPMOST As Long = -1
        Const HWND_NOTOPMOST As Long = -2
        If bSet Then
            SetWindowPos Me.hWnd, HWND_TOPMOST, 0, 0, 0, 0, SWP_NOMOVE Or SWP_NOSIZE
        Else
            SetWindowPos Me.hWnd, HWND_NOTOPMOST, 0, 0, 0, 0, SWP_NOMOVE Or SWP_NOSIZE
        End If
    
    End Sub
    In your form_load, simply call MakeTopMost True

    Edited: Beat to the punch I see
    Insomnia is just a byproduct of, "It can't be done"

    Newbie? Novice? Bored? Spend a few minutes browsing the FAQ section of the forum. Read the HitchHiker's Guide to Getting Help on the Forums.
    Here is the list of TAGs you can use to format your posts


    {Alpha Image Control} {Memory Leak FAQ} {GDI+ Classes/Samples} {Unicode Open/Save Dialog} {Icon Organizer/Extractor}
    {VBA Control Arrays} {XP/Vista Manifest Creator} {UserControl Button Template} {stdPicture Render Usage}

  4. #4

    Thread Starter
    Member
    Join Date
    Dec 2010
    Posts
    37

    Re: Need help getting form window to top and active

    Thanks for the replies. But I've done this. And a bunch more - ActiveWindow, SetFocus etc. (Sorry - I'm on another computer right now and I don't have the code with me. Actually, though, I've deleted all the codes that didn't work.)

    I can get the VB form window to be on top, but I can't get it to be the active application with Word in the background. I thought I saw an AppActivate in my searching, but it wouldn't compile in my form module, Maybe that's dot-net??

    But anything I do from within the form module when Word is the active app just makes the form's notifier on the bottom flash until I click on it, and Word stays as the active application, although it's stacked behind the form.

    Ed

  5. #5
    PowerPoster
    Join Date
    Feb 2012
    Location
    West Virginia
    Posts
    6,995

    Re: Need help getting form window to top and active

    Have you tried simply adding a
    Code:
    Me.SetFocus
    in a timer? Or
    Code:
    AppActivate (Me.Caption)
    Either should pull your app to the front and give it focus at any time.

  6. #6
    VBaholic & Loving It LaVolpe's Avatar
    Join Date
    Oct 2007
    Location
    GetWindowRect()
    Posts
    11,938

    Re: Need help getting form window to top and active

    You'll probably need to show us some code
    Insomnia is just a byproduct of, "It can't be done"

    Newbie? Novice? Bored? Spend a few minutes browsing the FAQ section of the forum. Read the HitchHiker's Guide to Getting Help on the Forums.
    Here is the list of TAGs you can use to format your posts


    {Alpha Image Control} {Memory Leak FAQ} {GDI+ Classes/Samples} {Unicode Open/Save Dialog} {Icon Organizer/Extractor}
    {VBA Control Arrays} {XP/Vista Manifest Creator} {UserControl Button Template} {stdPicture Render Usage}

  7. #7

    Thread Starter
    Member
    Join Date
    Dec 2010
    Posts
    37

    Re: Need help getting form window to top and active

    Quote Originally Posted by DataMiser View Post
    Have you tried simply adding a
    Code:
    Me.SetFocus
    in a timer? Or
    Code:
    AppActivate (Me.Caption)
    Either should pull your app to the front and give it focus at any time.
    Yah, I tried both. The SetFocus just makes the app notification on bottom flash. The AppActivate wouldn't compile.

    I'll get the code later when I get back to the other computer and I'll post what I have. Like I said, I've deleted a lot of stuff that just didn't work.

    Oh - this is with Word 2000 and XPSP3.

    Ed

  8. #8
    PowerPoster
    Join Date
    Feb 2012
    Location
    West Virginia
    Posts
    6,995

    Re: Need help getting form window to top and active

    I tried both methods here and both methods worked just fine in XPSP3. No matter what application I had running in fact I had to stop the program before I could type this message because it would grab focus away every second.

  9. #9
    PowerPoster Spoo's Avatar
    Join Date
    Nov 2008
    Location
    Right Coast
    Posts
    2,656

    Re: Need help getting form window to top and active

    Ed

    A shot in the dark here (as an alternative in the
    event the other suggestions don't pan out) ..

    .. is there some way to bring the Word doc "into"
    your VB6 app .. ie, place it in some sort of control?

    I'm thinking out loud here ..
    • maybe in a RichTextbox control?
    • something else?

    My thinking is that if it is all "contained" on your Form,
    your "inadvertant" issues would evaporate.

    Unfortunately, I just don't know enough about Word docs
    and VB6 forms to be of any real help. Hopefully, others
    will have more ideas.

    Spoo

  10. #10
    PowerPoster
    Join Date
    Feb 2012
    Location
    West Virginia
    Posts
    6,995

    Re: Need help getting form window to top and active

    Quote Originally Posted by Ed_from_AZ View Post
    Yah, I tried both. The SetFocus just makes the app notification on bottom flash. The AppActivate wouldn't compile.

    I'll get the code later when I get back to the other computer and I'll post what I have. Like I said, I've deleted a lot of stuff that just didn't work.

    Oh - this is with Word 2000 and XPSP3.

    Ed
    I am confused. Where did you put this code? In a word doc or in a VB app?

  11. #11

    Thread Starter
    Member
    Join Date
    Dec 2010
    Posts
    37

    Re: Need help getting form window to top and active

    Spoo: I didn't mess with a Rich Text box because I didn't want to import the doc or cause any changes to the formatting, etc; I just wanted to open the doc. (It was all fine as long as it was just me using this and I could work around all my bad code! But now I gotta share and the other person isn't as into it all as I am.)

    DataMiser: All code is in a VB form; nothing is in a Word doc. I just mentioned my Word and Windows versions in case something there made a difference in what was happening.

    Ed

  12. #12
    PowerPoster Spoo's Avatar
    Join Date
    Nov 2008
    Location
    Right Coast
    Posts
    2,656

    Re: Need help getting form window to top and active

    Ed

    Fair enough.

    It belatedly occurred to me that the "something" else
    might be a WebBrowser control.

    Maybe something like this will suffice ...

    Code:
    Dim myFile As String
    myFile = "c:\myWord.doc"
    With WebBrowser1
        .Top = 100
        .Left = 100
        .Height = 5000
        .Width = 12000
        .Visible = True
        .Navigate2 myFile
    End With
    I just tried it and it works, except for the File Download
    dialogue box that comes up.

    I clicked Open and it seems fine. But, I don't work enough
    with the WebBrowser control to know how to prevent this
    message or how to automatically deal with it.

    Maybe someone else does.

    Anyway.. perhaps this is a usable alternative.

    EDIT

    I should also add that it "doesn't work" if the file is already
    open.

    You get the same dialogue box, but after clicking Open,
    "nothing" seems to happen... ie, the WebBrowser control
    does not get populated.

    So, some additional code will be needed to see if the file
    is open somewhere else on the desktop.

    Spoo
    Last edited by Spoo; Feb 21st, 2012 at 09:40 PM.

  13. #13

    Thread Starter
    Member
    Join Date
    Dec 2010
    Posts
    37

    Re: Need help getting form window to top and active

    Okay - finally, here's some chunks of my code. (I tried posting this last night, but my phone wouldn't cooperate!) The whole purpose of this app is to let me type in a word or phrase from a song and open the Word doc for that song. All the song docs are in one folder. Because they are songs, they have certain font and style settings that I didn't want to risk affecting by opening them in anything other than Word. There should never be more than one doc open at a time, and there are no other apps running other than VB and Word. Also, I only have the learning edition, so this is not a compiled exe - but it still works, except for my one problem.

    On Load, the form reads through a doc and populates drop-down boxes. There's also a test field that lets me type in words and phrases. Using these, I'm able to specify a certain Word doc I want opened. I can then key in a number from 1 to 8 or Shift+1 to 8 and open that doc; when the doc opens, the form shrinks and moves to the upper left. If I type a zero, the doc closes and the form resets.

    That's why I'm trying so hard to keep the VB form and app on top and active. If the mouse gets clicked and the Word doc becomes the active app (even if the VB form is the top-most window), if I type the 0 the doc doesn't close. A CTRL+W to close then brings up the dialog about "Do you want to save changes?", and it's just something I don't need.

    I've included the declarations, the Text1_KeyPress sub that opens a doc, and the timer routine where I'm trying to stick the code to put the VB app on top and active. But anything I try just makes the VB taskbar button flash until I click it.

    vb Code:
    1. Private m_clsCombo1 As clsControlCombo
    2. Private m_clsCombo2 As clsControlCombo
    3. Private m_clsCombo3 As clsControlCombo
    4. Private m_clsCombo4 As clsControlCombo
    5. Private m_clsCombo5 As clsControlCombo
    6. Private m_clsCombo6 As clsControlCombo
    7.  
    8. Private Declare Function GetActiveWindow Lib _
    9.   "user32" () As Integer
    10.  
    11. Private Declare Function SetActiveWindow Lib _
    12.   "user32" (ByVal HWnd As Long) As Integer
    13.  
    14. Private Declare Function GetForegroundWindow Lib _
    15.   "user32" () As Long
    16.  
    17. Private Declare Function SetForegroundWindow Lib _
    18.   "user32" (ByVal HWnd As Long) As Integer
    19.  
    20. Private Declare Function SetWindowPos Lib _
    21.   "user32" (ByVal HWnd As Long, _
    22.   ByVal hWndInsertAfter As Long, _
    23.   ByVal x As Long, ByVal y As Long, _
    24.   ByVal cx As Long, ByVal cy As Long, _
    25.   ByVal wFlags As Long) As Long
    26.  
    27. Private Declare Function FindWindow Lib _
    28.   "user32" Alias "FindWindowA" _
    29.   (ByVal lpClassName As String, _
    30.   ByVal lpWindowName As String) As Long
    31.  
    32. Private Declare Function GetClassName Lib _
    33.   "user32" Alias "GetClassNameA" _
    34.   (ByVal HWnd As Long, _
    35.   ByVal lpClassName As String, _
    36.   ByVal nMaxCount As Long) As Long
    37.  
    38. Const HWND_TOPMOST = -1
    39. Const HWND_NOTOPMOST = -2
    40. Const SWP_NOMOVE = &H2
    41. Const SWP_NOSIZE = &H1
    42.  
    43. Dim appWd As Word.Application
    44. Dim doc As Word.Document
    45. Dim rng As Word.Range
    46. Dim aryTlb() As String
    47. Dim cntTlb As Integer
    48.  
    49. Dim aryFT() As String
    50. Dim aryFL() As String
    51. Dim aryFC() As String
    52. Dim aryST() As String
    53. Dim arySL() As String
    54. Dim arySC() As String
    55.  
    56. Dim arySongs(100) As String
    57. Dim cntSongs As Integer
    58. Dim x As Integer
    59. Dim bolChgMe As Boolean
    60. Dim bolNoSong As Boolean
    61. Dim bolTwoMon As Boolean
    62. Dim bolSongCls As Boolean
    63. Dim bolFirstLet As Boolean
    64.  
    65. Dim XX
    66.  
    67. Dim frmTop As Long
    68. Dim frmLeft As Long
    69.  
    70. Dim ScreenArea 'As RECT
    71. Dim MyHwnd
    72. ''
    73. Private m_clsCombo1 As clsControlCombo
    74. Private m_clsCombo2 As clsControlCombo
    75. Private m_clsCombo3 As clsControlCombo
    76. Private m_clsCombo4 As clsControlCombo
    77. Private m_clsCombo5 As clsControlCombo
    78. Private m_clsCombo6 As clsControlCombo
    79.  
    80. Private Declare Function GetActiveWindow Lib _
    81.   "user32" () As Integer
    82.  
    83. Private Declare Function SetActiveWindow Lib _
    84.   "user32" (ByVal HWnd As Long) As Integer
    85.  
    86. Private Declare Function GetForegroundWindow Lib _
    87.   "user32" () As Long
    88.  
    89. Private Declare Function SetForegroundWindow Lib _
    90.   "user32" (ByVal HWnd As Long) As Integer
    91.  
    92. Private Declare Function SetWindowPos Lib _
    93.   "user32" (ByVal HWnd As Long, _
    94.   ByVal hWndInsertAfter As Long, _
    95.   ByVal x As Long, ByVal y As Long, _
    96.   ByVal cx As Long, ByVal cy As Long, _
    97.   ByVal wFlags As Long) As Long
    98.  
    99. Private Declare Function FindWindow Lib _
    100.   "user32" Alias "FindWindowA" _
    101.   (ByVal lpClassName As String, _
    102.   ByVal lpWindowName As String) As Long
    103.  
    104. Private Declare Function GetClassName Lib _
    105.   "user32" Alias "GetClassNameA" _
    106.   (ByVal HWnd As Long, _
    107.   ByVal lpClassName As String, _
    108.   ByVal nMaxCount As Long) As Long
    109.  
    110. Const HWND_TOPMOST = -1
    111. Const HWND_NOTOPMOST = -2
    112. Const SWP_NOMOVE = &H2
    113. Const SWP_NOSIZE = &H1
    114.  
    115. Dim appWd As Word.Application
    116. Dim doc As Word.Document
    117. Dim rng As Word.Range
    118. Dim aryTlb() As String
    119. Dim cntTlb As Integer
    120.  
    121. Dim aryFT() As String
    122. Dim aryFL() As String
    123. Dim aryFC() As String
    124. Dim aryST() As String
    125. Dim arySL() As String
    126. Dim arySC() As String
    127.  
    128. Dim arySongs(100) As String
    129. Dim cntSongs As Integer
    130. Dim x As Integer
    131. Dim bolChgMe As Boolean
    132. Dim bolNoSong As Boolean
    133. Dim bolTwoMon As Boolean
    134. Dim bolSongCls As Boolean
    135. Dim bolFirstLet As Boolean
    136.  
    137. Dim XX
    138.  
    139. Dim frmTop As Long
    140. Dim frmLeft As Long
    141.  
    142. Dim ScreenArea 'As RECT
    143. Dim MyHwnd
    144. '
    145. '************
    146. '
    147. Private Sub Text1_KeyPress(KeyAscii As Integer)
    148.    
    149.   XX = KeyAscii
    150.   Dim idx
    151.   Dim strList As String
    152.   Dim strFile As String
    153.  
    154.   If KeyAscii = 48 Then  ' Typed zero, close top Word doc
    155.     'Stop
    156.     If appWd.Documents.Count > 0 Then
    157.         appWd.Documents(1).Close
    158.         bolSongCls = True
    159.         GoTo SongClosed
    160.     End If
    161.   End If
    162.    
    163.   If KeyAscii < 33 Then Exit Sub
    164.   If KeyAscii > 95 Then Exit Sub
    165.   If KeyAscii > 64 And KeyAscii < 91 Then Exit Sub
    166.  
    167.   If Me.Text1.Text = "" Then bolNoSong = True
    168.   If InStr(1, Me.Text1.Text, "=") > 0 Then bolNoSong = True
    169.  
    170.   Select Case XX
    171.     Case 33 'SHIFT+1 = Fast Title
    172.       If bolNoSong = True Then GoTo NoSong
    173.       idx = Me.Label7.Tag
    174.       strFile = aryFT(idx + 1, 2)
    175.     Case 64 'SHIFT+2 = Fast Line
    176.       If bolNoSong = True Then GoTo NoSong
    177.       idx = Me.Label9.Tag
    178.       strFile = aryFL(idx + 1, 2)
    179.     Case 35 'SHIFT+3 = Fast Chorus
    180.       If bolNoSong = True Then GoTo NoSong
    181.       idx = Me.Label8.Tag
    182.       strFile = aryFC(idx + 1, 2)
    183.     Case 36 'SHIFT+4 = Slow Title
    184.       If bolNoSong = True Then GoTo NoSong
    185.       idx = Me.Label10.Tag
    186.       strFile = aryST(idx + 1, 2)
    187.     Case 37 'SHIFT+5 = Slow Line
    188.       If bolNoSong = True Then GoTo NoSong
    189.       idx = Me.Label12.Tag
    190.       strFile = arySL(idx + 1, 2)
    191.     Case 94 'SHIFT+6 = Slow Chorus
    192.       If bolNoSong = True Then GoTo NoSong
    193.       idx = Me.Label11.Tag
    194.       strFile = arySC(idx + 1, 2)
    195.     Case 49 '1  = Fast List #1
    196.       strFile = aryFT(Me.Combo7.ListIndex + 1, 2)
    197.     Case 50 '2 = Fast List #2
    198.       strFile = aryFT(Me.Combo8.ListIndex + 1, 2)
    199.     Case 51 '3 = Fast List #3
    200.       strFile = aryFT(Me.Combo9.ListIndex + 1, 2)
    201.     Case 52 '4 = Offering
    202.       strFile = aryFT(Me.Combo10.ListIndex + 1, 2)
    203.     Case 53 '5 = Slow List #1
    204.       strFile = aryST(Me.Combo11.ListIndex + 1, 2)
    205.     Case 54 '6 = Slow List #2
    206.       strFile = aryST(Me.Combo12.ListIndex + 1, 2)
    207.     Case 55 '7 = Slow List #3
    208.       strFile = aryST(Me.Combo13.ListIndex + 1, 2)
    209.     Case 56 '8 = Slow List #4
    210.       strFile = aryST(Me.Combo14.ListIndex + 1, 2)
    211.   End Select
    212.  
    213. SongClosed:
    214.   KeyAscii = 0
    215.   Me.Text1.Text = ""
    216.  
    217. 'Stop
    218.  
    219. 'If Word app is gone, reset app object
    220. Err.Clear
    221. On Error Resume Next
    222.   Dim tstAppName As String
    223.   tstAppName = appWd.Name
    224. On Error GoTo 0
    225.  
    226. If tstAppName = "" Then
    227.   Set appWd = New Word.Application
    228. End If
    229.  
    230. tstAppName = ""
    231.  
    232. If bolSongCls = True Then
    233.   bolSongCls = False
    234.  
    235.   If bolTwoMon = True Then
    236.     SearchMe.SetFocus
    237.     SearchMe.Text1.SetFocus
    238.   End If
    239.  
    240.   GoTo NoSong
    241. End If
    242. 'Stop
    243. If strFile <> "" Then
    244.   cntSongs = cntSongs + 1
    245.   arySongs(cntSongs) = strFile
    246.  
    247.   strFile = Chr(34) & strFile & Chr(34)
    248.   Set doc = appWd.Documents.Open(FileName:=strFile, Visible:=True)
    249.   'doc.AttachedTemplate = Chr(34) & "C:\Documents and Settings\Ed\My Documents\FindSongs\SongsTempl.dot" & Chr(34)
    250.   appWd.ActiveWindow.WindowState = wdWindowStateMaximize
    251.   appWd.ActiveWindow.View = wdPrintView
    252.   '''appWd.ActiveWindow.View.Zoom.Percentage = 92
    253.   '''appWd.ActiveWindow.View.Zoom.Percentage = 130
    254.   doc.ActiveWindow.ActivePane _
    255.     .Zooms(wdPrintView).PageFit = wdPageFitFullPage
    256.  
    257.   bolFirstLet = True
    258.  
    259. Else
    260.   'MsgBox "No file"
    261. End If
    262.  
    263. If bolTwoMon = False Then
    264.   'Set form to go back
    265.   frmTop = SearchMe.Top
    266.   frmLeft = SearchMe.Left
    267.   SearchMe.Top = 3
    268.   SearchMe.Left = 3
    269.   SearchMe.Height = 1
    270.   SearchMe.Width = 5000
    271.   SearchMe.Caption = "Close song by typing 0 (zero)."
    272. End If
    273.  
    274. Timer1.Enabled = True
    275. Timer1.Interval = 600
    276.  
    277. If strFile <> "" Then
    278.  On Error Resume Next
    279.   appWd.Visible = True
    280.   AppActivate appWd.Caption
    281.   appWd.Windows(1).Activate
    282.  On Error GoTo 0
    283.   appWd.Windows(1).View.TableGridlines = False
    284.   appWd.Windows(1).DisplayRulers = False
    285.   appWd.Windows(1).View.ShowAll = False
    286.   doc.ShowGrammaticalErrors = False
    287.   doc.ShowSpellingErrors = False
    288.   appWd.Windows(1).SmallScroll Down:=3
    289.  
    290.   'If bolTwoMon = True Then
    291.     SearchMe.SetFocus
    292.     SearchMe.Text1.SetFocus
    293.   'End If
    294.  
    295. End If
    296.  
    297. NoSong:
    298. bolNoSong = False
    299.  
    300. End Sub
    301.  
    302. Private Sub Timer1_Timer()
    303.  
    304. Dim tstDocName As String
    305.  
    306. ' Check to see if a Word doc exists
    307. On Error Resume Next
    308.   Set doc = appWd.Documents(1)
    309.   tstDocName = doc.Name
    310.  
    311.   'If no Word doc, restore form
    312.   If Err.Number <> 0 Then
    313.     Timer1.Enabled = False
    314.     Set doc = Nothing
    315.    
    316.     'Bring app to front
    317.     appWd.Visible = False
    318.     SearchMe.Top = frmTop
    319.     SearchMe.Left = frmLeft
    320.     SearchMe.Height = 12075
    321.     SearchMe.Width = 10980
    322.     SearchMe.Caption = "Search Song List"
    323.  
    324.     '''SearchMe.Visible = True
    325.     SearchMe.SetFocus
    326.     SearchMe.Text1.SetFocus
    327.  
    328.   Else
    329.     'If a Word doc exists, ensure form has focus
    330.     Call SetWindowPos(MyHwnd, HWND_TOPMOST, 0, 0, 0, 0, SWP_NOSIZE)
    331.     Call SetActiveWindow(MyHwnd)
    332.     'SearchMe.SetFocus
    333.     'AppActivate ("FindMySong")
    334.  
    335.    
    336.     If bolTwoMon = False Then _
    337.       doc.Windows(1).Activate
    338.   End If
    339.  
    340. On Error GoTo 0
    341.  
    342. End Sub

  14. #14
    PowerPoster
    Join Date
    Feb 2012
    Location
    West Virginia
    Posts
    6,995

    Re: Need help getting form window to top and active

    Code:
    'AppActivate ("FindMySong")
    Try
    Code:
    AppActivate(Me.Caption)
    Could this be your problem that makes it flash?
    Code:
    If bolTwoMon = False Then _
          doc.Windows(1).Activate
      End If

  15. #15

    Thread Starter
    Member
    Join Date
    Dec 2010
    Posts
    37

    Re: Need help getting form window to top and active

    Thank you very much!! I'll have to wait until later to try those, and I'll let you know what happens.

    So I had the AppActivate syntax wrong, eh?? Knew it would be something simple!

    And all the bolTwoMon stuff should have been commented out. I'll have to fix that. (Originally, this was just me on my laptop, and I had thought to try an external monitor so I could leave the form open on one and pull up songs on the other. Now we do have two monitors, but they're clones showing the same thing.)

    Ed

  16. #16
    PowerPoster Spoo's Avatar
    Join Date
    Nov 2008
    Location
    Right Coast
    Posts
    2,656

    Re: Need help getting form window to top and active

    Ed

    Glad you and DataMiser have worked things out.

    So, now that your "deck" is sufficiently cleared, you
    might be in a better position to try the alternative
    I mentioned.

    Regarding your concern ..
    Because they are songs, they have certain font and
    style settings that I didn't want to risk affecting by
    opening them in anything other than Word.
    .. I'll mention in passing that the WebBrowser control
    • preserves all font and style settings
    • preserves all highlighted text (colors)
    • preserves all graphics
    • automatically includes scroll bars

    Basically, it looks and feels just like Word itself.

    Spoo

  17. #17

    Thread Starter
    Member
    Join Date
    Dec 2010
    Posts
    37

    Re: Need help getting form window to top and active

    Thank you, Spoo. Obviously, I've never delved that far into this. The WebBrowser control might be a good alternative, especially if it loads faster! :8>)

    Ed

  18. #18

    Thread Starter
    Member
    Join Date
    Dec 2010
    Posts
    37

    Re: Need help getting form window to top and active

    Quote Originally Posted by DataMiser View Post
    Could this be your problem that makes it flash?
    Code:
    If bolTwoMon = False Then _
          doc.Windows(1).Activate
      End If
    Commented this out
    Quote Originally Posted by DataMiser View Post
    Code:
    'AppActivate ("FindMySong")
    Try
    Code:
    AppActivate(Me.Caption)
    No joy! The task bar and the form title bar just flash.

    Looks like it's time to see about a second form with a full-screen WebBrowser control.

    Ed

  19. #19
    PowerPoster Spoo's Avatar
    Join Date
    Nov 2008
    Location
    Right Coast
    Posts
    2,656

    Re: Need help getting form window to top and active

    Ed

    In that case, you might want to take a look at this thread

    http://www.vbforums.com/showthread.php?t=673141

    Guess which thread was "another thread" ..

    Spoo

  20. #20

    Thread Starter
    Member
    Join Date
    Dec 2010
    Posts
    37

    Re: Need help getting form window to top and active

    Yah - saw that thread as I was scoping out the WebBrowser control.
    I'm sure I will have some questions to add to it!!
    Won't have a chance until this weekend, though.

    Ed

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Featured


Click Here to Expand Forum to Full Width

Survey posted by VBForums.