BorlandTalk.com Forum Index BorlandTalk.com
Borland discussion newsgroups
 
Archives   FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Deriving TComboBox ...

 
Post new topic   Reply to topic    BorlandTalk.com Forum Index -> C++ Builder (VCL Components Development)
View previous topic :: View next topic  
Author Message
Matrix
Guest





PostPosted: Wed Jul 28, 2004 6:11 am    Post subject: Deriving TComboBox ... Reply with quote




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
Display posts from previous:   
Post new topic   Reply to topic    BorlandTalk.com Forum Index -> C++ Builder (VCL Components Development) All times are GMT
Page 1 of 1

 
Jump to:  
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


Powered by phpBB © 2001, 2006 phpBB Group
SEO toolkit © 2004-2006 webmedic.