Block window focus

Posted on 2006-04-18
Last Modified: 2010-04-05
I created an on-screen keyboard and I want my form not to receive the focus when I click it or any control on it. Does anybody know how can I do it?

Thanks in advance
Question by:quentin1
    LVL 11

    Accepted Solution

    Try this:

    procedure TForm1.FormCreate(Sender: TObject);
    FormStyle := fsStayOnTop;
    SetWindowLong(handle, gwl_exstyle, GetWindowLong(handle, gwl_exstyle) or ws_ex_noactivate);

    procedure TForm1.Button1Click(Sender: TObject);
    caption := 'test';
    LVL 11

    Expert Comment

    You may also add this line to onCreate event:
    ShowWindow(handle, sw_showna);

    Without this line the form (when I tried it) looked like it's active (however it was NOT). When added this line, it got a "light" border (like inactive windows have).

    When clicking controls on a form with ws_ex_noactivate ex-style, they may get a focus, but they will not be active.

    Author Comment

    Thanks ZhaawZ. It works fine
    LVL 11

    Expert Comment

    glad to help ;)

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Maximize Your Threat Intelligence Reporting

    Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

    This article explains how to create forms/units independent of other forms/units object names in a delphi project. Have you ever created a form for user input in a Delphi project and then had the need to have that same form in a other Delphi proj…
    In my programming career I have only very rarely run into situations where operator overloading would be of any use in my work.  Normally those situations involved math with either overly large numbers (hundreds of thousands of digits or accuracy re…
    It is a freely distributed piece of software for such tasks as photo retouching, image composition and image authoring. It works on many operating systems, in many languages.
    This video discusses moving either the default database or any database to a new volume.

    779 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    9 Experts available now in Live!

    Get 1:1 Help Now