Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

form redrawing in game app

Status
Not open for further replies.

tmandy

Instructor
May 12, 2004
1
US
Excuse the long winded diatribe below, but I wanted to show the flow of the problem

I have a small program I developed some years ago in D3 C/S that controls aircraft in a game. Specifically MS Flight Simulator. It is lightening fast and in no way disturbs the game it controls. I've just re-written it in D7 and have a problem with Focus between the sim and my app.

The Main Form is simple, with panels holding a series of Speedbuttons. This form has no border and fsstayontop is set. On startup the application sees

Code:
initialization
sendtowindow(s);
//which gets the handle of the sim and uses the API

Code:
getforegroundwindow(hwnd)
to make it active. Since the form is stayontop, I also see it over the sim.

PROBLEM OCCURRENCE 1... It takes about three seconds to redraw the form and speedbuttons. I send keystrokes to the sim with (part of code) (A)

Code:
(A) procedure TForm1.SB_RMouseDown(Sender: TObject; Button: TMouseButton;
  Shift: TShiftState; X, Y: Integer);
begin
setforegroundwindow(fltwin); //handle of the sim window
PostKeyEX32(Ord('R'),[],False); //send an R to th sim
setforegroundwindow(fltwin);
end;

I can live with the above, but why the slow redraw?
Now, the real problem:

There is a very small form with a bitmap on it that I call up to sit in the corner of the sim to free up space. It is also borderless and FsStayOnTop I call it as in (B)below:

Code:
(B) procedure TForm1.sb_TinyMouseDown(Sender: TObject; Button: TMouseButton;
  Shift: TShiftState; X, Y: Integer);
begin
form1.Hide;
form2.Show;
setwindowpos(tinywin, HWND_TOPMOST, 0, 0, 0, 0, SWP_NOMOVE + SWP_NOSIZE);

All is well and it appears above the sim.

Now we click the bitmap to hide the tiny form and return to the main form with the speedbuttons. (C) below...

Code:
(C) procedure TForm2.LMDNImage1Click(Sender: TObject);
begin
form2.Hide;
form1.Left := form2.Left;
form1.Top := form2.Top;
setwindowpos(mywin, HWND_TOPMOST, 0, 0, 0, 0, SWP_NOMOVE + SWP_NOSIZE);
form1.Show;
end;

This works VERY FAST EXCEPT the sim is not active. If I add code as in setwindowpos() OR showwindow() OR setforegroundwindow()API's I go round and round with that slow redraw of the form again.

What I'd like is the main form to pop up without redrawing every component AND the sim to have focus again and my app to sit there on top of the sim ready to do its thing.

BTW

I used to send a ('') null keysequence to the sim to focus it. This does not seem to do the trick in D7???

Thanks for any help you folks can offer.

Tim Mandeville
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top