试度把那按钮的区域用相同标题栏的颜色盖住
我没试过
只试过在标题栏画按钮(BCB的),看看吧 可能有用//---------------------------------------------------------------------------#include <vcl.h>
#pragma hdrstop#include "Unit2.h"
#include "Unit3.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma link "Trayicon"
#pragma resource "*.dfm"
TForm1 *Form1;
//---------------------------------------------------------------------------
__fastcall TForm1::TForm1(TComponent* Owner)
: TForm(Owner)
{
WindowCanvas = new TCanvas;
// this code determines if we are running on NT3.X
TOSVersionInfo ver;
ver.dwOSVersionInfoSize = sizeof(TOSVersionInfo);
GetVersionEx( &ver);
if(ver.dwMajorVersion < 4)
{
/* if the OS is NT 3.5, the custom caption won't be drawn
use the Caption property as usual, since the custom
caption won't be able to draw the string.
*/
IsNT35 = true;
}
else
IsNT35 = false ;
Caption="9x9=81 ?";
}
//---------------------------------------------------------------------------void __fastcall TForm1::WMNCActivate(TWMNCActivate &Msg)
{
Msg.Result = true; // always handle this message;
if ((bool)Msg.Active == false) // if non-active draw default
{ // non-active title bar // add code here to draw caption when window is inactive.
// in this example, we leave the inactive caption alone. DefWindowProc( Handle, Msg.Msg, Msg.Active, 0 );
return;
}
TMessage PaintMsg; // if active, do same thing as WMNCPaint
PaintMsg.Msg = Msg.Msg; // create a MSG to pass to WMNCPaint and
PaintMsg.WParam = Msg.Active; // call the function directly so painting WMNCPaint(PaintMsg); // happens now.}
//---------------------------------------------------------------------------void __fastcall TForm1::WMNCPaint(TMessage &Msg)
{
CaptionRect1 = new TRect;
CaptionRect2 = new TRect;
// use default processing to draw min/max/close buttons, menu, and the
// frame. the caption bar is drawn too, but we paint over that later. DefWindowProc(Handle, Msg.Msg,Msg.WParam,Msg.LParam);
// create a DC for the entire window, then assign
// the handle to the window canvas
HDC WindowDC = GetWindowDC(Handle);
WindowCanvas->Handle = WindowDC; SetRect(CaptionRect1 , this->Width-29 , 6 , this->Width-19 , 16);
SetRect(CaptionRect2 , this->Width-41 , 6 , this->Width-30 , 16); DrawFrameControl( WindowDC , CaptionRect1 , DFC_CAPTION , 1 );
DrawFrameControl( WindowDC , CaptionRect2 , 0 , 1 ); ReleaseDC(Handle, WindowDC); // free resources
WindowCanvas->Handle = NULL ;
}//--------------------------------------------------------------------------__fastcall TForm1::~TForm1(void)
{
delete WindowCanvas;
WindowCanvas = NULL ;
}//--------------------------------------------------------------------------void __fastcall TForm1::FormResize(TObject *Sender)
{
Perform(WM_NCPAINT,1,0); //not write this Event will happed question!
}//---------------------------------------------------------------------------void __fastcall TForm1::WndProc(TMessage &Msg)
{ switch ( Msg.Msg )
{
case WM_NCLBUTTONDOWN :
{
POINT *p = new POINT;
GetCursorPos( p );
Canvas->Handle = GetWindowDC( Handle ); if ( PtInRect ( CaptionRect1 , Point ( p->x - Left, p->y - Top )))
{
Label1->Caption=Msg.Msg;//.HitTest ;
//WindowState = wsMinimized;
} if ( PtInRect ( CaptionRect2 , Point ( p->x - Left, p->y - Top )))
{
PopupMenu1->Popup(p->x,p->y);
}
}
break; case WM_NCMOUSEMOVE :
{
POINT *p = new POINT;
GetCursorPos( p );
Canvas->Handle = GetWindowDC( Handle ); if ( PtInRect ( CaptionRect1 , Point ( p->x - Left, p->y - Top )))
{
Label2->Caption=Msg.Msg+2;//.HitTest ; } if ( PtInRect ( CaptionRect2 , Point ( p->x - Left, p->y - Top )))
{
Label2->Caption=Msg.WParam+5;//.HitTest ;
} }
break; case WM_NCLBUTTONUP :
{
POINT *p = new POINT;
GetCursorPos( p );
Canvas->Handle = GetWindowDC( Handle ); if ( PtInRect ( CaptionRect1 , Point ( p->x - Left, p->y - Top )))
{
WindowState = wsMinimized;
}
}
break; default : Msg.Result=false ;
}
TForm::WndProc(Msg);
}//----------------------------------------------------------------+++++++++++++++++++++++++++++++++++++++++++++++++.h//---------------------------------------------------------------------------#ifndef Unit2H
#define Unit2H
//---------------------------------------------------------------------------
#include <Classes.hpp>
#include <Controls.hpp>
#include <StdCtrls.hpp>
#include <Forms.hpp>
#include <ExtCtrls.hpp>
#include <Menus.hpp>
#include "Trayicon.h"
//---------------------------------------------------------------------------
class TForm1 : public TForm
{
__published: // IDE-managed Components
TLabel *Label1;
TLabel *Label2;
TPopupMenu *PopupMenu1;
TMenuItem *A1;
TMenuItem *B1;
TTrayIcon *TrayIcon1;
void __fastcall FormResize(TObject *Sender);
void __fastcall FormCreate(TObject *Sender);
private: // User declarations TCanvas *WindowCanvas;
bool IsNT35;
TRect *CaptionRect1 , *CaptionRect2;
void __fastcall WMNCPaint( TMessage &Msg );
void __fastcall WMNCActivate( TWMNCActivate &Msg );
//void __fastcall On_ButtonDown( TWMNCLButtonDown &Msg ) ;
//void __fastcall On_MouseMove( TWMNCMouseMove &Msg );
//void __fastcall OnNcHitTest(TMessage &Message);
void __fastcall WndProc(TMessage &Msg);public: // User declarations BEGIN_MESSAGE_MAP
MESSAGE_HANDLER( WM_NCPAINT , TMessage , WMNCPaint )
MESSAGE_HANDLER( WM_NCACTIVATE , TWMNCActivate , WMNCActivate )
//MESSAGE_HANDLER( WM_NCLBUTTONDOWN , TWMNCLButtonDown , On_ButtonDown )
//MESSAGE_HANDLER( WM_NCMOUSEMOVE , TWMNCMouseMove , On_MouseMove )
//MESSAGE_HANDLER( WM_NCHITTEST , TMessage , OnNcHitTest )
END_MESSAGE_MAP( TForm )
__fastcall ~TForm1( void );
__fastcall TForm1( TComponent* Owner );
};
//---------------------------------------------------------------------------
extern PACKAGE TForm1 *Form1;
//---------------------------------------------------------------------------
#endif
我没试过
只试过在标题栏画按钮(BCB的),看看吧 可能有用//---------------------------------------------------------------------------#include <vcl.h>
#pragma hdrstop#include "Unit2.h"
#include "Unit3.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma link "Trayicon"
#pragma resource "*.dfm"
TForm1 *Form1;
//---------------------------------------------------------------------------
__fastcall TForm1::TForm1(TComponent* Owner)
: TForm(Owner)
{
WindowCanvas = new TCanvas;
// this code determines if we are running on NT3.X
TOSVersionInfo ver;
ver.dwOSVersionInfoSize = sizeof(TOSVersionInfo);
GetVersionEx( &ver);
if(ver.dwMajorVersion < 4)
{
/* if the OS is NT 3.5, the custom caption won't be drawn
use the Caption property as usual, since the custom
caption won't be able to draw the string.
*/
IsNT35 = true;
}
else
IsNT35 = false ;
Caption="9x9=81 ?";
}
//---------------------------------------------------------------------------void __fastcall TForm1::WMNCActivate(TWMNCActivate &Msg)
{
Msg.Result = true; // always handle this message;
if ((bool)Msg.Active == false) // if non-active draw default
{ // non-active title bar // add code here to draw caption when window is inactive.
// in this example, we leave the inactive caption alone. DefWindowProc( Handle, Msg.Msg, Msg.Active, 0 );
return;
}
TMessage PaintMsg; // if active, do same thing as WMNCPaint
PaintMsg.Msg = Msg.Msg; // create a MSG to pass to WMNCPaint and
PaintMsg.WParam = Msg.Active; // call the function directly so painting WMNCPaint(PaintMsg); // happens now.}
//---------------------------------------------------------------------------void __fastcall TForm1::WMNCPaint(TMessage &Msg)
{
CaptionRect1 = new TRect;
CaptionRect2 = new TRect;
// use default processing to draw min/max/close buttons, menu, and the
// frame. the caption bar is drawn too, but we paint over that later. DefWindowProc(Handle, Msg.Msg,Msg.WParam,Msg.LParam);
// create a DC for the entire window, then assign
// the handle to the window canvas
HDC WindowDC = GetWindowDC(Handle);
WindowCanvas->Handle = WindowDC; SetRect(CaptionRect1 , this->Width-29 , 6 , this->Width-19 , 16);
SetRect(CaptionRect2 , this->Width-41 , 6 , this->Width-30 , 16); DrawFrameControl( WindowDC , CaptionRect1 , DFC_CAPTION , 1 );
DrawFrameControl( WindowDC , CaptionRect2 , 0 , 1 ); ReleaseDC(Handle, WindowDC); // free resources
WindowCanvas->Handle = NULL ;
}//--------------------------------------------------------------------------__fastcall TForm1::~TForm1(void)
{
delete WindowCanvas;
WindowCanvas = NULL ;
}//--------------------------------------------------------------------------void __fastcall TForm1::FormResize(TObject *Sender)
{
Perform(WM_NCPAINT,1,0); //not write this Event will happed question!
}//---------------------------------------------------------------------------void __fastcall TForm1::WndProc(TMessage &Msg)
{ switch ( Msg.Msg )
{
case WM_NCLBUTTONDOWN :
{
POINT *p = new POINT;
GetCursorPos( p );
Canvas->Handle = GetWindowDC( Handle ); if ( PtInRect ( CaptionRect1 , Point ( p->x - Left, p->y - Top )))
{
Label1->Caption=Msg.Msg;//.HitTest ;
//WindowState = wsMinimized;
} if ( PtInRect ( CaptionRect2 , Point ( p->x - Left, p->y - Top )))
{
PopupMenu1->Popup(p->x,p->y);
}
}
break; case WM_NCMOUSEMOVE :
{
POINT *p = new POINT;
GetCursorPos( p );
Canvas->Handle = GetWindowDC( Handle ); if ( PtInRect ( CaptionRect1 , Point ( p->x - Left, p->y - Top )))
{
Label2->Caption=Msg.Msg+2;//.HitTest ; } if ( PtInRect ( CaptionRect2 , Point ( p->x - Left, p->y - Top )))
{
Label2->Caption=Msg.WParam+5;//.HitTest ;
} }
break; case WM_NCLBUTTONUP :
{
POINT *p = new POINT;
GetCursorPos( p );
Canvas->Handle = GetWindowDC( Handle ); if ( PtInRect ( CaptionRect1 , Point ( p->x - Left, p->y - Top )))
{
WindowState = wsMinimized;
}
}
break; default : Msg.Result=false ;
}
TForm::WndProc(Msg);
}//----------------------------------------------------------------+++++++++++++++++++++++++++++++++++++++++++++++++.h//---------------------------------------------------------------------------#ifndef Unit2H
#define Unit2H
//---------------------------------------------------------------------------
#include <Classes.hpp>
#include <Controls.hpp>
#include <StdCtrls.hpp>
#include <Forms.hpp>
#include <ExtCtrls.hpp>
#include <Menus.hpp>
#include "Trayicon.h"
//---------------------------------------------------------------------------
class TForm1 : public TForm
{
__published: // IDE-managed Components
TLabel *Label1;
TLabel *Label2;
TPopupMenu *PopupMenu1;
TMenuItem *A1;
TMenuItem *B1;
TTrayIcon *TrayIcon1;
void __fastcall FormResize(TObject *Sender);
void __fastcall FormCreate(TObject *Sender);
private: // User declarations TCanvas *WindowCanvas;
bool IsNT35;
TRect *CaptionRect1 , *CaptionRect2;
void __fastcall WMNCPaint( TMessage &Msg );
void __fastcall WMNCActivate( TWMNCActivate &Msg );
//void __fastcall On_ButtonDown( TWMNCLButtonDown &Msg ) ;
//void __fastcall On_MouseMove( TWMNCMouseMove &Msg );
//void __fastcall OnNcHitTest(TMessage &Message);
void __fastcall WndProc(TMessage &Msg);public: // User declarations BEGIN_MESSAGE_MAP
MESSAGE_HANDLER( WM_NCPAINT , TMessage , WMNCPaint )
MESSAGE_HANDLER( WM_NCACTIVATE , TWMNCActivate , WMNCActivate )
//MESSAGE_HANDLER( WM_NCLBUTTONDOWN , TWMNCLButtonDown , On_ButtonDown )
//MESSAGE_HANDLER( WM_NCMOUSEMOVE , TWMNCMouseMove , On_MouseMove )
//MESSAGE_HANDLER( WM_NCHITTEST , TMessage , OnNcHitTest )
END_MESSAGE_MAP( TForm )
__fastcall ~TForm1( void );
__fastcall TForm1( TComponent* Owner );
};
//---------------------------------------------------------------------------
extern PACKAGE TForm1 *Form1;
//---------------------------------------------------------------------------
#endif
解决方案 »
- 最近很郁闷,和一个客户争吵起来了(路过进)
- 如何得到 vfp应用程序form上的文本框中的内容
- -------------如何检测windows服务的状态----------------------
- 如何用locate搜索两个字段
- 已得到接口指针,如何通过接口指针得到接口GUID
- 关于用SQL备份数据库
- 几个有关delphi的问题
- rave中如何在打印之前(打印预览中的实际打印)显示自定义的提示?
- 求救啊!
- 如何避免Edit的onchange事件触发2次
- 100分的期待( 分数在VB版中)--请问如何打开IE6的Cookie(是手工打开,不是程序实现),有些网页访问时提示:Cookie Required.
- 有没人搞过swFlash.ocx的,进来指教一下。
Delphi5以下的版本应该也可以吧。我现在这里只有Delphi6.
如果在运行的时候改变,就好象要写些代码重载窗体。
。在程序中动态设定按钮只会变灰,要重载一下窗体