• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 175
  • Last Modified:

I don't want to activate my Form!?

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
Masonok
Asked:
Masonok
  • 14
  • 8
  • 5
  • +2
1 Solution
 
LischkeCommented:
Set TForm.Enabled := False;

Ciao, Mike
0
 
MasonokAuthor Commented:
NO! Doesn't work as I want!
It became un touchable! Useless.

Form must recognize all mouse events but stay on background... always
0
 
TheNeilCommented:
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
Upgrade your Question Security!

Your question, your audience. Choose who sees your identity—and your question—with question security.

 
MasonokAuthor Commented:
Is there any possibilities to get what I want by prosessing Windows MESSAGES?

And if it possible - how can I do that?
0
 
craig_capelCommented:
Mas, i am not totally sure what your program is doing, if you let us know what your making?... maybe i can help...
0
 
LischkeCommented:
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
 
MasonokAuthor Commented:
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
 
MasonokAuthor Commented:
Can you provide me a sample code - where and how I need to use WindowPos (or whatever). I am newone in this area.
0
 
TheNeilCommented:
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
 
MasonokAuthor Commented:
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
 
craig_capelCommented:
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
 
nricoCommented:
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
 
nricoCommented:
Unrelated question: Are you using
  PaintDesktop(Form1.Canvas.Handle)
to let the original Desktop background show trough?
0
 
LischkeCommented:
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
 
MasonokAuthor Commented:
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
 
MasonokAuthor Commented:
Great!
0
 
craig_capelCommented:
this has to be one of the best reponce times i have ever seen
0
 
MasonokAuthor Commented:
Great place!
Great People!
Great Professionals!
0
 
MasonokAuthor Commented:
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
 
LischkeCommented:
:-)
0
 
LischkeCommented:
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
 
MasonokAuthor Commented:
The problem is that after my program starts - it close all other windows - can I send it back at the beginning?
0
 
craig_capelCommented:
whats inherited;  actually do?.....
0
 
LischkeCommented:
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
 
craig_capelCommented:
urrrrrrr ok, thanks...... for the info?... (feels dumb)
0
 
MasonokAuthor Commented:
Thank you! You really help me!
0
 
MasonokAuthor Commented:
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
 
LischkeCommented:
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
 
MasonokAuthor Commented:
:)! That was COOL!
I can say this code Kicks my Windows OFF! :) My comruter - became dead! :)

Even Mice freezes!
0
 
LischkeCommented:
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
 
MasonokAuthor Commented:
Ok! Thank you very much for you help!
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Cloud Class® Course: CompTIA Cloud+

The CompTIA Cloud+ Basic training course will teach you about cloud concepts and models, data storage, networking, and network infrastructure.

  • 14
  • 8
  • 5
  • +2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now