Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

I don't want to activate my Form!?

Posted on 2000-03-16
31
Medium Priority
?
167 Views
Last Modified: 2010-04-04
How can I prevent to "activate" my form if I press mouse button on it?
My program should be always on "background" position - as a desktop... If I use SetWindowPos all other windows blink once and I want to escape it... I want to do that if I press on my window the last active window became just passive without any blinks... Absolutely like when you press on Desktop - nothing blinks! Can you provide me with the CODE, please?!
0
Comment
Question by:Masonok
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 14
  • 8
  • 5
  • +2
31 Comments
 
LVL 10

Expert Comment

by:Lischke
ID: 2623197
Set TForm.Enabled := False;

Ciao, Mike
0
 

Author Comment

by:Masonok
ID: 2623240
NO! Doesn't work as I want!
It became un touchable! Useless.

Form must recognize all mouse events but stay on background... always
0
 
LVL 5

Expert Comment

by:TheNeil
ID: 2623288
You could add SendToBack to the OnPaint method but it still causes the brief blink that you wanted to avoid. It'll still get mouse moves though.

You can get rid of the blink by setting the form's Enabled property to FALSE and just adding SendToBack to the OnActivate method (rather than OnPaint) BUT it doesn't process the mouse anymore. A solution to THAT would be to have a timer and check the mouse position using Mouse.CursorPos every 10 milliseconds or so. No idea how you'd process mouse clicks though

The Neil
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Author Comment

by:Masonok
ID: 2623344
Is there any possibilities to get what I want by prosessing Windows MESSAGES?

And if it possible - how can I do that?
0
 
LVL 2

Expert Comment

by:craig_capel
ID: 2623359
Mas, i am not totally sure what your program is doing, if you let us know what your making?... maybe i can help...
0
 
LVL 10

Expert Comment

by:Lischke
ID: 2623387
Ok, I think I have what you need. It is the message WM_WINDOWPOSCHANGING. The remark to this message is:

While this message is being processed, modifying any of the values in WINDOWPOS affects the window's new size, position, or place in the Z order. An application can prevent changes to the window by setting or clearing the appropriate bits in the flags member of WINDOWPOS.
//--- end of quote

Hence all you need is to capture this message for the window you want to have as background and set
 
  WindowPos.flags := WindowPos.Flags or SWP_NOZORDER;

before you call the inherited handler. This should prevent the window from changing its z-order.

Ciao, Mike
0
 

Author Comment

by:Masonok
ID: 2623390
I want to write a program to replace Windows Desktop... So my form should stay behind all other windows and listen where is mouse on my form! It should have the same behavior as Win Desktop!
So you know the idea... any suggestions?
0
 

Author Comment

by:Masonok
ID: 2623410
Can you provide me a sample code - where and how I need to use WindowPos (or whatever). I am newone in this area.
0
 
LVL 5

Expert Comment

by:TheNeil
ID: 2623416
Having just tried catching the WM_ACTIVATE and WM_ACTIVATEAPP messages, I have to say that I think you're stuck with having a blink. There is however a quick fix solution...

If you capture the desktop as an image, throw it onto your form and THEN do a SendToBack then you'll still get the blink but you just won't notice it. Just a thought

The Neil
0
 

Author Comment

by:Masonok
ID: 2623436
I guess It better to have a sex with Messages - I think It will work faster...

Can you say how can I catch a Win Message before this message will be recognize by my application and executed? I found that I should be able to do this but I cannot find where and how can I operate with these messages!
0
 
LVL 2

Expert Comment

by:craig_capel
ID: 2623457
ok I just had a look for this code i thought i had, and luckly, i found it :)

http://members.xoom.com/craig_c/md4.zip 

Ok this will allow you to catch the mouse clicks without having a dll running... but If you manage to do anything with this, i would like to know how, every time i add code, it becomes REALLY unstable and crashes... for example...

Getmessagepos combined with that method will be all i need, but getting the two to work together is proving difficuly...

num:=getmessagepos();
 x:=hiword(num);
 y:=loword(num);

If you can make a form that displays the x and y values (code above) and make it show everytime the user clicks the mouse button, i would be a very happy chappy, Points mean nothing once i got this code stable....

Craig C.
0
 
LVL 1

Expert Comment

by:nrico
ID: 2623471
Maybe it's just me, but if you click the desktop you _will_ get a flash: All windows will lose focus and the desktop gains it.

Other problem: All windows should still be visible, though, so somehow you'll have to prevent the painting of your desktop form.
0
 
LVL 1

Expert Comment

by:nrico
ID: 2623476
Unrelated question: Are you using
  PaintDesktop(Form1.Canvas.Handle)
to let the original Desktop background show trough?
0
 
LVL 10

Accepted Solution

by:
Lischke earned 200 total points
ID: 2623486
Masonok,

well, as I said, I've got it. The code for your form should include:

type
  TForm1 = class(TForm)
  private
    procedure WMWindowPosChanging(var Message: TWMWindowPosChanging); message WM_WINDOWPOSCHANGING;
  end;

  :
  :

procedure TMainForm.WMWindowPosChanging(var Message: TWMWindowPosChanging);

begin
  with Message do
    WindowPos.flags := WindowPos.flags or SWP_NOZORDER;
  inherited;
end;


Once the one is send back in the z-order you never get it back to front(although you still can activate it etc.).

Ciao, Mike
0
 

Author Comment

by:Masonok
ID: 2623510
YES man! I know that I need to prevent paint it...

Could you show me how to catch a message, than recognize it and if this message is should activate my form - I need kill it? Do you think it is good idea?
0
 

Author Comment

by:Masonok
ID: 2623565
Great!
0
 
LVL 2

Expert Comment

by:craig_capel
ID: 2623605
this has to be one of the best reponce times i have ever seen
0
 

Author Comment

by:Masonok
ID: 2623618
Great place!
Great People!
Great Professionals!
0
 

Author Comment

by:Masonok
ID: 2623646
Check this out! Now I get what I want - this code send my FORM back and prevent Z-order to change! Do you think it is OK?

procedure TDesktop.WMWindowPosChanging(var Message: TWMWindowPosChanging);
begin
  with Message do

WindowPos.hwndInsertAfter:= HWND_BOTTOM;

WindowPos.flags := WindowPos.flags or SWP_NOZORDER;
  inherited;
end;
0
 
LVL 10

Expert Comment

by:Lischke
ID: 2623650
:-)
0
 
LVL 10

Expert Comment

by:Lischke
ID: 2623661
Yep, but you don't need the HWND_BOTTOM parameter to set (at least according to the help file) because:

SWP_NOZORDER      Retains the current Z order (ignores the hWndInsertAfter parameter).

But anything else is ok :-)

Ciao, Mike
0
 

Author Comment

by:Masonok
ID: 2623674
The problem is that after my program starts - it close all other windows - can I send it back at the beginning?
0
 
LVL 2

Expert Comment

by:craig_capel
ID: 2623686
whats inherited;  actually do?.....
0
 
LVL 10

Expert Comment

by:Lischke
ID: 2623723
Masonok,

do you mean you would like to prevent closing all already existant windows? If yes then use a flag which is initially not set and only if this flag is set then modify the WindowPos structure. On app start bring the form to the bottom (SetWindowPos with HWND_BOTTOM) and then set this flag.

Craig,

inherited; just calls the the inherited method handler with the same mehod index (given by the message ID). In TControl (which is the ancestor for all windowed controls) the default window procedure will be called (which is somewhere in User32.DLL for non-subclassed windows otherwise in the specific DLLs like ComCtrl32.dll for TTreeView etc.).

Ciao, Mike
0
 
LVL 2

Expert Comment

by:craig_capel
ID: 2623776
urrrrrrr ok, thanks...... for the info?... (feels dumb)
0
 

Author Comment

by:Masonok
ID: 2626483
Thank you! You really help me!
0
 

Author Comment

by:Masonok
ID: 2626537
I hope it could be interest for YOU!

procedure TDesktop.WMWindowPosChanging(var Message: TWMWindowPosChanging);
begin
  with Message do begin
   If WindowPos.hwndInsertAfter = HWND_BOTTOM then
    WindowPos.flags := WindowPos.flags or SWP_NOZORDER;

   WindowPos.hwndInsertAfter := HWND_BOTTOM;

  end;
  inherited;
end;

Look at this  - this code NOW Works!!!!
At the beginning my form goes back and then works as I need! It is interesting - If I put
"Windowpos.hwndInsertAfter:= hwnd_bottom" before "If Windowpos....."
it doesn't send my form back! But on the way I showed now - IT WORKS!
Why it starts to work only on the "Second circle"?

(if I use Setwindowpos in this procedure when my form starts or closing - all other windows are bkinking (several times). In my code windows don't blink!)
0
 
LVL 10

Expert Comment

by:Lischke
ID: 2627053
Ah yes, this makes it even easier :-) Here's a little modification to make it also saver :-))


procedure TDesktop.WMWindowPosChanging(var Message: TWMWindowPosChanging);
begin
  with Message do begin
   If WindowPos.hwndInsertAfter = HWND_BOTTOM then
    WindowPos.flags := WindowPos.flags or SWP_NOZORDER
  else
  begin
    WindowPos.hwndInsertAfter := HWND_BOTTOM;
WindowPos.flags := WindowPos.flags and not SWP_NOZORDER;
  end;

  end;
  inherited;
end;
0
 

Author Comment

by:Masonok
ID: 2627105
:)! That was COOL!
I can say this code Kicks my Windows OFF! :) My comruter - became dead! :)

Even Mice freezes!
0
 
LVL 10

Expert Comment

by:Lischke
ID: 2627172
Ooooh, this was really not intented. How can that be? Anyway, because you have a working solution (and there's nothing more interesting for me with this problem) I'd say let's close this thread so we can focus on other things :-)

Ciao, Mike
0
 

Author Comment

by:Masonok
ID: 2627191
Ok! Thank you very much for you help!
0

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction I have seen many questions in this Delphi topic area where queries in threads are needed or suggested. I know bumped into a similar need. This article will address some of the concepts when dealing with a multithreaded delphi database…
Introduction Raise your hands if you were as upset with FireMonkey as I was when I discovered that there was no TListview.  I use TListView in almost all of my applications I've written, and I was not going to compromise by resorting to TStringGrid…
This tutorial will teach you the special effect of super speed similar to the fictional character Wally West aka "The Flash" After Shake : http://www.videocopilot.net/presets/after_shake/ All lightning effects with instructions : http://www.mediaf…
In this video, Percona Solution Engineer Dimitri Vanoverbeke discusses why you want to use at least three nodes in a database cluster. To discuss how Percona Consulting can help with your design and architecture needs for your database and infras…
Suggested Courses

688 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