Solved

Stop HTCLIENT acting like HTCAPTION

Posted on 2004-10-02
6
678 Views
Last Modified: 2010-04-05
I have this code :

....Inherited;....
if Msg.Result = HTCLIENT then Msg.Result := HTCAPTION;
.....

It's usefull cause my form has no borders and i want to move it anyware on the screen.

I also have an image on the form with an "on click event" but it doesnt work cause the form acts like caption (..cant ''see'' the image).

I dont want to replace the image with a button or any other control.
Is there a way to get back focus on the image?

Also can u please give me some help with HT... ?
For e.x :
Form=HTCLIENT
Caption=HTCAPTION
Image= ? .......
 
0
Comment
Question by:CodedK
  • 3
  • 2
6 Comments
 
LVL 7

Accepted Solution

by:
LRHGuy earned 75 total points
Comment Utility
Anything dereived from a TControl returns HTCLIENT unless it shouldn't (meaning it's been overridden.)

You most likely will have to check the hit point yourself, and only set HTCAPTION when you know there is no control at the point. Something similar to:

if (Message.Result = HTCLIENT)
and (ControlAtPos(ScreenToClient( SmallPointToPoint(TWMNCHitTest(Message).Pos)), False)= nil)
then
          Message.Result := HTCAPTION;

I haven't tested that, but I think it'll work.
0
 
LVL 33

Assisted Solution

by:Slick812
Slick812 earned 45 total points
Comment Utility
hello CodedK, I have tried to use the HTCAPTION as a way to get a drag form on Client area, but I had proplems with it, the method I use now is with the Forms's OnMouseDown Event, get your OnMouseDown event and add this code -


procedure TForm1.FormMouseDown(Sender: TObject; Button: TMouseButton;
  Shift: TShiftState; X, Y: Integer);
begin
if (Button = mbLeft) then
  begin
  ReleaseCapture;
  Form1.perform(WM_SysCommand, $F012, 0);
  end;
end;

this will allow to to Click other controls (and TImages) on your form. . .
If the TImage you talk about the click event, covers the entire form, then you may have problems
0
 
LVL 16

Author Comment

by:CodedK
Comment Utility
Thank you LRHGuy and Slick812.
LRHGuy code works fine (replaced message with msg)


  private
    { Private declarations }
    procedure WMNCHitTest(var Msg: TWMNCHitTest);
    message WM_NCHITTEST;
.......
........

procedure TForm1.WMNCHitTest(var Msg: TWMNCHitTest);
begin
  inherited;
  if (Msg.Result = HTCLIENT)
  and
  (ControlAtPos(ScreenToClient(SmallPointToPoint(TWMNCHitTest(Msg).Pos)),False)
  = nil)
  then
  Msg.Result := HTCAPTION;
end;


I think this code will work for u too Slick812.

But still this "WM_SysCommand, $F012, 0" and
(ControlAtPos(ScreenToClient(SmallPointToPoint(TWMNCHitTest(Msg).Pos)),False) = nil)
remains a mystery... Where can i find a list of WM.. commands and msg ???
0
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 
LVL 33

Expert Comment

by:Slick812
Comment Utility
There are several "System" message identifier (wParam) constants for the WM_SYSCOMMAND window message, examples of some you can use or test for are SC_MOVE, SC_CLOSE, and SC_KEYMENU . There are some others for hit test actions that are not generaly listed in the win32 Help for WM_SYSCOMMAND, these include -

SC_DRAGMOVE = $F012; // used if result of WM_NCHITTEST is HTCAPTION
SC_LEFTSIZE = $F001; // used if result of WM_NCHITTEST is HTLEFT
SC_RIGHTSIZE = $F002; // used if result of WM_NCHITTEST is HTRIGHT
SC_UPSIZE = $F003; // used if result HTTOP
SC_UPLEFTSIZE = $F004; // used if result HTTOPLEFT
SC_UPRIGHTSIZE = $F005; // used if result HTTOPRIGHT
SC_DNSIZE = $F006; // HTBOTTOM
SC_DNLEFTSIZE = $F007; // HTBOTTOMLEFT
SC_DNRIGHTSIZE = $F008; // HTBOTTOMRIGHT

as I understand the way this works, If you Left button Mouse Down on the Form (window) Caption (non button) the WM_NCHITTEST message is sent to the Form with the result as constanst HTCAPTION, then this WM_NCHITTEST message, HTCAPTION result is processed by the System, it will send the WM_SYSCOMMAND message to that same window (Form) with the wParam as SC_DRAGMOVE ($F012).

In the code you use for the WM_NCHITTEST message, you test for the HTCLIENT Result, and then change the Result to HTCAPTION. If the HTCAPTION Result is returned to the system, it will cause the system to send the WM_SYSCOMMAND message to the Form, with the wParam as SC_DRAGMOVE ($F012). . .

in my code I Skip all of the WM_NCHITTEST processing and go directly to what the system does anyway, perform the WM_SYSCOMMAND message, with the wParam as SC_DRAGMOVE ($F012) . . . .

if you want you can test this out by getting the WM_SYSCOMMAND and testing for the wParam as SC_DRAGMOVE , , with this code -

private
    { Private declarations }
    procedure WMSysCommand(var Message: TMessage); message WM_SYSCOMMAND;

procedure TForm1.WMSysCommand(var Message: TMessage);
begin
if Message.WParam = $F012 then
  Label1.Caption := 'Got SC_DRAGMOVE wParam';
if Message.WParam = $F001 then
  Label1.Caption := 'Got SC_LEFTSIZE wParam';
inherited;
end;

if you drag your form by the caption or size it by the Left, the Label1 should change Captions. . . .

- - - - - - - - - - - - - - - - - -

You ask about other windows messages (and commands), there are many, many (more than a hundred) of system window messges, many of these listed in the Win32 API Help that comes with most versions of Delphi. You can start by looking in the Index for  "WM_A", and go down the list. . . . You can find thousands of  API functions  in the API Help also, but it would take a LONG time to cover all of the API methods and messages

0
 
LVL 16

Author Comment

by:CodedK
Comment Utility
Thank you Slick812.
You helped me a lot man.
I know that it will take a long time... but i didnt even knew where to look.
This could be a start....
So.... thank you again.. :)
0
 
LVL 33

Expert Comment

by:Slick812
Comment Utility
yea, the Win32 API Help is good to learn from, but there is so much in it, most do not know where to look.  . some tips for ya-

you might go to Index  "Messages and Message Queues" in the API Help and then you need to lclick the    >_>    title bar button at the top of the Help window, to go to the next page of that subject. .  there are several many pages to that subject. .

you may also want to look at Index  "Windows" and click the   >_>  button to read those pages
0

Featured Post

What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

Have you ever had your Delphi form/application just hanging while waiting for data to load? This is the article to read if you want to learn some things about adding threads for data loading in the background. First, I'll setup a general applica…
Hello everybody This Article will show you how to validate number with TEdit control, What's the TEdit control? TEdit is a standard Windows edit control on a form, it allows to user to write, read and copy/paste single line of text. Usua…
This video discusses moving either the default database or any database to a new volume.
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

762 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

10 Experts available now in Live!

Get 1:1 Help Now