 |
BorlandTalk.com Borland discussion newsgroups
|
| View previous topic :: View next topic |
| Author |
Message |
Matrix Guest
|
Posted: Wed Jul 28, 2004 6:11 am Post subject: Deriving TComboBox ... |
|
|
Hi, I'm trying to create a new component deriving from TComboBox...the only thing I want it does is:
1) the control background color must become yellow when it receives focus
2) the control background color must become white when it receives focus
This is my actual code:
static inline void ValidCtrCheck(TPComboBox *)
{
new TPComboBox(NULL);
}
//========== COSTRUTTORI ===================
__fastcall TPComboBox::TPComboBox(TComponent* Owner)
: TComboBox(Owner)
{
InitClassVariables();
// Intercetto i messaggi Windows nel metodo SubClassWndProc
WindowProc = SubClassWndProc;
}
//========== DISTRUTTORE ===================
__fastcall TPComboBox::~TPComboBox(void)
{
}
//=============== FUNZIONI PRIVATE ====================
void __fastcall TPComboBox::SubClassWndProc(Messages::TMessage &Message)
{
switch (Message.Msg)
{
case WM_SETFOCUS:
HandlerMessage_WM_SETFOCUS(Message);
break;
case WM_KILLFOCUS:
HandlerMessage_WM_KILLFOCUS(Message);
break;
case WM_CHAR:
HandlerMessage_WM_CHAR(Message);
break;
default:
inherited::WndProc(Message);
break;
}
}
void __fastcall TPComboBox::HandlerMessage_WM_SETFOCUS(TMessage &Message)
{
assert(Message.Msg == WM_SETFOCUS);
if (Message.Msg != WM_SETFOCUS) return;
inherited::WndProc(Message);
this->Color = this->m_SetFocusColor;
}
void __fastcall TPComboBox::HandlerMessage_WM_KILLFOCUS(TMessage &Message)
{
assert(Message.Msg == WM_KILLFOCUS);
if (Message.Msg != WM_KILLFOCUS) return;
inherited::WndProc(Message);
this->Color = this->m_KillFocusColor;
}
void __fastcall TPComboBox::HandlerMessage_WM_CHAR(TMessage &Message)
{
assert(Message.Msg == WM_CHAR);
if (Message.Msg != WM_CHAR) return;
if ((this->Style == csDropDownList) && (this->m_AutoComplete))
{
char cChar = Message.WParam;
int iItemIndex = CB_ERR;
this->m_sPartialStringToSearch += AnsiString(cChar);
iItemIndex = SendMessage(this->Handle,
CB_FINDSTRING,
-1,
(LPARAM)this->m_sPartialStringToSearch.c_str());
if (iItemIndex == CB_ERR)
{
this->m_sPartialStringToSearch = AnsiString(cChar);
iItemIndex = SendMessage(this->Handle,
CB_FINDSTRING,
-1,
(LPARAM)this->m_sPartialStringToSearch.c_str());
}
if (iItemIndex != CB_ERR)
{
int iCurrentItemIndex = this->ItemIndex;
this->ItemIndex = iItemIndex;
// Devo scatenare l'evento DOPO che l'item e' cambiato
// (comportamento STANDARD delle ComboBox)
if (iCurrentItemIndex != iItemIndex)
{
DoChange();
}
}
}
else
{
this->m_sPartialStringToSearch = "";
// Comportamento Standard
inherited::WndProc(Message);
}
}
//=============== ALTRE FUNZIONI ====================
void __fastcall TPComboBox::InitClassVariables(void)
{
this->m_SetFocusColor = clYellow;
this->m_KillFocusColor = clWindow;
}
void __fastcall TPComboBox::SetAutoComplete(bool Value)
{
this->m_AutoComplete = Value;
if (!this->m_AutoComplete)
{
this->m_sPartialStringToSearch = "";
}
else
{
}
}
//=============== FUNZIONI PROTETTE ====================
void __fastcall TPComboBox::DoChange(void)
{
if (this->OnChange) this->OnChange(this);
}
I've got a problem when the combo receives the focus: both the messages WM_SETFOCUS and WM_KILLFOCUS are sent to the component.
If I set the style of the Combo as DropDownList the behaviour is right (yellow when it gets focus, window when it losts it).
Any advice???
TIA.
|
|
| Back to top |
|
 |
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
|