Ir ao conteúdo
  • Cadastre-se
DAVIFN

C++ - Meu software está ficando legal?

Recommended Posts

Olá pessoal, meu passatempo é criar programas (sou muito leigo em C++), e, hoje comecei a criar um editor de texto simples, mas com algumas funções muito úteis:

1 - Ele seria um executável que guardaria o texto dentro de si mesmo, não precisando de um programa auxiliar para abrí-lo.

2 - Teria várias opções de personalização de cores e tamanho da janela, você pode ter quantos executáveis quiser cada um com personalizações diferentes, pois cada um guarda as opções de personalização dentro de si mesmo.

3 - O executável principal deve criar este aqui postado no disco local (C:), este aqui postado terá um ícone de pasta, e é muito engraçado o que fiz: Caso alguém tente abrí-lo, ele se oculta e se transforma numa pasta, e autoabre a mesma. Ele só pode ser aberto pelo meu software (veja depois instruções para ver como seria esta pasta)

Então, o motivo que me levou a criar este tópico é para vocês analisarem como está ficando e, se acharem erros ou algo que poderia ser melhor, compartilhassem comigo. Também há vários comandos legais para programadores "hobbies" como eu. Segue abaixo o código fonte do até então software:

#include <direct.h>
#include <stdio.h>
#include <windows.h>
char*homedrive;
int tamanhojanela=0;
LRESULT CALLBACK WindowProcedure(HWND, UINT, WPARAM, LPARAM);
char*titulocr="";
HWND hwnd,corjanelaum,corjaneladois,corjanelatres,corjanelaquatro,texto,textoborda,titulo,menu,menutexto,menuborda,personalizarbotao,personalizar,selecionarbotao,selecionar,backupbotao,backup,ajudabotao,ajuda,sairbotao,sair,sairsbotao,sairs,minimizarbotao,minimizarborda,minimizar,personalizartexto,selecionartexto,backuptexto,ajudatexto,sairtexto,sairstexto,minimizartexto;
RECT rect;
HDC hdc;
PAINTSTRUCT ps;
HFONT hFont;
char modulo[999];
char*nomepasta;
FILE*Gravacoes;
char Recebergravacoes[88500];
char temporario[1];
int fgetcchar;
int WINAPI WinMain(HINSTANCE hThisInstance,HINSTANCE hPrevInstance,LPSTR lpszArgument,int nFunsterStil)
{
if(GetModuleFileName(NULL,modulo,999));
if(strcmp(lpszArgument,"Remova esta frase")==0)
{
if(SetFileAttributes(modulo,FILE_ATTRIBUTE_HIDDEN)){}
if(SetFileAttributes(modulo,FILE_ATTRIBUTE_SYSTEM)){}
if(SetFileAttributes(modulo,FILE_ATTRIBUTE_READONLY)){}
if(nomepasta=strdup(modulo)){}
if(nomepasta[strlen(nomepasta)-4]='\0'){}
if(mkdir(nomepasta)){}
if(ShellExecute(hwnd,"open","explorer.exe",nomepasta,NULL,SW_NORMAL)==NULL){}
return 0;
}
homedrive=getenv("homedrive");
MSG messages;
WNDCLASSEX wincl;
wincl.hInstance = hThisInstance;
wincl.lpszClassName = "DaviFN";
wincl.lpfnWndProc = WindowProcedure;
wincl.style = CS_DBLCLKS;
wincl.cbSize = sizeof (WNDCLASSEX);
wincl.hIcon = LoadIcon (NULL, IDI_APPLICATION);
wincl.hIconSm = LoadIcon (NULL, IDI_APPLICATION);
wincl.hCursor = LoadCursor (NULL, IDC_ARROW);
wincl.lpszMenuName = NULL;
wincl.cbClsExtra = 0;
wincl.cbWndExtra = 0;
wincl.hbrBackground = (HBRUSH) 0;
if (!RegisterClassEx (&wincl))
return 0;
switch(tamanhojanela)
{
case 0:
hwnd = CreateWindowEx (
0,
"DaviFN",
"DaviFN",
WS_CAPTION,
(GetSystemMetrics(SM_CXSCREEN)-725)/2,
(GetSystemMetrics(SM_CYSCREEN)-575)/2,
720,
550,
HWND_DESKTOP,
NULL,
hThisInstance,
NULL
);
break;
}
ShowWindow(hwnd,SW_NORMAL);
while (GetMessage (&messages, NULL, 0, 0))
{
TranslateMessage(&messages);
DispatchMessage(&messages);
}
return messages.wParam;
}
LRESULT CALLBACK WindowProcedure (HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
{
HINSTANCE hInstance=(HINSTANCE)GetWindowLong(hwnd,GWL_HINSTANCE);
switch (message)
{
case WM_COMMAND:
switch(wParam)
{
case 0:
//ShowWindow(hwnd,SW_HIDE);
// DestroyWindow(hwnd);
MessageBox(NULL,"Menu para personalizar ainda não programado, pessoal!","Erro!",MB_OK);
ShowWindow(hwnd,SW_HIDE);
DestroyWindow(hwnd);
break;
case 1:
SetFocus(texto);
SendMessage(texto,EM_SETSEL,0,-1);
break;
case 2:
ShowWindow(hwnd,SW_HIDE);
DestroyWindow(hwnd);
break;
case 3:
ShowWindow(hwnd,SW_HIDE);
MessageBox(NULL,"A aba \"sobre\" ainda está para ser criada! Sinto muito!","Erro!",MB_OK);
DestroyWindow(hwnd);
break;
case 4:
if(ShowWindow(hwnd,SW_HIDE)){}
if(GetWindowText(texto,Recebergravacoes,88500)){}
if(Gravacoes=fopen("Teste.txt","wb")){}
if(fprintf(Gravacoes,Recebergravacoes)){}
if(fclose(Gravacoes)){}
if(DestroyWindow(hwnd)){}
case 5:
ShowWindow(hwnd,SW_HIDE);
DestroyWindow(hwnd);
break;
case 6:
ShowWindow(hwnd,SW_MINIMIZE);
}
break;
case WM_CREATE:
corjanelaum=CreateWindow("static","",WS_CHILD|WS_VISIBLE,0,0,375,550,hwnd,NULL,hInstance,NULL);
corjaneladois=CreateWindow("static","",WS_CHILD|WS_VISIBLE,515,0,200,550,hwnd,NULL,hInstance,NULL);
corjanelatres=CreateWindow("static","",WS_CHILD|WS_VISIBLE,375,0,140,25,hwnd,NULL,hInstance,NULL);
corjanelaquatro=CreateWindow("static","",WS_CHILD|WS_VISIBLE,375,65,395,453,hwnd,NULL,hInstance,NULL);
textoborda=CreateWindow("static","",WS_CHILD|WS_VISIBLE,198,86,494,407,hwnd,NULL,hInstance,NULL);
titulo=CreateWindow("edit",NULL,WS_CHILD|WS_VISIBLE,200,88,490,16,hwnd,NULL,hInstance,NULL);
SetWindowText(titulo,"Olá pessoal do Fórum do Clube do Hardware!");
texto=CreateWindow("edit",NULL,WS_CHILD|WS_VISIBLE|WS_VSCROLL|ES_LEFT|ES_AUTOVSCROLL|ES_MULTILINE,200,106,490,384,hwnd,NULL,hInstance,NULL);
SendMessage(texto,EM_LIMITTEXT,88500,0);
if(Gravacoes=fopen("Teste.txt","rb")){}
while((fgetcchar=fgetc(Gravacoes))!=EOF)
{
sprintf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aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaabab");
if(SetWindowText(texto,Recebergravacoes)){}
//}
menuborda=CreateWindow("static","",WS_CHILD|WS_VISIBLE,20,86,158,362,hwnd,NULL,hInstance,NULL);
menu=CreateWindow("static","",WS_CHILD|WS_VISIBLE,22,88,154,16,hwnd,NULL,hInstance,NULL);
menutexto=CreateWindow("static","Menu",WS_CHILD|WS_VISIBLE,79,88,36,13,hwnd,NULL,hInstance,NULL);
personalizarbotao=CreateWindow("button","",WS_VISIBLE|WS_CHILD|BS_OWNERDRAW,22,106,154,55,hwnd,HMENU(0),hInstance, NULL);
personalizar=CreateWindow("static","",WS_CHILD|WS_VISIBLE,22,106,154,55,hwnd,NULL,hInstance,NULL);
selecionarbotao=CreateWindow("button","",WS_VISIBLE|WS_CHILD|BS_OWNERDRAW,22,163,154,55,hwnd,HMENU(1),hInstance, NULL);
selecionar=CreateWindow("static","",WS_CHILD|WS_VISIBLE,22,163,154,55,hwnd,NULL,hInstance,NULL);
backupbotao=CreateWindow("button","",WS_VISIBLE|WS_CHILD|BS_OWNERDRAW,22,220,154,55,hwnd,HMENU(2),hInstance, NULL);
backup=CreateWindow("static","",WS_CHILD|WS_VISIBLE,22,220,154,55,hwnd,NULL,hInstance,NULL);
ajudabotao=CreateWindow("button","",WS_VISIBLE|WS_CHILD|BS_OWNERDRAW,22,277,154,55,hwnd,HMENU(3),hInstance, NULL);
ajuda=CreateWindow("static","",WS_CHILD|WS_VISIBLE,22,277,154,55,hwnd,NULL,hInstance,NULL);
sairbotao=CreateWindow("button","",WS_VISIBLE|WS_CHILD|BS_OWNERDRAW,22,334,154,55,hwnd,HMENU(4),hInstance, NULL);
sair=CreateWindow("static","",WS_CHILD|WS_VISIBLE,22,334,154,55,hwnd,NULL,hInstance,NULL);
sairsbotao=CreateWindow("button","",WS_VISIBLE|WS_CHILD|BS_OWNERDRAW,22,391,154,55,hwnd,HMENU(5),hInstance, NULL);
sairs=CreateWindow("static","",WS_CHILD|WS_VISIBLE,22,391,154,55,hwnd,NULL,hInstance,NULL);
minimizarbotao=CreateWindow("button","",WS_VISIBLE|WS_CHILD|BS_OWNERDRAW,22,472,154,19,hwnd,HMENU(6),hInstance, NULL);
minimizarborda=CreateWindow("static","",WS_CHILD|WS_VISIBLE,20,470,158,23,hwnd,NULL,hInstance,NULL);
minimizar=CreateWindow("static","",WS_CHILD|WS_VISIBLE,22,472,154,19,hwnd,NULL,hInstance,NULL);
personalizartexto=CreateWindow("static","Personalizar",WS_CHILD|WS_VISIBLE,54,124,83,13,hwnd,NULL,hInstance,NULL);
selecionartexto=CreateWindow("static","Selecionar tudo",WS_CHILD|WS_VISIBLE,45,181,120,13,hwnd,NULL,hInstance,NULL);
backuptexto=CreateWindow("static","Backup",WS_CHILD|WS_VISIBLE,71,238,48,25,hwnd,NULL,hInstance,NULL);
ajudatexto=CreateWindow("static","Sobre",WS_CHILD|WS_VISIBLE,76,295,38,25,hwnd,NULL,hInstance,NULL);
sairtexto=CreateWindow("static","Salvar e sair",WS_CHILD|WS_VISIBLE,55,352,85,25,hwnd,NULL,hInstance,NULL);
sairstexto=CreateWindow("static","Sair sem salvar",WS_CHILD|WS_VISIBLE,46,409,105,25,hwnd,NULL,hInstance,NULL);
minimizartexto=CreateWindow("static","Minimizar",WS_CHILD|WS_VISIBLE,66,473,67,18,hwnd,NULL,hInstance,NULL);

// janela=CreateWindow("static","",WS_CHILD|WS_VISIBLE,0,0,150,200,hwnd,NULL,(HINSTANCE)GetWindowLong(hwnd,GWL_HINSTANCE),NULL);
// contador=CreateWindow("static","0",WS_CHILD|WS_VISIBLE,65,30,60,20,hwnd,NULL,(HINSTANCE)GetWindowLong(hwnd,GWL_HINSTANCE),NULL);
// botaomaisum=CreateWindow("button","",WS_VISIBLE|WS_CHILD|BS_OWNERDRAW,20,105,40,15,hwnd,HMENU(0),NULL, NULL);
// botaomaisdois=CreateWindow("button","",WS_VISIBLE|WS_CHILD|BS_OWNERDRAW,32,93,15,40,hwnd,HMENU(0),NULL, NULL);
// botaomenos=CreateWindow("button","",WS_VISIBLE|WS_CHILD|BS_OWNERDRAW,80,105,40,15,hwnd,HMENU(1),NULL, NULL);
// bbotaomaisum=CreateWindow("static","0",WS_CHILD|WS_VISIBLE,20,105,40,15,hwnd,NULL,(HINSTANCE)GetWindowLong(hwnd,GWL_HINSTANCE),NULL);
// bbotaomaisdois=CreateWindow("static","0",WS_CHILD|WS_VISIBLE,32,93,15,40,hwnd,NULL,(HINSTANCE)GetWindowLong(hwnd,GWL_HINSTANCE),NULL);
// bbotaomenos=CreateWindow("static","0",WS_CHILD|WS_VISIBLE,80,105,40,15,hwnd,NULL,(HINSTANCE)GetWindowLong(hwnd,GWL_HINSTANCE),NULL);
break;
case WM_CTLCOLORSTATIC:
/*if((HWND)lParam==janela||(HWND)lParam==contador)
{
SetTextColor((HDC)wParam,RGB(0,0,0));
SetBkColor((HDC)wParam,RGB(255,255,255));
return (INT_PTR)CreateSolidBrush(RGB(255,255,255));
}
else
{
SetTextColor((HDC)wParam,RGB(0,0,0));
SetBkColor((HDC)wParam,RGB(0,0,0));
return (INT_PTR)CreateSolidBrush(RGB(0,0,0));
}*/
if((HWND)lParam==corjanelaum||(HWND)lParam==corjaneladois||(HWND)lParam==corjanelatres||(HWND)lParam==corjanelaquatro||(HWND)lParam==titulo||(HWND)lParam==menu||(HWND)lParam==menutexto||(HWND)lParam==personalizar||(HWND)lParam==selecionar||(HWND)lParam==backup||(HWND)lParam==ajuda||(HWND)lParam==sair||(HWND)lParam==sairs||(HWND)lParam==minimizar||(HWND)lParam==personalizartexto||(HWND)lParam==selecionartexto||(HWND)lParam==backuptexto||(HWND)lParam==ajudatexto||(HWND)lParam==sairtexto||(HWND)lParam==sairstexto||(HWND)lParam==minimizartexto)
{
SetTextColor((HDC)wParam,RGB(0,0,0));
SetBkColor((HDC)wParam,RGB(255,255,255));
return (INT_PTR)CreateSolidBrush(RGB(255,255,255));
}
else
{
SetTextColor((HDC)wParam,RGB(255,255,255));
SetBkColor((HDC)wParam,RGB(0,0,0));
return (INT_PTR)CreateSolidBrush(RGB(0,0,0));
}
break;
case WM_PAINT:
hdc = BeginPaint(hwnd, &ps);
hFont = CreateFont(48,0,0,0,FW_DONTCARE,FALSE,FALSE,FALSE,DEFAULT_CHARSET,OUT_OUTLINE_PRECIS,
CLIP_DEFAULT_PRECIS,ANTIALIASED_QUALITY,VARIABLE_PITCH,NULL);
SelectObject(hdc,hFont);
SetRect(&rect, 375, 20, 0, 0);
SetTextColor(hdc, RGB(0,0,0));
SetBkColor(hdc,RGB(255,255,255));
DrawText(hdc, TEXT("DaviFN"), -1,&rect, DT_NOCLIP);
EndPaint(hwnd, &ps);
break;
case WM_CLOSE:
//ShowWindow(hwnd,SW_HIDE);
//DestroyWindow(hwnd);
break;
case WM_DESTROY:
PostQuitMessage(0);
break;
default:
return DefWindowProc (hwnd, message, wParam, lParam);
}

return 0;
}

Nota: Remova a frase "Remova esta frase" logo no início do código e compile para ver como seria ele se fosse aberto manualmente. Caso você compile sem remover a frase, ele irá abrir normalmente (recomendo compilar com a frase primeiro)

Aguardo respostas!!!

EDIT : Pessoal, você que tá começando e não entendeu muito os comandos aí, mas gostou do resultado, eu posso te ajudar com meus conhecimentos (que são muito poucos), afinal, faço o que gostaria de receber. Você pode me adicionar no Facebook™ caso queira explicação de algum comando, ou ajuda, ou até quem sabe para sermos amigos. Davi Nonnenmacher.

Compartilhar este post


Link para o post
Compartilhar em outros sites

Continuo programando e, quando terminar as personalizações e backup, edito o código pelo novo.

Compartilhar este post


Link para o post
Compartilhar em outros sites

Crie uma conta ou entre para comentar

Você precisar ser um membro para fazer um comentário

Criar uma conta

Crie uma nova conta em nossa comunidade. É fácil!

Crie uma nova conta

Entrar

Já tem uma conta? Faça o login.

Entrar agora





Sobre o Clube do Hardware

No ar desde 1996, o Clube do Hardware é uma das maiores, mais antigas e mais respeitadas publicações 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

×