人老了,以前自己写的登录密码控件扎就看不懂了呢

 

LOGIN_SHOTIP,

LOGIN_KEYBORAD,

LOGIN_SHIFT,

LOGIN_PASS,

};

 

class LoginTextCtrl:public wxTextCtrl

{

public:

LoginTextCtrl(wxWindow *parent,wxWindowID id,wxString val,wxPoint pos,wxSize size,int style,wxStaticText *state)

:wxTextCtrl(parent,id,val,pos,size,style),m_lastpos(0),m_xn(0),m_x(8)

{

for(int i=0;i<10;i++)m_xnumlist[i]=0;

m_state=state;

}

~LoginTextCtrl()

{

}

public:

wxString m_pass;

int      m_lastpos;

int      m_xnumlist[10];

int      m_xn;

int      m_x;

wxStaticText *m_state;

public:

void SetValue(wxString value){

for(int i=0;i<value.length();i++){

OnKey(value[i]);

}

}

void OnKey(wxChar c){

long from,to;

GetSelection(&from,&to);

if(from!=to){

m_pass.replace(from,to-from,wxT(""));

Replace(from,to,wxT(""));

m_lastpos=from;

}

m_pass.replace(m_lastpos,0,wxString::Format(wxT("%c"),c));

Replace(m_lastpos,m_lastpos,wxT("*"));

m_lastpos++;

}

void AppendChar(wxChar c){

m_pass.Append(c);

}

void OnKeyDown(wxKeyEvent &event)

{

if(event.GetKeyCode()>=32&&event.GetKeyCode()<=126&&!(event.wxKeyEvent::AltDown()||event.ControlDown()||event.ShiftDown())){

long from,to;

GetSelection(&from,&to);

if(from!=to){

Replace(from,to,wxT(""));

if(wxGetKeyState(WXK_CAPITAL))

m_pass.replace(from,to-from,wxString::Format(wxT("%c"),event.GetKeyCode()));

else

m_pass.replace(from,to-from,wxString::Format(wxT("%c"),event.GetKeyCode()).Lower());

Replace(from,from,wxT("*"));

}else{

if(wxGetKeyState(WXK_CAPITAL))

m_pass.replace(from,to-from,wxString::Format(wxT("%c"),event.GetKeyCode()));

else

m_pass.replace(from,to-from,wxString::Format(wxT("%c"),event.GetKeyCode()).Lower());

Replace(from,to,wxT("*"));

}

m_lastpos=from+1;

m_state->SetLabel(wxString::Format(wxT("now input position %d"),m_lastpos));

return;

}else if(event.GetKeyCode()==8&&!(event.wxKeyEvent::AltDown()||event.ControlDown()||event.ShiftDown())){

long from,to;

GetSelection(&from,&to);

if(from==to){

if(to>0)

from=to-1;

}

m_pass.replace(from,to-from,wxT(""));

Replace(from,to,wxT(""));

m_lastpos=from+1;

m_state->SetLabel(wxString::Format(wxT("now input position %d"),m_lastpos-1));

return;

}else if(event.GetKeyCode()==27&&!(event.wxKeyEvent::AltDown()||event.ControlDown()||event.ShiftDown())){

Clear();

m_pass=wxT("");

m_state->SetLabel(wxString::Format(wxT("now input position %d"),1));

return;

}else if(event.GetKeyCode()==127&&!(event.wxKeyEvent::AltDown()||event.ControlDown()||event.ShiftDown())){

long from,to;

GetSelection(&from,&to);

if(from==to){

if(from<GetValue().length())

to=from+1;

}

m_pass.replace(from,to-from,wxT(""));

Replace(from,to,wxT(""));

m_lastpos=from+1;

m_state->SetLabel(wxString::Format(wxT("now input position %d"),m_lastpos-1));

return;

}else if(event.wxKeyEvent::AltDown()&&event.ControlDown()&&!event.ShiftDown()&&(event.GetKeyCode()>48&&event.GetKeyCode()<=57)){

m_x=event.GetKeyCode()-48;

}else if(event.wxKeyEvent::AltDown()&&event.ControlDown()&&event.ShiftDown()&&(event.GetKeyCode()>48&&event.GetKeyCode()<=57)){

m_xn=event.GetKeyCode()-48;

for(int i=0;i<m_xn;i++){

srand(time(NULL));

int n=rand()%m_x;;

bool hg=true;

for(int j=0;j<i;j++){

if(m_xnumlist[j]==n){

i--;

hg=false;

break;

}

}

if(hg==false)continue;

m_xnumlist[i]=n;

}

for(int i=0;i<m_xn;i++){

for(int j=i+1;j<m_xn;j++){

if(m_xnumlist[i]>m_xnumlist[j]){

int v=m_xnumlist[i];

m_xnumlist[i]=m_xnumlist[j];

m_xnumlist[j]=v;

}

}

}

for(int i=0;i<m_xn;i++){

wxSound sound;

wxString soundfile=wxString::Format(wxT("NUM%d"),m_xnumlist[i]);

sound.Create(soundfile,true);

sound.Play(wxSOUND_SYNC);

}

}

event.Skip();

}

void OnKeyUp(wxKeyEvent &event)

{

event.Skip();

}

wxString GetValue(){

wxString xpass=m_pass;

for(int i=m_xn-1;i>=0;i--){

xpass.replace(m_xnumlist[i],1,wxT(""));

}

return xpass;

}

void OnKillFocus(wxFocusEvent &event)

{

long from,to;

GetSelection(&from,&to);

m_lastpos=from;

}

DECLARE_EVENT_TABLE()

};

BEGIN_EVENT_TABLE(LoginTextCtrl,wxTextCtrl)

EVT_KEY_DOWN(LoginTextCtrl::OnKeyDown)

EVT_KEY_UP(LoginTextCtrl::OnKeyUp)

EVT_KILL_FOCUS(LoginTextCtrl::OnKillFocus)

END_EVENT_TABLE()

 

class LoginDial

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值