Houve um evento aqui WebCheats com alguns desafios, participei e deixo a source aberta aqui no fórum para possíveis estudos:
Login: Admin
Senha: Livros
Download Projeto: Mega
Scan do arquivo: VirusTotal
Caso tenha preguiça de baixar e abrir no notepad:
/*@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
@@@@@@@@@@@@@@80GGGGGGG0GGG0GGGGGGG08@@@@@@@@@@@@@
@@@@@@@@@@@80GGGGG1. ,tGGGGG0@@@@@@@@@@@
@@@@@@@@@8GGGGL. ,CGGG0@@@@@@@@@
@@@@@@@@0GGG; 1GGG0@@@@@@@
@@@@@@@GGGt LGG0@@@@@@
@@@@@@GGG: iGGG@@@@@
@@@@@GGG, ........ .,::, ;GG0@@@@
@@@@0CC; ::::::::::::. :::::::::. 1CC8@@@
@@@@00f :::::::::::::: :::::::::::. .L08@@@
@@@@GG ::::, .::::, .::::. ,::::. ;00@@@
@@@@G; .;;::, ::::: .::::.:::;;: fG@@@
@@@@C .;;;;, ,;;;;: .;;;;,:;;, :0@@@
@@@@G: .;;;;,:;;;;;;;: .;;;;, ,8@@@
@@@@@ff. .;;;;,:;;;;;;. .;;;;, .fL@@@@
@@@@@8tt, ,,,,..,,. ,,,,. ;tt@@@@@
@@@@@@811: ;1t@@@@@@
@@@@@@@@tii .iiL@@@@@@@
@@@@@@@@@0ii; .;i18@@@@@@@@
@@@@@@@@@@@01;;: :;;t8@@@@@@@@@@
@@@@@@@@@@@@@@0t;;;:, .,:;;;f8@@@@@@@@@@@@@
@@@@@@@@@@@@@@@@@@8Cfi;;;;;;;1LG@@@@@@@@@@@@@@@@@@
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@*/
program WC_BIBLIOTECA;
uses
Windows,Messages,XPMan,StrUtils,SysUtils;
//* Definição de um novo tipo de dado *//
type
INFOBOOKS = record
Nome: string;
Autor: string;
Genero: string;
Corredor, Prateleira, xPesquisas: Integer;
end;
{$R recurso.res}
var
//* Classe Principal da Janela e mensagem*//
winClass: TWndClassA;
Msg: TMsg;
//* Handles da janela de login e seus componentes *//
window, ButtonLogin, EditLogin, EditPass,LabelL,LabelP: THandle;
//* Handles da janela de pesquisa e seus componentes *//
window2, ButtonSearch, EditSearch, ListBox, LabelS, LabelI, LabelxS, ComboBox:THandle;
LabelTop3: THandle;
//*Variáveis para fins funcionais e estéticos*//
hFont: Integer;
id: array[1..10] of Integer;
idCount: Integer;
tLab: HDC;
r: TRect;
eraseBrush: HBRUSH;
buff, buff2:array[0..255] of Char;
nTemp, iTemp, totalSearch: Integer;
//* Definição dos livros e seus dados *//
Livro : array [1..10] of INFOBOOKS = (
(Nome:'Lava Jato'; Autor:'Vladimir Neto'; Genero:'Primeira Pessoa e Não Ficção';Corredor:1;Prateleira:1;xPesquisas:0),
(Nome:'O diario de Larissa Manuela'; Autor:'Larissa Manoela'; Genero:'Infanto Juvenil'; Corredor:2;Prateleira:2;xPesquisas:0),
(Nome:'Quem me roubou de mim'; Autor:'Fabio de Melo'; Genero:'Auto Ajuda'; Corredor:1;Prateleira:2;xPesquisas:0),
(Nome:'Não fale com estranhos'; Autor:'Harlan Coben'; Genero:'Ficção'; Corredor:2;Prateleira:1;xPesquisas:0),
(Nome:'A Guerra dos Tronos'; Autor:'George R. R. Martin';Genero:'Ficção'; Corredor:3;Prateleira:1;xPesquisas:0),
(Nome:'Filosofia para Corajosos'; Autor:'Luiz Felipe Pondé'; Genero:'Não Ficção'; Corredor:1;Prateleira:3;xPesquisas:0),
(Nome:'Muito mais que 5inco Minutos'; Autor:'Kefera Buchmann'; Genero:'Infanto Juvenil'; Corredor:4;Prateleira:1;xPesquisas:0),
(Nome:'De volta ao jogo'; Autor:'Rezendeevil'; Genero:'Infanto Juvenil'; Corredor:1;Prateleira:4;xPesquisas:0),
(Nome:'Harry Potter e a Ordem da Fênix';Autor:'J.K. Rowling'; Genero:'Fantasia'; Corredor:5;Prateleira:1;xPesquisas:0),
(Nome:'O Código da Vinci'; Autor:'Dan Brown'; Genero:'Ficção'; Corredor:1;Prateleira:5;xPesquisas:0)
);
const
//* Definição de uma constante para simular o "pulo de linha" facilitando o uso no decorrer da programação *//
lB = AnsiString(#13#10);
//* Função para atualizar a listagem dos livros de forma decrescente, mantendo os mais pesquisados no topo *//
procedure AttTop3();
var
bN, bA, bG: string;
i, Count, bC,bP,bxP: Integer;
begin
for i:=1 to 10 do
begin
for Count:=1 to 10 do
begin
if Livro[i].xPesquisas > Livro[Count].xPesquisas then
begin
bN:=Livro[i].Nome;
bA:=Livro[i].Autor;
bG:=Livro[i].Genero;
bC:=Livro[i].Corredor;
bP:=Livro[i].Prateleira;
bxP:=Livro[i].xPesquisas;
Livro[i].Nome:=Livro[Count].Nome;
Livro[i].Autor:=Livro[Count].Autor;
Livro[i].Genero:=Livro[Count].Genero;
Livro[i].Corredor:=Livro[Count].Corredor;
Livro[i].Prateleira:=Livro[Count].Prateleira;
Livro[i].xPesquisas:=Livro[Count].xPesquisas;
Livro[Count].Nome:=bN;
Livro[Count].Autor:=bA;
Livro[Count].Genero:=bG;
Livro[Count].Corredor:=bC;
Livro[Count].Prateleira:=bP;
Livro[Count].xPesquisas:=bxP;
end;
end;
end;
end;
//* Função para fazer a pesquisa de acordo com o filtro *//
function SearchBook(EditString: string; comboID: string) : Integer;
var
i:Integer;
begin
idCount:=0;
case AnsiIndexStr(LowerCase(comboID),['nome','autor','genero','corredor','prateleira']) of
0:
begin
for i:=1 to 10 do
begin
if(Pos(LowerCase(EditString),LowerCase(Livro[i].Nome)) > 0) then
begin
idCount:=idCount+1;
id[idCount]:=i;
Livro[i].xPesquisas:= Livro[i].xPesquisas+1;
end;
end;
end;
1:
begin
for i:=1 to 10 do
begin
if(Pos(LowerCase(EditString),LowerCase(Livro[i].Autor)) > 0) then
begin
idCount:=idCount+1;
id[idCount]:=i;
Livro[i].xPesquisas:= Livro[i].xPesquisas+1;
end;
end;
end;
2:
begin
for i:=1 to 10 do
begin
if(Pos(LowerCase(EditString),LowerCase(Livro[i].Genero)) > 0) then
begin
idCount:=idCount+1;
id[idCount]:=i;
Livro[i].xPesquisas:= Livro[i].xPesquisas+1;
end;
end;
end;
3:
begin
for i:=1 to 10 do
begin
if(Pos(LowerCase(EditString),LowerCase(IntToStr(Livro[i].Corredor))) > 0) then
begin
idCount:=idCount+1;
id[idCount]:=i;
end;
end;
end;
4:
begin
for i:=1 to 10 do
begin
if(Pos(LowerCase(EditString),LowerCase(IntToStr(Livro[i].Prateleira))) > 0) then
begin
idCount:=idCount+1;
id[idCount]:=i;
end;
end;
end;
end;
Result:=idCount;
end;
//* Função principal da janela, onde é processado todas as mensagens do programa *//
function WinMain(hWnd: DWORD; uMsg, wParam, lParam: Integer) : Integer; stdcall;
begin
Result:= DefWindowProc(hWnd, uMsg, wParam, lParam);
case uMsg of
WM_DESTROY: //Fechar programa
begin
PostQuitMessage(0);
Halt;
end;
WM_COMMAND:
begin
if(lParam = ButtonLogin) then //Caso o botão de login seja pressionado
begin
GetWindowText(EditLogin,@buff, MAX_PATH);
GetWindowText(EditPass,@buff2,MAX_PATH);
if((AnsiCompareStr(buff, 'Admin') = 0) and (AnsiCompareStr(buff2, 'Livros') = 0)) then
begin
ShowWindow(window2, 1);
ShowWindow(window, 0)
end else
MessageBox(hWnd,PChar('Login ou Senha incorretos, solicite ajuda para um funcionário da biblioteca!'),PChar('Erro!'),MB_OK);
end;
if(lParam = ButtonSearch) then //Caso o botão de pesquisa for pressionado
begin
SendMessage(ListBox, LB_RESETCONTENT,0,0);
GetWindowText(EditSearch,@buff, MAX_PATH);
GetWindowText(ComboBox,@buff2,MAX_PATH);
nTemp:=SearchBook(buff,buff2);
if((buff2 <> '') and (buff <> '')) then
begin
if nTemp = 0 then
MessageBox(hWnd,PChar('Nenhum resultado encontrado!'),PChar('Pesquisa Concluída!'),MB_OK)
else
begin
for iTemp:=1 to nTemp do
begin
SendMessage(ListBox,LB_ADDSTRING,0,LongInt(PChar(Livro[id[iTemp]].Nome)));
end;
GetClientRect(LabelTop3,r);
InvalidateRect(LabelTop3, @r,True);
MapWindowPoints(LabelTop3,hWnd,r,2);
RedrawWindow(hWnd,@r,0,RDW_ERASE or RDW_INVALIDATE);
GetClientRect(LabelxS,r);
InvalidateRect(LabelxS, @r,True);
MapWindowPoints(LabelxS,hWnd,r,2);
RedrawWindow(hWnd,@r,0,RDW_ERASE or RDW_INVALIDATE);
AttTop3();
totalSearch:=totalSearch+1;
if totalSearch >= 3 then
SetWindowText(LabelTop3,PChar(' Top 3 Mais Pesquisados:'+lB+lB+'1: '+Livro[1].Nome+lB+lB+'2: '+Livro[2].Nome+lB+lB+'3: '+Livro[3].Nome));
SetWindowText(LabelxS,PChar('Pesquisas Feitas: '+IntToStr(totalSearch)));
end;
nTemp:=MessageBox(hWnd,PChar('Pesquisa realizada com sucesso!'+lB+'Deseja realizar outra?'),PChar('Info'),MB_YESNO);
if nTemp = 7 then
begin
ShowWindow(window,1);
ShowWindow(window2,0);
end;
end else
MessageBox(hWnd,PChar('Nenhum prefixo selecionado ou nenhuma palavra digitada na barra de pesquisa!'),PChar('Erro!'),MB_OK);
end;
if(lParam = ListBox) then
begin
if(HiWord(wParam) = LBN_SELCHANGE) then //Atualizar as informações do livro de acordo com o que foi selecionado no ListBox
begin
nTemp:=SendMessage(ListBox,LB_GETCURSEL,0,0);
SendMessage(ListBox,LB_GETTEXT,nTemp,Integer(@Buff));
GetClientRect(LabelI,r);
InvalidateRect(LabelI, @r,True);
MapWindowPoints(LabelI,hWnd,r,2);
RedrawWindow(hWnd,@r,0,RDW_ERASE or RDW_INVALIDATE);
nTemp:=SearchBook(buff,'nome');
SetWindowText(LabelI,PChar('Infos:'+lB+lB+'Nome: '+Livro[id[1]].Nome+lB+lB+'Autor: '+Livro[id[1]].Autor+lB+lB+'Genero: '+Livro[id[1]].Genero+lB+lB+'Corredor: '+IntToStr(Livro[id[1]].Corredor)+lB+'Prateleira: '+IntToStr(Livro[id[1]].Prateleira)));
end;
end;
end;
WM_CTLCOLORSTATIC: //Estética do label
begin
tLab:= wParam;
SetBkMode(tLab,TRANSPARENT);
Result:= GetStockObject(NULL_BRUSH);
end;
end;
end;
begin
with winClass do //Definição da Classe principal do programa
begin
style:= CS_OWNDC or CS_HREDRAW or CS_VREDRAW;
lpfnWndProc:= @WinMain;
hInstance:=hInstance;
hbrBackground:=CreateSolidBrush($FFFFFF);
lpszClassName:='DPTeamClass';
hCursor:=LoadCursor(0,IDC_ARROW);
hIcon:=LoadImage(GetModuleHandle(0),'DP_ICOx64.ico',IMAGE_ICON,32,32,LR_LOADFROMFILE);
end;
hFont := CreateFont(-11, 0, 0, 0, 400, 0, 0, 0, DEFAULT_CHARSET,OUT_DEFAULT_PRECIS, CLIP_DEFAULT_PRECIS, DEFAULT_QUALITY,DEFAULT_PITCH or FF_DONTCARE, 'MS Sans Serif');
RegisterClassA(winClass);
//* Criação dos componentes da janela de login *//
window:= CreateWindowExA(0,'DPTeamClass', 'Biblioteca',WS_OVERLAPPED or WS_CAPTION or WS_SYSMENU or WS_MINIMIZEBOX, CW_USEDEFAULT,CW_USEDEFAULT,192,200,0,0,HInstance,nil);
ButtonLogin:= CreateWindowExA(0,'Button','Logar',WS_TABSTOP or WS_VISIBLE or WS_CHILD,40,130,100,25,window,3 ,HInstance,nil);
EditLogin:= CreateWindowExA(0,'Edit','',WS_TABSTOP or WS_VISIBLE or WS_CHILD or WS_BORDER, 10,30,165,25,window,1,HInstance,nil);
EditPass:= CreateWindowExA(0,'Edit','',WS_TABSTOP or ES_PASSWORD or WS_VISIBLE or WS_CHILD or WS_BORDER, 10,80,165,25,window,2,HInstance,nil);
LabelL:= CreateWindowExA(0,'Static','Login:',WS_VISIBLE or WS_CHILD,10,10,100,20,window,0,HInstance,nil);
LabelP:= CreateWindowExA(0,'Static','Senha:',WS_VISIBLE or WS_CHILD,10,60,100,20,window,0,HInstance,nil);
//* Definição da fonte padrão para todos esses componentes *//
SendMessage(ButtonLogin,WM_SETFONT,hFont,0);
SendMessage(EditLogin,WM_SETFONT,hFont,0);
SendMessage(EditPass,WM_SETFONT,hFont,0);
SendMessage(LabelL,WM_SETFONT,hFont,0);
SendMessage(LabelP,WM_SETFONT,hFont,0);
ShowWindow(window, SW_SHOWNORMAL); //Mostrar janela principal
//* Criação dos componentes da janela de pesquisa *//
window2:= CreateWindowExA(0,'DPTeamClass', 'Biblioteca DarkProgramming',WS_OVERLAPPED or WS_CAPTION or WS_SYSMENU or WS_MINIMIZEBOX, CW_USEDEFAULT,CW_USEDEFAULT,370,430,0,0,HInstance,nil);
EditSearch:=CreateWindowExA(0,'Edit','',WS_VISIBLE or WS_CHILD or WS_BORDER,110,30,150,25,window2,0,HInstance,nil);
ButtonSearch:=CreateWindowExA(0,'Button','Procurar',WS_VISIBLE or WS_CHILD, 270,29,80,25,window2,0,HInstance,nil);
LabelS:=CreateWindowExA(0,'Static','Pesquisar por:',WS_VISIBLE or WS_CHILD, 10,10,100,25,window2,0,HInstance,nil);
LabelxS:=CreateWindowExA(0,'Static','Pesquisas Feitas: 0',WS_VISIBLE or WS_CHILD, 10, 60,100,20,window2,0,hInstance,nil);
LabelI:=CreateWindowExA(0,'Static','Info: ',WS_VISIBLE or WS_CHILD, 215, 100, 150,200, window2,0,HInstance,nil);
ListBox:=CreateWindowExA(0,'ListBox','ListBox',LBS_NOTIFY or WS_VISIBLE or WS_CHILD or WS_BORDER,10,90,200,200,window2,0,HInstance,nil);
ComboBox:=CreateWindowExA(0,'ComboBox','Nome',WS_VISIBLE or WS_CHILD or WS_BORDER or CBS_DROPDOWN, 11,30,80,30,window2,0,HInstance,nil);
LabelTop3:=CreateWindowExA(0,'Static',' Top 3 Mais Pesquisados: '+lB+lB+'1: '+lB+lB+'2: '+lB+lB+'3: ',WS_VISIBLE or WS_CHILD, 10, 285, 300,200,window2,0,HInstance,nil);
//* Definição dos itens que compoem o ComboBox para realizar o filtro de pesquisa *//
SendMessage(ComboBox,CB_ADDSTRING,0,LongInt(PChar('Nome')));
SendMessage(ComboBox,CB_ADDSTRING,0,LongInt(PChar('Autor')));
SendMessage(ComboBox,CB_ADDSTRING,0,LongInt(PChar('Genero')));
SendMessage(ComboBox,CB_ADDSTRING,0,LongInt(PChar('Corredor')));
SendMessage(ComboBox,CB_ADDSTRING,0,LongInt(PChar('Prateleira')));
//* Definição da fonte padrão para os componentes da janela de login *//
SendMessage(EditSearch,WM_SETFONT,hFont,0);
SendMessage(ButtonSearch,WM_SETFONT,hFont,0);
SendMessage(LabelS,WM_SETFONT,hFont,0);
SendMessage(ListBox,WM_SETFONT,hFont,0);
SendMessage(LabelxS,WM_SETFONT,hFont,0);
SendMessage(LabelI,WM_SETFONT,hFont,0);
SendMessage(LabelTop3,WM_SETFONT, hFont,0);
SendMessage(ComboBox,WM_SETFONT,hFont,0);
//* Processamento das mensagens que estão circulando na aplicação *//
while (GetMessage(Msg,0,0,0)) do
begin
TranslateMessage(Msg);
DispatchMessage(Msg);
end;
end.