DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

+ Reply to Thread
Results 1 to 3 of 3
  1. #1
    Frank Guest

    How to make an application get focus



    I am developping product which consist of two applications, let me name them
    A and B. B is an ActiveX EXE(standalone) which exposes a class C.
    C will provide the communication channel between A and B. In A, I create
    an object ObjC of C. A and B, each has a button, when you click on the button
    in A, the focus will turn to B. When clicking on the button in B,
    the focus is supposed to turn to A. C exposes a method Setfocus. in A,
    Calling ObjC.SetFocus which calls the SetFocus of the main form in B.
    Objc exposes an event. A will receive the event when B raises it. In the
    event procedure, A calls the Form's SetFocus.

    It is supposed to work. The result is that Setfocus of Form seems not work.
    Sometimes it works. Here A is a MDI application and B is a SDI

    It is for sure that all Setfocus is called. Any processes happened, but in
    term of behavior, nothing happened.

    Any help would be highly appreciated.

    Thank a lot in advance

    Frank


  2. #2
    Kenny Acock Guest

    Re: How to make an application get focus


    Frank,

    Try the SetForegroundWindow API:

    Declare Function SetForegroundWindow Lib "user32" (ByVal hWnd As Long) _
    As Long

    Declare this in both A and B. If A calls this to set focus for B all you
    will get is the flashing taskbar button. So A & B should call it for themselves.
    When A wants focus, A calls it for itself, and also B calls it for itself.

    You can call it like this:

    lReturn = SetForegroundWindow(Me.hWnd)
    or
    SetForegroundWindow Me.hWnd

    I haven't tested this, but it should work.

    --Kenny

  3. #3
    Frank Guest

    Re: How to make an application get focus


    Hi, Kenny,

    I already totally solved the problem.

    Thanks a lot

    Frank

    "Kenny Acock" <kennya@teacherspal.com> wrote:
    >
    >Frank,
    >
    >Try the SetForegroundWindow API:
    >
    >Declare Function SetForegroundWindow Lib "user32" (ByVal hWnd As Long) _
    > As Long
    >
    >Declare this in both A and B. If A calls this to set focus for B all you
    >will get is the flashing taskbar button. So A & B should call it for themselves.
    > When A wants focus, A calls it for itself, and also B calls it for itself.
    >
    >You can call it like this:
    >
    >lReturn = SetForegroundWindow(Me.hWnd)
    > or
    >SetForegroundWindow Me.hWnd
    >
    >I haven't tested this, but it should work.
    >
    >--Kenny



Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


Top DevX Stories

Easy Web Services with SQL Server 2005 HTTP Endpoints
JavaOne 2005: Java Platform Roadmap Focuses on Ease of Development, Sun Focuses on the "Free" in F.O.S.S.
Wed Yourself to UML with the Power of Associations
Microsoft to Add AJAX Capabilities to ASP.NET
IBM's Cloudscape Versus MySQL


Sponsored Links