CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 2 of 2

Thread: ~Focus~

  1. #1
    Join Date
    Jan 2000
    Posts
    45

    ~Focus~

    From my program, how would I make another program the active window, such as Microsoft paint or notepad?


  2. #2
    Join Date
    May 1999
    Location
    Oxford UK
    Posts
    1,459

    Re: ~Focus~

    It depends on which version of Windows you are running. If you are running Windows95, or NT4 then you can use this code :


    option Explicit
    '
    public Declare Function FindWindowEx Lib "user32" Alias "FindWindowExA" _
    (byval hWnd1 as Long, byval hWnd2 as Long, byval lpsz1 as string, _
    byval lpsz2 as string) as Long
    public Declare Function SetForegroundWindow Lib "user32" _
    (byval hwnd as Long) as Long
    '
    public Sub FindNotepad()
    Dim lHwnd as Long
    '
    lHwnd = FindWindowEx(0, 0, "Notepad", vbNullString)
    If lHwnd > 0 then
    SetForegroundWindow lHwnd
    End If
    End Sub




    - in a module.

    If you use Win98 or Win2K, Microsoft have 'changed the rules' so that an application can't just jump to the front when it feels like it - although Karl Peterson has some excellent code to get around this problem at :

    http://www.mvps.org/vb/index2.html?samples.htm - look for the ForceFore.zip sample - be warned though, it's quite heavy going if you don't know anything about the API.


    Chris Eastwood

    CodeGuru - the website for developers
    http://codeguru.developer.com/vb

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

Featured