C++ Builder
| Главная | Уроки | Статьи | FAQ | Форум | Downloads | Литература | Ссылки | RXLib | Диски |

 
Написание компонента, Написание компонента типа TComboBox
vysotskiy
  Отправлено: 16.11.2004, 21:25


Ученик-кочегар

Группа: Участник
Сообщений: 3



Есть свой компонент на Delphi — все pаботает.
Пpи пеpеносе на CB6 возникают непонятные ошибки.
Посмотpите, ПОЖАЛУЙСТА, что я делаю не так.

DBTreeComboFIB.H
//---------------------------------------------------------------------------

#ifndef DBTreeComboFIBH
#define DBTreeComboFIBH
//---------------------------------------------------------------------------
#include
#include
#include
#include
//---------------------------------------------------------------------------
class TDBTreeView : public TTreeView
{
private:
protected:
void __fastcall CreateParams(TCreateParams &Params);
void __fastcall CreateWnd();
public:
__fastcall TDBTreeView(TComponent* Owner);
void __fastcall Show(const TRect &R);
};
//---------------------------------------------------------------------------
class PACKAGE TDBTreeComboFIB : public TCustomEdit
{
private:
TSpeedButton* FSpeedButton;
TDBTreeView* FTreeView;
protected:
void __fastcall CreateParams(TCreateParams &Params);
void __fastcall DoShowTree(void);
void __fastcall DoButtonClick(TObject* Sender);
void __fastcall WMSize(TWMSize &Message);
public:
__fastcall TDBTreeComboFIB(TComponent* Owner);
__fastcall ~TDBTreeComboFIB(void);
__published:
};
//---------------------------------------------------------------------------
extern PACKAGE void __fastcall Register(void);
#endif


DBTreeComboFIB.cpp
//---------------------------------------------------------------------------

#include

#pragma hdrstop

#include "DBTreeComboFIB.h"
#pragma package(smart_init)

//---------------------------------------------------------------------------
static inline void ValidCtrCheck(TDBTreeComboFIB *)
{
new TDBTreeComboFIB(NULL);
}
//---------------------------------------------------------------------------
namespace Dbtreecombofib
{
void __fastcall PACKAGE Register()
{
TComponentClass classes[1] = {__classid(TDBTreeComboFIB)};
RegisterComponents("My", classes, 0);
}
}

//---------------------------------------------------------------------------
// { TTreeWindow }
//---------------------------------------------------------------------------
__fastcall TDBTreeView::TDBTreeView(TComponent* Owner) : TTreeView(Owner)
{
ControlStyle = (TControlStyle() << csNoDesignVisible << csReplicatable <<
csAcceptsControls);
Visible = false;
}

//------------------------------------------------------------------------
void __fastcall TDBTreeView::CreateWnd()
{
SetParent((TWinControl *)Handle);
this->SetFocus();
// CallWindowProc((int)(__stdcall *)DefWndProc, Handle, WM_SETFOCUS, 0, 0);
}

void __fastcall TDBTreeView::CreateParams(TCreateParams &Params)
{
Params.Style = WS_POPUP | WS_BORDER | WS_CLIPCHILDREN;
Params.ExStyle = WS_EX_TOOLWINDOW;
Params.WindowClass.style = Params.WindowClass.style | CS_SAVEBITS;
}
/*
void __fastcall TDBTreeView::Hide(void)
{
SetWindowPos(Handle, 0, 0, 0, 0, 0, SWP_NOZORDER | SWP_NOMOVE | SWP_NOSIZE |
SWP_NOACTIVATE | SWP_HIDEWINDOW);
Visible = false;
}
*/
void __fastcall TDBTreeView::Show(const TRect &R)
{
Visible = true;
SetWindowPos(Handle, HWND_TOP, R.Left, R.Top, R.Right, R.Bottom, SWP_NOACTIVATE
| SWP_SHOWWINDOW);
}

//---------------------------------------------------------------------------
// { TDBTreeComboFIB }
//---------------------------------------------------------------------------
void __fastcall TDBTreeComboFIB::CreateParams(TCreateParams &Params)
{
Params.Style = Params.Style | ES_MULTILINE | WS_CLIPCHILDREN; //862
// Params.Style = WS_POPUP | WS_BORDER | WS_CLIPCHILDREN;
// Params.ExStyle = WS_EX_TOOLWINDOW;
// Params.WindowClass.style = Params.WindowClass.style | CS_SAVEBITS;
}

__fastcall TDBTreeComboFIB::TDBTreeComboFIB(TComponent* Owner) :
TCustomEdit(Owner)
{
TMenuItem *MItem;
TTreeNode *FTekNod;

FSpeedButton = new TSpeedButton(this);
FSpeedButton->Parent = this;
FSpeedButton->Top = 0;
FSpeedButton->Width = 12;
FSpeedButton->Height = this->Height;// 21;
FSpeedButton->Left = this->Left + this->Width — FSpeedButton->Width;
FSpeedButton->OnClick = DoButtonClick;

FTreeView = new TDBTreeView(this);
FTreeView->Parent = this;
if (FTreeView->Items->Count> 0) FTreeView->Items->Clear();
FTreeView->Top = this->Top + this->Height;
FTreeView->Visible = false;
}

__fastcall TDBTreeComboFIB::~TDBTreeComboFIB(void)
{
FSpeedButton->Free();
FSpeedButton = NULL;
FTreeView->Free();
FTreeView = NULL;
}

void __fastcall TDBTreeComboFIB::WMSize(TWMSize &Message)
{
if (FSpeedButton != NULL)
{
FSpeedButton->Height = Message.Height;
FSpeedButton->Left = this->Left + Message.Width — FSpeedButton->Width;
}
}

void __fastcall TDBTreeComboFIB::DoButtonClick(TObject* Sender)
{
DoShowTree();
}

void __fastcall TDBTreeComboFIB::DoShowTree(void)
{
TRect R;
TPoint P = Parent->ClientToScreen(Point(Left, Top));
R.Top = P.y + Height;
R.Left = P.x;
R.Right = this->Width;
if (FTreeView->Height> 0) R.Bottom = FTreeView->Height;
else R.Bottom = this->Width;

if ((R.Top + FTreeView->Height)> Screen->Height) R.Top = P.y -
FTreeView->Height;
if (R.Top < 0) R.Top = 0;
else
if ((R.Top + FTreeView->Height)> Screen->Height) R.Top = Screen->Height -
FTreeView->Height;

if ((R.Left + FTreeView->Width)> Screen->Width) R.Left -= (FTreeView->Width -
Width);
if (R.Left < 0) R.Left = 0;
else if ((R.Left + FTreeView->Width)> Screen->Width) R.Left = Screen->Width -
FTreeView->Width;

FTreeView->Show®;
FTreeView->SetFocus();
}


Пpимеp использования
void __fastcall TForm1::Button1Click(TObject *Sender)
{
TDBTreeComboFIB *TreeFIB = new TDBTreeComboFIB(this);
TreeFIB->Parent = Form1; // *Тут выскакивает ошибка*
TreeFIB->Name = "TreeFIB";
TreeFIB->Top = 10;
TreeFIB->Left = 10;
}
Rius
Отправлено: 18.11.2004, 16:27


Мастер участка

Группа: Участник
Сообщений: 321



А ошибка-то хоть какая?
vysotskiy
Отправлено: 19.11.2004, 20:50


Ученик-кочегар

Группа: Участник
Сообщений: 3



System Error. Code: 87.
Параметр задан неверно.

Вообще нужен компонент типа ComboBox, но при нажатии на кнопку (раскрытию списка) выпадал TreeView.
Rius
Отправлено: 20.11.2004, 10:35


Мастер участка

Группа: Участник
Сообщений: 321



Надо либо убрать функцию
CODE
void __fastcall TDBTreeComboFIB::CreateParams(TCreateParams &Params)
{
Params.Style = Params.Style | ES_MULTILINE | WS_CLIPCHILDREN; //862
// Params.Style = WS_POPUP | WS_BORDER | WS_CLIPCHILDREN;
// Params.ExStyle = WS_EX_TOOLWINDOW;
// Params.WindowClass.style = Params.WindowClass.style | CS_SAVEBITS;
}
, либо сделать так:
CODE
void __fastcall TDBTreeComboFIB::CreateParams(TCreateParams &Params)
{
TCustomEdit::CreateParams(Params);
Params.Style = Params.Style | ES_MULTILINE | WS_CLIPCHILDREN; //862
// Params.Style = WS_POPUP | WS_BORDER | WS_CLIPCHILDREN;
// Params.ExStyle = WS_EX_TOOLWINDOW;
// Params.WindowClass.style = Params.WindowClass.style | CS_SAVEBITS;
}

С этой функцией не работал, так что точнее сказать не могу.
vysotskiy
Отправлено: 20.11.2004, 19:31


Ученик-кочегар

Группа: Участник
Сообщений: 3



Спасибо! Заработало.
Где бы почитать о создании компонентов на CBuilder.
А если б еще и в электронном виде.
Rius
Отправлено: 20.11.2004, 19:52


Мастер участка

Группа: Участник
Сообщений: 321



Посмотри здесь: http://www.progz.ru/forum/viewtopic.php?t=11128

Отредактировано Rius — 20/11/2004, 22:57

Вернуться в Вопросы программирования в C++Builder