c++ builder 的Tarckbar控件没有mousedown和mouseup事件。请问怎么样来截取Tarckbar控件的上述消息。然后写自己的处理代码。

pp616 2001-07-16 09:37:51
...全文
317 20 打赏 收藏 转发到动态 举报
写回复
用AI写文章
20 条回复
切换为时间正序
请发表友善的回复…
发表回复
sincostan 2001-07-20
  • 打赏
  • 举报
回复
如果不用Shift,Button参数则看不出来。

sincostan 2001-07-20
  • 打赏
  • 举报
回复
重要声明(本人犯的一个错误)

所写的TMyTrackBar源码虽然能工作,但又测试了一下有个问题.

源码:
void __fastcall TMyTrackBar::WndProc(TMessage &Message)
{ TTrackBar::WndProc(Message);
if (Message.Msg == WM_LBUTTONDOWN)
{ int xPos = Message.LParamLo; //对的
int yPos = Message.LParamHi; //对的
TShiftState Shift ;//改正.应该必须赋值
TMouseButton Button;//改正.应该必须赋值
DoMouseDown( Button , Shift,xPos,yPos);
}

if (Message.Msg == WM_LBUTTONUP)
{ int xPos = Message.LParamLo;
int yPos = Message.LParamHi;
TShiftState Shift ;//改正.应该必须赋值
TMouseButton Button;//改正.应该必须赋值
DoMouseUp( Button , Shift,xPos,yPos);
}
}
但具体怎么赋值,我不清楚,望指点
pp616 2001-07-19
  • 打赏
  • 举报
回复
to: sincostan
你的程序我已通过了调试。谢谢你。
即可送上150分。
sincostan 2001-07-19
  • 打赏
  • 举报
回复
头文件
//---------------------------------------------------------------------------

#ifndef MyTrackBarH
#define MyTrackBarH
//---------------------------------------------------------------------------
#include <SysUtils.hpp>
#include <Controls.hpp>
#include <Classes.hpp>
#include <Forms.hpp>
#include <ComCtrls.hpp>
//---------------------------------------------------------------------------
class PACKAGE TMyTrackBar : public TTrackBar
{
private:
TMouseEvent FOnMouseDown;
TMouseEvent FOnMouseUp;

protected:
virtual void __fastcall DoMouseDown( TMouseButton Button,
Classes::TShiftState Shift, int X, int Y);

virtual void __fastcall DoMouseUp( TMouseButton Button,
Classes::TShiftState Shift, int X, int Y);

void __fastcall WndProc(TMessage &Message); //重载窗口过程

public:
__fastcall TMyTrackBar(TComponent* Owner);
__published:
__property TMouseEvent myOnMouseDown={read=FOnMouseDown,write=FOnMouseDown};
__property TMouseEvent myOnMouseUp={read=FOnMouseUp,write=FOnMouseUp};


};
//---------------------------------------------------------------------------
#endif
***************** 实现文件 ***********************
//---------------------------------------------------------------------------

#include <vcl.h>
#pragma hdrstop

#include "MyTrackBar.h"
#pragma package(smart_init)
//---------------------------------------------------------------------------
// ValidCtrCheck is used to assure that the components created do not have
// any pure virtual functions.
//

static inline void ValidCtrCheck(TMyTrackBar *)
{
new TMyTrackBar(NULL);
}
//========
void __fastcall TMyTrackBar::DoMouseDown( TMouseButton Button,
Classes::TShiftState Shift, int X, int Y)
{
if (FOnMouseDown) FOnMouseDown(this,Button,Shift,X,Y);
}
//========
void __fastcall TMyTrackBar::DoMouseUp( TMouseButton Button,
Classes::TShiftState Shift, int X, int Y)
{
if (FOnMouseUp) FOnMouseUp(this,Button,Shift,X,Y);
}
//=========
void __fastcall TMyTrackBar::WndProc(TMessage &Message)
{ TTrackBar::WndProc(Message);
if (Message.Msg == WM_LBUTTONDOWN)
{ int xPos = Message.LParamLo;
int yPos = Message.LParamHi;
TShiftState Shift ;//=(TShiftState) Message.WParam;
TMouseButton Button;
DoMouseDown( Button , Shift,xPos,yPos);
}

if (Message.Msg == WM_LBUTTONUP)
{ int xPos = Message.LParamLo;
int yPos = Message.LParamHi;
TShiftState Shift ;//=(TShiftState) Message.WParam;
TMouseButton Button;
DoMouseUp( Button , Shift,xPos,yPos);
}


}
//==========
//---------------------------------------------------------------------------
__fastcall TMyTrackBar::TMyTrackBar(TComponent* Owner)
: TTrackBar(Owner)
{
}
//---------------------------------------------------------------------------
namespace Mytrackbar
{
void __fastcall PACKAGE Register()
{
TComponentClass classes[1] = {__classid(TMyTrackBar)};
RegisterComponents("AddBlank", classes, 0);
}
}
//---------------------------------------------------------------------------


sincostan 2001-07-19
  • 打赏
  • 举报
回复
问题解决了
我测试了可以,不过不知你是否知道如何安装控件 Component-->Install Component->
按Browse按钮找到 MyTrackBar.cpp 这个单元文件。装完后在组件栏出现一个新页AddBlank (纯粹个人安排问题,不必理会,你也完全可把它添加在Samples一项)
(我的测试程序在你的机子上有可能不行,属于配置问题,你可重建)
Chxis 2001-07-19
  • 打赏
  • 举报
回复
选ApplicationEvents控件
在OnMessage里写上:

procedure TForm1.ApplicationEvents1Message(var Msg: tagMSG;
var Handled: Boolean);
begin
if Msg.hwnd=TrackBar1.Handle then
begin
if Msg.message=WM_LBUTTONDOWN then //do ur like
if Msg.message=WM_LBUTTONUP then //do ur like
end;
end;



对不起,没CB所以请你自己来吧,其实就是截取form的消息,
再比较与trackbar是否一样,然后就判断键有否按下...
wjzhuang 2001-07-19
  • 打赏
  • 举报
回复
哦~~~~~~~
和尚,i see
路人丁 2001-07-19
  • 打赏
  • 举报
回复
关注!
sincostan 2001-07-18
  • 打赏
  • 举报
回复
有空时尽快写写试试如果能行就发给你
sw0324 2001-07-17
  • 打赏
  • 举报
回复
gz
pp616 2001-07-17
  • 打赏
  • 举报
回复
我的信箱:zmzpp@sohu.com
pp616 2001-07-17
  • 打赏
  • 举报
回复
能发个示例程序给我看看吗?你们所说的我都照做过了。可以程序一运行就出错了。
我是个入门者。发段示例代码个我学习学习吧。收到代码立刻加分。
wjzhuang 2001-07-17
  • 打赏
  • 举报
回复
Tarckbar是什么呀?
pp616 2001-07-17
  • 打赏
  • 举报
回复
150分了。还没有人愿意写段代码给我吗?
sincostan 2001-07-17
  • 打赏
  • 举报
回复
代理出毛病了,重发了
sincostan 2001-07-17
  • 打赏
  • 举报
回复
添加个事件属性就可了
(自定义控件的问题)
class TmyTarckbar: public Tarckbar
{
private:
TMouseEvent FO nMouseDown;
protected:
virtual void __fastcall DoMouseEvent( );
void __fastcall WndProc(TMessage &Message) //重载窗口过程
__published:
__property TMouseEvent OnMouseDown={read=FOnMouseDown,write=FOnMOuseDown};
...
}

void TmyTarckbar::DoMOuseEvent( ?){
if(FOnMouseDown) FOnMOuseDown() ;} //搞不太清参数怎么添,望见谅
void __fastcall TmyTarckbar::WndProc(TMessage &Message)
{ TTarckbar::WndProc(Message); //基类的
if(Message.Msg == WM_LBUTTONDOWN) // WM_LBUTTONUP
{
DoMouseEvent( ? )
}
}



sincostan 2001-07-17
  • 打赏
  • 举报
回复
添加个事件属性就可了
(自定义控件的问题)
class TmyTarckbar: public Tarckbar
{
private:
TMouseEvent FO nMouseDown;
protected:
virtual void __fastcall DoMouseEvent( );
void __fastcall WndProc(TMessage &Message) //重载窗口过程
__published:
__property TMouseEvent OnMouseDown={read=FOnMouseDown,write=FOnMOuseDown};
...
}

void TmyTarckbar::DoMOuseEvent( ?){
if(FOnMouseDown) FOnMOuseDown() ;} //搞不太清参数怎么添,望见谅
void __fastcall TmyTarckbar::WndProc(TMessage &Message)
{ TTarckbar::WndProc(Message); //基类的
if(Message.Msg == WM_LBUTTONDOWN) // WM_LBUTTONUP
{
DoMouseEvent( ? )
}
}



xycleo 2001-07-17
  • 打赏
  • 举报
回复
老猪!!!就是那个win32里的最不起眼的拉条!!!
xycleo 2001-07-17
  • 打赏
  • 举报
回复
在OnChange事件中写就可以啦1!!
luhongjun 2001-07-16
  • 打赏
  • 举报
回复
Tarckbar是什么呀?

13,865

社区成员

发帖
与我相关
我的任务
社区描述
C++ Builder相关内容讨论区
社区管理员
  • 基础类社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧