Solved

Stop HTCLIENT acting like HTCAPTION

Posted on 2004-10-02
6
697 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
ID: 12206945
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
ID: 12208237
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
ID: 12211002
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
Live: Real-Time Solutions, Start Here

Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

 
LVL 33

Expert Comment

by:Slick812
ID: 12219857
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
ID: 12225379
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
ID: 12229335
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

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

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

Suggested Solutions

Objective: - This article will help user in how to convert their numeric value become words. How to use 1. You can copy this code in your Unit as function 2. than you can perform your function by type this code The Code   (CODE) The Im…
In this tutorial I will show you how to use the Windows Speech API in Delphi. I will only cover basic functions such as text to speech and controlling the speed of the speech. SAPI Installation First you need to install the SAPI type library, th…
This Micro Tutorial will give you a basic overview how to record your screen with Microsoft Expression Encoder. This program is still free and open for the public to download. This will be demonstrated using Microsoft Expression Encoder 4.
Established in 1997, Technology Architects has become one of the most reputable technology solutions companies in the country. TA have been providing businesses with cost effective state-of-the-art solutions and unparalleled service that is designed…

813 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

11 Experts available now in Live!

Get 1:1 Help Now