TSpeedButton는 CM_MOUSEENTER, CM_MOUSELEAVE 의 메세지와 겹쳐서 처리가 잘 되지 않는다고 하는군요. 만약 굳이 WM_NCHITTEST 를 사용하시려면, HTCAPTION 로 재 설정하시기 전에, 마우스가 SpeedButton 위에 있는지 비교하신 뒤, 설정해 주시는 방법이 있습니다.
다른 하나의 방법은, 폼을 잡아서 드래그 해 주시는 방법은 아래와 같이 Form의 OnMouseDown에 간단히 넣어주시면 처리를 하실 수 있습니다. 다른 메세지 처리가 없어두요.. (하지만 아래처럼 WM_NCHITTEST 을 사용하실때는 Dispatch 를 꼭 해주셔야 합니다)
아래는 간단히 폼의 드래그를 해주는 처리 예제입니다. 그리고, 만약 폼의 이동시 폼의 모양을 그대로 보이게 하고 싶으시다면 아래의 게시물도 도움이 되실것 같네요.
http://www.borlandforum.com/impboard/impboard.dll?action=read&db=bcb_qna&no=18635
//---------------------------------------------------------------------------
#include <vcl.h>
#pragma hdrstop
#include "Unit1.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma resource "*.dfm"
TForm1 *Form1;
//---------------------------------------------------------------------------
__fastcall TForm1::TForm1(TComponent* Owner) : TForm(Owner)
{
}
//---------------------------------------------------------------------------
void __fastcall TForm1::FormMouseDown(TObject *Sender, TMouseButton Button, TShiftState Shift, int X, int Y)
{
if(Shift.Contains(ssLeft)) {
ReleaseCapture();
SendMessage(Handle, WM_SYSCOMMAND, 0xF012, 0);
}
}
//---------------------------------------------------------------------------
유지상 님이 쓰신 글 :
: void __fastcall TForm1::WMNCHitTest(TWMNCHitTest& Msg)
: {
: TForm::Dispatch(&Msg);
: if( Msg.Result == HTCLIENT)
: Msg.Result = HTCAPTION;
: }
: 프로젝트에서 폼 하나만 만들고, 위와 같은 코딩을 추가하였습니다.
: 위 코딩은 프로그램실행시, 폼의 클라이언트영역을 클릭해서 폼을 드레그할 수 있게 해줍니다. (즉, 제목표시줄을 클릭해서 윈도우를 드레그하는 것과 같은 효과가 나옵니다.)
: 그 폼 위에 두 개의 버튼을 올려놓았는데,
: 하나는 TButton 이고, 다른 하나느 TSpeedButton입니다.
: 프로그램을 실행해보면, TButton을 누르면 버튼이 눌려집니다.
: 그러나, TSpeedBUtton 은 눌려지지가 않습니다.
: TSpeedButton에 마우스를 누르면, 버튼이 눌려지지 않는 대신, 폼을 드레그할 수 있게 됩니다.
: 왜 이렇게 TButton과 TSpeedButton이 다르게 행동하는 거지요?
: TSpeedButton도 눌려질 수 있도록 하려면 어떻게 해야 하죠?
:
:
:
:
:
: 전체 소스코드. (CBuilder 5 의 프로젝트파일이 첨부되어있습니다.)
:
: (Unit1.h)
:
:
: //---------------------------------------------------------------------------
:
: #ifndef Unit1H
: #define Unit1H
: //---------------------------------------------------------------------------
: #include <Classes.hpp>
: #include <Controls.hpp>
: #include <StdCtrls.hpp>
: #include <Forms.hpp>
: #include <Buttons.hpp>
: //---------------------------------------------------------------------------
: class TForm1 : public TForm
: {
: __published: // IDE-managed Components
: TButton *Button1;
: TSpeedButton *SpeedButton1;
: private: // User declarations
: public: // User declarations
: __fastcall TForm1(TComponent* Owner);
: void __fastcall WMNCHitTest(TWMNCHitTest& Msg);
: protected:
: BEGIN_MESSAGE_MAP
: VCL_MESSAGE_HANDLER(WM_NCHITTEST, TWMNCHitTest, WMNCHitTest)
: END_MESSAGE_MAP(TForm)
:
: // void __fastcall WMNCHitTest(TWMNCHitTest& Msg);
:
: };
: //---------------------------------------------------------------------------
: extern PACKAGE TForm1 *Form1;
: //---------------------------------------------------------------------------
: #endif
:
:
: (Unit1.cpp)
:
:
: #include <vcl.h>
: #pragma hdrstop
:
: #include "Unit1.h"
: //---------------------------------------------------------------------------
: #pragma package(smart_init)
: #pragma resource "*.dfm"
: TForm1 *Form1;
: //---------------------------------------------------------------------------
: __fastcall TForm1::TForm1(TComponent* Owner)
: : TForm(Owner)
: {
: }
: //---------------------------------------------------------------------------
:
: /*
: void __fastcall TForm1::WMNCHitTest(TWMNCHitTest& Msg)
: {
: //Enabling this form to be dragged by clicking the client region.
: } */
:
:
:
: void __fastcall TForm1::WMNCHitTest(TWMNCHitTest& Msg)
: {
: TForm::Dispatch(&Msg);
: if( Msg.Result == HTCLIENT)
: Msg.Result = HTCAPTION;
: }
: