-
Posts
10 -
Cadastrado em
-
Última visita
Tópicos solucionados
-
O post de _FBO_ em Callback em C++ como no delphi foi marcado como solução
Deu certo, muito obrigado pela sua ajuda e paciência.
Segue o codigo funcionando:
//Edit1.h class Edit; typedef void (*TNotifyEvent)(Edit* sender); typedef void (*TOnKeyPress )(Edit* sender, char Key); class Edit{ private: char lastKey; string buff; public: Edit(); virtual ~Edit(); void CheckKeys(); string text; TOnKeyPress OnKeyPress; TNotifyEvent OnEditingDone; }; //Edit.cpp #include "Edit.h" Edit::Edit() { text.clear(); buff.clear(); lastKey= '\0'; OnKeyPress = NULL; OnEditingDone = NULL; } Edit::~Edit() { } void Edit::CheckKeys() { if((GetAsyncKeyState(48) < 0)&&(lastKey != '0')){ buff+= '0'; lastKey= '0'; } if((GetAsyncKeyState(49) < 0)&&(lastKey != '1')){ buff+= '1'; lastKey= '1'; } if((GetAsyncKeyState(50) < 0)&&(lastKey != '2')){ buff+= '2'; lastKey= '2'; } if((GetAsyncKeyState(51) < 0)&&(lastKey != '3')){ buff+= '3'; lastKey= '3'; } if((GetAsyncKeyState(52) < 0)&&(lastKey != '4')){ buff+= '4'; lastKey= '4'; } if((GetAsyncKeyState(53) < 0)&&(lastKey != '5')){ buff+= '5'; lastKey= '5'; } if((GetAsyncKeyState(54) < 0)&&(lastKey != '6')){ buff+= '6'; lastKey= '6'; } if((GetAsyncKeyState(55) < 0)&&(lastKey != '7')){ buff+= '7'; lastKey= '7'; } if((GetAsyncKeyState(56) < 0)&&(lastKey != '8')){ buff+= '8'; lastKey= '8'; } if((GetAsyncKeyState(57) < 0)&&(lastKey != '9')){ buff+= '9'; lastKey= '9'; } if(GetAsyncKeyState(13) < 0) { lastKey = '\0'; text = buff; buff.clear(); if(this->OnEditingDone != NULL) { this->OnEditingDone(this); } } else { if(this->OnKeyPress != NULL) { this->OnKeyPress(this, lastKey); } } } //Main.cpp #include "Edit.h" #include <stdio.h> #include <windows.h> using namespace std; Edit* edit1; void Edit1_OnKeyPress(Edit* Sender, char Key) { printf("OnKeyPress chamado: %c", Key); } void Edit1_OnEditingDone(Edit* Sender) { printf("OnEditingDone chamado: %s", Sender->text); } int main() { edit1 = new Edit; edit1->OnKeyPress = Edit1_OnKeyPress; edit1->OnEditingDone = Edit1_OnEditingDone; while(1) { edit1->CheckKeys(); } delete edit1; return 0; }
Sobre o Clube do Hardware
No ar desde 1996, o Clube do Hardware é uma das maiores, mais antigas e mais respeitadas comunidades sobre tecnologia do Brasil. Leia mais
Direitos autorais
Não permitimos a cópia ou reprodução do conteúdo do nosso site, fórum, newsletters e redes sociais, mesmo citando-se a fonte. Leia mais