Ir ao conteúdo
  • Cadastre-se

C Sistema bancario em linguagem C


kisne

Posts recomendados

<Olá, alguém poderia me ajuda a questão é a seguinte tô criando um sistema bancário básico com interface grafica, para fim didático, tem uma janela com os comandos de login e cadastro e outra janela com já os sistema de depósito e saque e mostrador de saldo que são apenas áreas de textos e os botões a minha dificuldade no caso é na hora de fazer a transição de uma janela para outra quando o usuário pressiona botão de login fecha essa janela e abre as com os botões de depósito e saque, aí gostaria de saber alguém tem um exemplo de código ou algum site em que eu possa aprender 
Uso Windows.h win32 
Quero aprender nesse primeiro antes de passa para sistemas que já me dá tudo mastigado como gtk.

Aqui está os códigos das duas janelas>

 

<   

#include <windows.h>
#include <Conta Bancaria.c>

/* This is where all the input to the window goes to */
LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM);


/* The 'main' function of Win32 GUI programs: this is where execution starts */
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow) {
    WNDCLASSEX wc; /* A properties struct of our window */
    HWND hwnd; /* A 'HANDLE', hence the H, or a pointer to our window */
    MSG msg; /* A temporary location for all messages */

    /* zero out the struct and set the stuff we want to modify */
    memset(&wc,0,sizeof(wc));
    wc.cbSize         = sizeof(WNDCLASSEX);
    wc.lpfnWndProc     = WndProc; /* This is where we will send messages to */
    wc.hInstance     = hInstance;
    wc.hCursor         = LoadCursor(NULL, IDC_ARROW);
    
    /* White, COLOR_WINDOW is just a #define for a system color, try Ctrl+Clicking it */
    wc.hbrBackground = (HBRUSH)(COLOR_WINDOW+1);
    wc.lpszClassName = "WindowClass";
    wc.hIcon         = LoadIcon(NULL, IDI_APPLICATION); /* Load a standard icon */
    wc.hIconSm         = LoadIcon(NULL, IDI_APPLICATION); /* use the name "A" to use the project icon */

    if(!RegisterClassEx(&wc)) {
        MessageBox(NULL, "Window Registration Failed!","Error!",MB_ICONEXCLAMATION|MB_OK);
        return 0;
    }

    hwnd = CreateWindowEx(WS_EX_CLIENTEDGE,"WindowClass","Login Conta Bancaria",WS_VISIBLE|WS_OVERLAPPEDWINDOW,
        CW_USEDEFAULT, /* x */
        CW_USEDEFAULT, /* y */
        640, /* width */
        480, /* height */
        NULL,NULL,hInstance,NULL);

    if(hwnd == NULL) {
        MessageBox(NULL, "Window Creation Failed!","Error!",MB_ICONEXCLAMATION|MB_OK);
        return 0;
    }

    /*
        This is the heart of our program where all input is processed and 
        sent to WndProc. Note that GetMessage blocks code flow until it receives something, so
        this loop will not produce unreasonably high CPU usage
    */
    while(GetMessage(&msg, NULL, 0, 0) > 0) { /* If no error is received... */
        TranslateMessage(&msg); /* Translate key codes to chars if present */
        DispatchMessage(&msg); /* Send it to WndProc */
    }
    return msg.wParam;
}

#define ID_Login 1001
#define ID_Cadastrar 1002

HINSTANCE g_inst;
HWND EditNum1,EditNum2,EditNum3,EditNum4,EditNum5,EditNum6,EditTotal,Login,Cadastrar;

void DesenharObjectos(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
{   
    
    CreateWindowEx (
        0,"STATIC","Nome",
        WS_VISIBLE|WS_CHILD|WS_BORDER,
        10, 80, 80, 25,
        hwnd,NULL,g_inst,NULL);
        
    CreateWindowEx (
        0,"STATIC", "Nome",
        WS_VISIBLE|WS_CHILD|WS_BORDER,
        290, 80, 80, 25,
        hwnd, NULL, g_inst, NULL );
    
    CreateWindowEx (
        0,"STATIC","E-mail",
        WS_VISIBLE|WS_CHILD|WS_BORDER,
        10, 121, 80, 25,
        hwnd,NULL,g_inst,NULL);
        
    CreateWindowEx (
        0,"STATIC", "E-mail",
        WS_VISIBLE|WS_CHILD|WS_BORDER,
        290, 121, 80, 25,
        hwnd, NULL, g_inst, NULL );
    
    CreateWindowEx (
        0,"STATIC","Senha",
        WS_VISIBLE|WS_CHILD|WS_BORDER,
        10, 161, 80, 25,
        hwnd,NULL,g_inst,NULL);
        
    CreateWindowEx (
        0,"STATIC", "Senha",
        WS_VISIBLE|WS_CHILD|WS_BORDER,
        290, 161, 80, 25,
        hwnd, NULL, g_inst, NULL );
    
    EditNum1 = CreateWindowEx (
        WS_EX_CLIENTEDGE,"EDIT","a",
        WS_VISIBLE|WS_CHILD|WS_BORDER|ES_RIGHT ,
        90, 80, 200, 30,
        hwnd,NULL,g_inst,NULL);
        
    EditNum2 = CreateWindowEx (
        WS_EX_CLIENTEDGE,"EDIT", "",
        WS_VISIBLE|WS_CHILD|WS_BORDER,
        370, 80, 200, 30,
        hwnd, NULL, g_inst, NULL );
    
    EditNum3 = CreateWindowEx (
        WS_EX_CLIENTEDGE,"EDIT","",
        WS_VISIBLE|WS_CHILD|WS_BORDER|ES_RIGHT ,
        90, 120, 200, 30,
        hwnd,NULL,g_inst,NULL);
        
    EditNum4 = CreateWindowEx (
        WS_EX_CLIENTEDGE,"EDIT", "",
        WS_VISIBLE|WS_CHILD|WS_BORDER,
        370, 120, 200, 30,
        hwnd, NULL, g_inst, NULL );
        
        
    EditNum5 = CreateWindowEx (
        WS_EX_CLIENTEDGE,"EDIT","",
        WS_VISIBLE|WS_CHILD|WS_BORDER|ES_RIGHT ,
        90, 160, 200, 30,
        hwnd,NULL,g_inst,NULL);
        
    EditNum6 = CreateWindowEx (
        WS_EX_CLIENTEDGE,"EDIT", "",
        WS_VISIBLE|WS_CHILD|WS_BORDER,
        370, 160, 200, 30,
        hwnd, NULL, g_inst, NULL );
    
        
    Login = CreateWindowEx (
        0, "BUTTON", "Login",
        WS_VISIBLE|WS_CHILD,
        90, 220, 200, 30,
        hwnd,(HMENU)ID_Login, g_inst, NULL);
        
    Cadastrar = CreateWindowEx (
        0, "BUTTON", "Cadastrar",
        WS_VISIBLE|WS_CHILD,
        370, 220, 200, 30,
        hwnd,(HMENU)ID_Cadastrar, g_inst, NULL);

    SendMessage((HWND) EditNum1,(UINT) WM_SETFONT,(WPARAM) 0,(LPARAM) lParam);
    SendMessage((HWND) EditNum2,(UINT) WM_SETFONT, (WPARAM) 0,(LPARAM) lParam);
    SendMessage((HWND) EditNum3,(UINT) WM_SETFONT,(WPARAM) 0,(LPARAM) lParam);
    SendMessage((HWND) EditNum4,(UINT) WM_SETFONT, (WPARAM) 0,(LPARAM) lParam);
    SendMessage((HWND) EditNum5,(UINT) WM_SETFONT,(WPARAM) 0,(LPARAM) lParam);
    SendMessage((HWND) EditNum6,(UINT) WM_SETFONT, (WPARAM) 0,(LPARAM) lParam);
    SendMessage((HWND) EditTotal,(UINT) WM_SETFONT, (WPARAM) 0,(LPARAM) lParam);

    SendMessage((HWND) Login,(UINT) WM_SETFONT, (WPARAM) 0,(LPARAM) lParam);
    SendMessage((HWND) Cadastrar,(UINT) WM_SETFONT, (WPARAM) 0,(LPARAM) lParam);
}

char nome1[200] [50], email1[200] [50],senha1[200] [50], nome2[200] [50], email2[200] [50], senha2[200] [50];
int linha, i;

LRESULT CALLBACK WndProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam) {
    switch(message) {
        case WM_CREATE: 
            DesenharObjectos(hwnd,message,wParam,lParam);
        break;
        case WM_COMMAND:
            
            if ((HIWORD(wParam) == BN_CLICKED))
            {

                SendMessage((HWND)EditNum1,(UINT)EM_GETLINE,(WPARAM)1,(LPARAM) &nome1);

                SendMessage((HWND)EditNum2,(UINT)EM_GETLINE,(WPARAM)1,(LPARAM) &email1);
                
                SendMessage((HWND)EditNum3,(UINT)EM_GETLINE,(WPARAM)1,(LPARAM) &senha1);

                SendMessage((HWND)EditNum4,(UINT)EM_GETLINE,(WPARAM)1,(LPARAM) &nome2);
                
                SendMessage((HWND)EditNum5,(UINT)EM_GETLINE,(WPARAM)1,(LPARAM) &email2);

                SendMessage((HWND)EditNum6,(UINT)EM_GETLINE,(WPARAM)1,(LPARAM) &senha2);

                   //valor1 = atof(s_valor1);
                //valor2 = atof(s_valor2);

                switch (LOWORD(wParam))
                {
                    case ID_Login:
                        for(i=0;i<200;i++){
                           if(nome1[i]==nome2){
                                 if(email1[i]==email2){
                                      if(senha1[i]==senha2){
                                           Conta Bancaria();
                                      }
                                 }
                           }
                       }
                    break;
                    case ID_Cadastrar:
                        FILE *farq;
                do{
                    farq = fopen("arqtexto.txt","a");
    
                    fprintf(farq, "%s \n", &nome1[linha]);
                    fprintf(farq, "%s \n", &email1[linha]);
                    fprintf(farq, "%d \n", &senha1[linha]);
    
                    fclose(farq);
                    linha++;
                }while(op==1);
                    break;    
                }

                //ftoa(total,s_total,2);

                SendMessage((HWND) EditTotal, (UINT) WM_SETTEXT, (WPARAM) 0, (LPARAM) &s_total);

            }
            
        break;    
        /* Upon destruction, tell the main thread to stop */
        case WM_DESTROY: {
            PostQuitMessage(0);
            break;
        }
        
        /* Todas as outras mensagens (muitas delas) são processadas usando procedimentos padrão */
        default:
            return DefWindowProc(hwnd, message, wParam, lParam);
    }
    return 0;
}
 

>

 

#include <windows.h>
#include <math.h>
#include "resource.h"

void reverse(char* str, int len)
{
    int i = 0, j = len - 1, temp;
    while (i < j) {
        temp = str[i];
        str[i] = str[j];
        str[j] = temp;
        i++;
        j--;
    }
}
  
// Converte um determinado inteiro x em string str []. 
// d é o número de dígitos exigidos na saída. 
// Se d for mais do que o número de dígitos em x, 
// então 0s são adicionados no início.
int intToStr(int x, char str[], int d)
{
    int i = 0;
    while (x) {
        str[i++] = (x % 10) + '0';
        x = x / 10;
    }
  
    // Se o número de dígitos necessários for maior, então
    // adicione 0s no início
    while (i < d)
        str[i++] = '0';
  
    reverse(str, i);
    str[i] = '\0';
    return i;
}
  
// Converte um número de ponto flutuante / duplo em uma string.
void ftoa(float n, char* res, int afterpoint)
{
    // Extrair parte inteira
    int ipart = (int)n;
  
    // Extrair parte flutuante
    float fpart = n - (float)ipart;
  
    // converter parte inteira em string
    int i = intToStr(ipart, res, 0);
  
    // verifique a opção de exibição após o ponto
    if (afterpoint != 0) {
        res[i] = '.'; // add dot
  
        // Obtenha o valor da parte da fração até o nº fornecido.
        // de pontos após o ponto. O terceiro parâmetro
        // é necessário para lidar com casos como 233,007
        fpart = fpart * pow(10, afterpoint);
  
        intToStr((int)fpart, res + i + 1, afterpoint);
    }
}

/*Este é o lugar onde todas as entradas para a janela vão para */
LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM); 


/* A função 'principal' dos programas GUI Win32: é aqui que a execução começa */
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpszArgument, int nCmdShow) {
    WNDCLASSEX wc; /* Uma estrutura de propriedades da nossa janela*/
    HWND hwnd; /*Um 'HANDLE', daí o H, ou um ponteiro para nossa janela*/
    MSG msg; /* A temporary location for all messages */

    /* zero out the struct and set the stuff we want to modify */
    wc.hInstance     = hInstance;
    wc.lpszClassName = "WindowClass";
    wc.lpfnWndProc     = WndProc; /* This is where we will send messages to */
    wc.style = CS_DBLCLKS;
    wc.cbSize = sizeof (WNDCLASSEX);
    
    wc.hIcon         = LoadIcon(hInstance, IDI_ICON); /* Load a standard icon */
    wc.hIconSm         = LoadIcon(NULL, IDI_APPLICATION); /* use the name "A" to use the project icon */
    wc.hCursor         = LoadCursor(NULL, IDC_ARROW);
    wc.lpszMenuName= NULL;
    wc.cbClsExtra = 0;
    wc.cbWndExtra = 0;
    
    /* White, COLOR_WINDOW is just a #define for a system color, try Ctrl+Clicking it */
    wc.hbrBackground = (HBRUSH)(COLOR_WINDOW+1);    
    
    if(!RegisterClassEx(&wc)) {
        MessageBox(NULL, "Window Registration Failed!","Error!",MB_ICONEXCLAMATION|MB_OK);
        return 0;
    }

    hwnd = CreateWindowEx(0,"WindowClass","Conta Bancaria",WS_OVERLAPPEDWINDOW,
        350, /* x */
        350, /* y */
        640, /* width */
        480, /* height */
        HWND_DESKTOP,NULL,hInstance,NULL);
    
    ShowWindow (hwnd, nCmdShow);

    /*
        Este é o coração do nosso programa onde todas as entradas são processadas e
        enviado para WndProc. Observe que GetMessage bloqueia o fluxo de código até receber algo, então
        este loop não produzirá um uso de CPU excessivamente alto
    */
    while(GetMessage(&msg, NULL, 0, 0)) 
    { /* If no error is received... */
        TranslateMessage(&msg); /* Translate key codes to chars if present */
        DispatchMessage(&msg); /* Send it to WndProc */
    }
    return msg.wParam;
}
#define ID_Depositar 1001
#define ID_Sacar 1002

HINSTANCE g_inst;
HWND EditNum1,EditNum2,EditTotal,Depositar,Sacar;

void DesenharObjectos(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
{
    EditNum1 = CreateWindowEx (
        WS_EX_CLIENTEDGE,"EDIT","",
        WS_VISIBLE|WS_CHILD|WS_BORDER|ES_RIGHT ,
        20, 120, 200, 30,
        hwnd,NULL,g_inst,NULL);
        
    EditNum2 = CreateWindowEx (
        WS_EX_CLIENTEDGE,"EDIT", "",
        WS_VISIBLE|WS_CHILD|WS_BORDER,
        260, 120, 200, 30,
        hwnd, NULL, g_inst, NULL );

    EditTotal = CreateWindowEx (
        WS_EX_CLIENTEDGE,"EDIT", "",
        WS_VISIBLE|WS_CHILD|WS_BORDER,
        400, 20, 200, 30,
        hwnd, NULL, g_inst, NULL );
        
    Depositar = CreateWindowEx (
        0, "BUTTON", "Depositar",
        WS_VISIBLE|WS_CHILD,
        20, 160, 200, 30,
        hwnd,(HMENU)ID_Depositar, g_inst, NULL);
        
    Sacar = CreateWindowEx (
        0, "BUTTON", "Sacar",
        WS_VISIBLE|WS_CHILD,
        260, 160, 200, 30,
        hwnd,(HMENU)ID_Sacar, g_inst, NULL);

    SendMessage((HWND) EditNum1,(UINT) WM_SETFONT,(WPARAM) 0,(LPARAM) lParam);
    SendMessage((HWND) EditNum2,(UINT) WM_SETFONT, (WPARAM) 0,(LPARAM) lParam);
    SendMessage((HWND) EditTotal,(UINT) WM_SETFONT, (WPARAM) 0,(LPARAM) lParam);

    SendMessage((HWND) Depositar,(UINT) WM_SETFONT, (WPARAM) 0,(LPARAM) lParam);
    SendMessage((HWND) Sacar,(UINT) WM_SETFONT, (WPARAM) 0,(LPARAM) lParam);
}

char s_valor1[20] = "0", s_valor2[20] = "0", s_total[20] = "0";
float valor1, valor2, total, novoDeposito, novoSacar;

LRESULT CALLBACK WndProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam) {
    switch(message) {
        case WM_CREATE: 
            DesenharObjectos(hwnd,message,wParam,lParam);
        break;
        case WM_COMMAND:
            
            if ((HIWORD(wParam) == BN_CLICKED))
            {

                SendMessage((HWND)EditNum1,(UINT)EM_GETLINE,(WPARAM)1,(LPARAM) &s_valor1);

                SendMessage((HWND)EditNum2,(UINT)EM_GETLINE,(WPARAM)1,(LPARAM) &s_valor2);

                   valor1 = atof(s_valor1);
                valor2 = atof(s_valor2);

                switch (LOWORD(wParam))
                {
                    case ID_Depositar:
                        if(valor1>0){
                        MessageBox (NULL,"Parabens Deposito efetuado com sucesso \n voce acabou de Depositar", "Resultado", MB_OK);
                        novoDeposito = total;
                        novoDeposito = total + valor1;
                        total = novoDeposito;
                        SendMessage((HWND)EditNum1,(UINT)WM_SETTEXT,(WPARAM)1,(LPARAM) "");
                    }else{
                        MessageBox (NULL, "Erro Digite um valor", "Resultado", MB_OK);
                    }
                    break;
                    case ID_Sacar:
                        if(valor2<=total){
                            
                        MessageBox (NULL,"Parabens Saque efetuado com sucesso \n voce acabou de Sacar", "Resultado", MB_OK);
                        novoSacar = total;
                        novoSacar = total - valor2;
                        total = novoSacar;
                        SendMessage((HWND)EditNum2,(UINT)WM_SETTEXT,(WPARAM)1,(LPARAM) "");
                    }else if(valor2>total){
                        MessageBox (NULL, "Saldo insuficiente", "Resultado", MB_OK);
                        SendMessage((HWND)EditNum2,(UINT)WM_SETTEXT,(WPARAM)1,(LPARAM) "");
                    }else{
                        MessageBox (NULL, "Erro", "Resultado", MB_OK);
                    }
                    break;    
                }

                ftoa(total,s_total,2);

                SendMessage((HWND) EditTotal, (UINT) WM_SETTEXT, (WPARAM) 0, (LPARAM) &s_total);

            }
            
        break;    
        /* Upon destruction, tell the main thread to stop */
        case WM_DESTROY: {
            PostQuitMessage(0);
            break;
        }
        
        /* Todas as outras mensagens (muitas delas) são processadas usando procedimentos padrão */
        default:
            return DefWindowProc(hwnd, message, wParam, lParam);
    }
    return 0;
}
 

 >

Link para o comentário
Compartilhar em outros sites

1 hora atrás, kisne disse:

aí gostaria de saber alguém tem um exemplo de código ou algum site em que eu possa aprender 

 

Acho que deve imaginar que onde tem mais exemplos disso é na documentação do sistema. Não olhou lá?

 

Viu o material que tem em https://github.com/microsoft/Windows-classic-samples/tree/ac06e54a15e9a62443e400fffff190fb978ea586 ? Windows Classic Samples quer dizer isso mesmo. São exemplos de tudo.

 

E no MSDN? Olhou? Esse é o portal de documentação do sistema que está usando.

 

1 hora atrás, kisne disse:

Quero aprender nesse primeiro antes de passa para sistemas que já me dá tudo mastigado como gtk.

 

Não vai aprender muito com a API gráfica do Windows 32. Há muito não se escreve nada com isso. Nem a Microsoft recomenda. UWP é a plataforma recomendada, há mais de 10 anos.

 

Viu na documentação sobre common controls, em português?

 

Leu isso na documentação em português?: Conceitos básicos de design para aplicativos da Área de Trabalho

Como descrito no PRIMEIRO post desse forum, viu como formatar seu código?

 

Veja a diferença:

 

#include <windows.h>
#include <Conta Bancaria.c>

/* This is where all the input to the window goes to */
LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM);


/* The 'main' function of Win32 GUI programs: this is where execution starts */
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow) {
    WNDCLASSEX wc; /* A properties struct of our window */
    HWND hwnd; /* A 'HANDLE', hence the H, or a pointer to our window */
    MSG msg; /* A temporary location for all messages */

    /* zero out the struct and set the stuff we want to modify */
    memset(&wc,0,sizeof(wc));
    wc.cbSize         = sizeof(WNDCLASSEX);
    wc.lpfnWndProc     = WndProc; /* This is where we will send messages to */
    wc.hInstance     = hInstance;
    wc.hCursor         = LoadCursor(NULL, IDC_ARROW);
    
    /* White, COLOR_WINDOW is just a #define for a system color, try Ctrl+Clicking it */
    wc.hbrBackground = (HBRUSH)(COLOR_WINDOW+1);
    wc.lpszClassName = "WindowClass";
    wc.hIcon         = LoadIcon(NULL, IDI_APPLICATION); /* Load a standard icon */
    wc.hIconSm         = LoadIcon(NULL, IDI_APPLICATION); /* use the name "A" to use the project icon */

    if(!RegisterClassEx(&wc)) {
        MessageBox(NULL, "Window Registration Failed!","Error!",MB_ICONEXCLAMATION|MB_OK);
        return 0;
    }

    hwnd = CreateWindowEx(WS_EX_CLIENTEDGE,"WindowClass","Login Conta Bancaria",WS_VISIBLE|WS_OVERLAPPEDWINDOW,
        CW_USEDEFAULT, /* x */
        CW_USEDEFAULT, /* y */
        640, /* width */
        480, /* height */
        NULL,NULL,hInstance,NULL);

    if(hwnd == NULL) {
        MessageBox(NULL, "Window Creation Failed!","Error!",MB_ICONEXCLAMATION|MB_OK);
        return 0;
    }

    /*
        This is the heart of our program where all input is processed and 
        sent to WndProc. Note that GetMessage blocks code flow until it receives something, so
        this loop will not produce unreasonably high CPU usage
    */
    while(GetMessage(&msg, NULL, 0, 0) > 0) { /* If no error is received... */
        TranslateMessage(&msg); /* Translate key codes to chars if present */
        DispatchMessage(&msg); /* Send it to WndProc */
    }
    return msg.wParam;
}

#define ID_Login 1001
#define ID_Cadastrar 1002

HINSTANCE g_inst;
HWND EditNum1,EditNum2,EditNum3,EditNum4,EditNum5,EditNum6,EditTotal,Login,Cadastrar;

void DesenharObjectos(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
{   
    
    CreateWindowEx (
        0,"STATIC","Nome",
        WS_VISIBLE|WS_CHILD|WS_BORDER,
        10, 80, 80, 25,
        hwnd,NULL,g_inst,NULL);
        
    CreateWindowEx (
        0,"STATIC", "Nome",
        WS_VISIBLE|WS_CHILD|WS_BORDER,
        290, 80, 80, 25,
        hwnd, NULL, g_inst, NULL );
    
    CreateWindowEx (
        0,"STATIC","E-mail",
        WS_VISIBLE|WS_CHILD|WS_BORDER,
        10, 121, 80, 25,
        hwnd,NULL,g_inst,NULL);
        
    CreateWindowEx (
        0,"STATIC", "E-mail",
        WS_VISIBLE|WS_CHILD|WS_BORDER,
        290, 121, 80, 25,
        hwnd, NULL, g_inst, NULL );
    
    CreateWindowEx (
        0,"STATIC","Senha",
        WS_VISIBLE|WS_CHILD|WS_BORDER,
        10, 161, 80, 25,
        hwnd,NULL,g_inst,NULL);
        
    CreateWindowEx (
        0,"STATIC", "Senha",
        WS_VISIBLE|WS_CHILD|WS_BORDER,
        290, 161, 80, 25,
        hwnd, NULL, g_inst, NULL );
    
    EditNum1 = CreateWindowEx (
        WS_EX_CLIENTEDGE,"EDIT","a",
        WS_VISIBLE|WS_CHILD|WS_BORDER|ES_RIGHT ,
        90, 80, 200, 30,
        hwnd,NULL,g_inst,NULL);
        
    EditNum2 = CreateWindowEx (
        WS_EX_CLIENTEDGE,"EDIT", "",
        WS_VISIBLE|WS_CHILD|WS_BORDER,
        370, 80, 200, 30,
        hwnd, NULL, g_inst, NULL );
    
    EditNum3 = CreateWindowEx (
        WS_EX_CLIENTEDGE,"EDIT","",
        WS_VISIBLE|WS_CHILD|WS_BORDER|ES_RIGHT ,
        90, 120, 200, 30,
        hwnd,NULL,g_inst,NULL);
        
    EditNum4 = CreateWindowEx (
        WS_EX_CLIENTEDGE,"EDIT", "",
        WS_VISIBLE|WS_CHILD|WS_BORDER,
        370, 120, 200, 30,
        hwnd, NULL, g_inst, NULL );
        
        
    EditNum5 = CreateWindowEx (
        WS_EX_CLIENTEDGE,"EDIT","",
        WS_VISIBLE|WS_CHILD|WS_BORDER|ES_RIGHT ,
        90, 160, 200, 30,
        hwnd,NULL,g_inst,NULL);
        
    EditNum6 = CreateWindowEx (
        WS_EX_CLIENTEDGE,"EDIT", "",
        WS_VISIBLE|WS_CHILD|WS_BORDER,
        370, 160, 200, 30,
        hwnd, NULL, g_inst, NULL );
    
        
    Login = CreateWindowEx (
        0, "BUTTON", "Login",
        WS_VISIBLE|WS_CHILD,
        90, 220, 200, 30,
        hwnd,(HMENU)ID_Login, g_inst, NULL);
        
    Cadastrar = CreateWindowEx (
        0, "BUTTON", "Cadastrar",
        WS_VISIBLE|WS_CHILD,
        370, 220, 200, 30,
        hwnd,(HMENU)ID_Cadastrar, g_inst, NULL);

    SendMessage((HWND) EditNum1,(UINT) WM_SETFONT,(WPARAM) 0,(LPARAM) lParam);
    SendMessage((HWND) EditNum2,(UINT) WM_SETFONT, (WPARAM) 0,(LPARAM) lParam);
    SendMessage((HWND) EditNum3,(UINT) WM_SETFONT,(WPARAM) 0,(LPARAM) lParam);
    SendMessage((HWND) EditNum4,(UINT) WM_SETFONT, (WPARAM) 0,(LPARAM) lParam);
    SendMessage((HWND) EditNum5,(UINT) WM_SETFONT,(WPARAM) 0,(LPARAM) lParam);
    SendMessage((HWND) EditNum6,(UINT) WM_SETFONT, (WPARAM) 0,(LPARAM) lParam);
    SendMessage((HWND) EditTotal,(UINT) WM_SETFONT, (WPARAM) 0,(LPARAM) lParam);

    SendMessage((HWND) Login,(UINT) WM_SETFONT, (WPARAM) 0,(LPARAM) lParam);
    SendMessage((HWND) Cadastrar,(UINT) WM_SETFONT, (WPARAM) 0,(LPARAM) lParam);
}

char nome1[200] [50], email1[200] [50],senha1[200] [50], nome2[200] [50], email2[200] [50], senha2[200] [50];
int linha, i;

LRESULT CALLBACK WndProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam) {
    switch(message) {
        case WM_CREATE: 
            DesenharObjectos(hwnd,message,wParam,lParam);
        break;
        case WM_COMMAND:
            
            if ((HIWORD(wParam) == BN_CLICKED))
            {

                SendMessage((HWND)EditNum1,(UINT)EM_GETLINE,(WPARAM)1,(LPARAM) &nome1);

                SendMessage((HWND)EditNum2,(UINT)EM_GETLINE,(WPARAM)1,(LPARAM) &email1);
                
                SendMessage((HWND)EditNum3,(UINT)EM_GETLINE,(WPARAM)1,(LPARAM) &senha1);

                SendMessage((HWND)EditNum4,(UINT)EM_GETLINE,(WPARAM)1,(LPARAM) &nome2);
                
                SendMessage((HWND)EditNum5,(UINT)EM_GETLINE,(WPARAM)1,(LPARAM) &email2);

                SendMessage((HWND)EditNum6,(UINT)EM_GETLINE,(WPARAM)1,(LPARAM) &senha2);

                   //valor1 = atof(s_valor1);
                //valor2 = atof(s_valor2);

                switch (LOWORD(wParam))
                {
                    case ID_Login:
                        for(i=0;i<200;i++){
                           if(nome1[i]==nome2){
                                 if(email1[i]==email2){
                                      if(senha1[i]==senha2){
                                           Conta Bancaria();
                                      }
                                 }
                           }
                       }
                    break;
                    case ID_Cadastrar:
                        FILE *farq;
                do{
                    farq = fopen("arqtexto.txt","a");
    
                    fprintf(farq, "%s \n", &nome1[linha]);
                    fprintf(farq, "%s \n", &email1[linha]);
                    fprintf(farq, "%d \n", &senha1[linha]);
    
                    fclose(farq);
                    linha++;
                }while(op==1);
                    break;    
                }

                //ftoa(total,s_total,2);

                SendMessage((HWND) EditTotal, (UINT) WM_SETTEXT, (WPARAM) 0, (LPARAM) &s_total);

            }
            
        break;    
        /* Upon destruction, tell the main thread to stop */
        case WM_DESTROY: {
            PostQuitMessage(0);
            break;
        }
        
        /* Todas as outras mensagens (muitas delas) são processadas usando procedimentos padrão */
        default:
            return DefWindowProc(hwnd, message, wParam, lParam);
    }
    return 0;
}
 

>

 

< 

#include <windows.h>
#include <math.h>
#include "resource.h"

void reverse(char* str, int len)
{
    int i = 0, j = len - 1, temp;
    while (i < j) {
        temp = str[i];
        str[i] = str[j];
        str[j] = temp;
        i++;
        j--;
    }
}
  
// Converte um determinado inteiro x em string str []. 
// d é o número de dígitos exigidos na saída. 
// Se d for mais do que o número de dígitos em x, 
// então 0s são adicionados no início.
int intToStr(int x, char str[], int d)
{
    int i = 0;
    while (x) {
        str[i++] = (x % 10) + '0';
        x = x / 10;
    }
  
    // Se o número de dígitos necessários for maior, então
    // adicione 0s no início
    while (i < d)
        str[i++] = '0';
  
    reverse(str, i);
    str[i] = '\0';
    return i;
}
  
// Converte um número de ponto flutuante / duplo em uma string.
void ftoa(float n, char* res, int afterpoint)
{
    // Extrair parte inteira
    int ipart = (int)n;
  
    // Extrair parte flutuante
    float fpart = n - (float)ipart;
  
    // converter parte inteira em string
    int i = intToStr(ipart, res, 0);
  
    // verifique a opção de exibição após o ponto
    if (afterpoint != 0) {
        res[i] = '.'; // add dot
  
        // Obtenha o valor da parte da fração até o nº fornecido.
        // de pontos após o ponto. O terceiro parâmetro
        // é necessário para lidar com casos como 233,007
        fpart = fpart * pow(10, afterpoint);
  
        intToStr((int)fpart, res + i + 1, afterpoint);
    }
}

/*Este é o lugar onde todas as entradas para a janela vão para */
LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM); 


/* A função 'principal' dos programas GUI Win32: é aqui que a execução começa */
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpszArgument, int nCmdShow) {
    WNDCLASSEX wc; /* Uma estrutura de propriedades da nossa janela*/
    HWND hwnd; /*Um 'HANDLE', daí o H, ou um ponteiro para nossa janela*/
    MSG msg; /* A temporary location for all messages */

    /* zero out the struct and set the stuff we want to modify */
    wc.hInstance     = hInstance;
    wc.lpszClassName = "WindowClass";
    wc.lpfnWndProc     = WndProc; /* This is where we will send messages to */
    wc.style = CS_DBLCLKS;
    wc.cbSize = sizeof (WNDCLASSEX);
    
    wc.hIcon         = LoadIcon(hInstance, IDI_ICON); /* Load a standard icon */
    wc.hIconSm         = LoadIcon(NULL, IDI_APPLICATION); /* use the name "A" to use the project icon */
    wc.hCursor         = LoadCursor(NULL, IDC_ARROW);
    wc.lpszMenuName= NULL;
    wc.cbClsExtra = 0;
    wc.cbWndExtra = 0;
    
    /* White, COLOR_WINDOW is just a #define for a system color, try Ctrl+Clicking it */
    wc.hbrBackground = (HBRUSH)(COLOR_WINDOW+1);    
    
    if(!RegisterClassEx(&wc)) {
        MessageBox(NULL, "Window Registration Failed!","Error!",MB_ICONEXCLAMATION|MB_OK);
        return 0;
    }

    hwnd = CreateWindowEx(0,"WindowClass","Conta Bancaria",WS_OVERLAPPEDWINDOW,
        350, /* x */
        350, /* y */
        640, /* width */
        480, /* height */
        HWND_DESKTOP,NULL,hInstance,NULL);
    
    ShowWindow (hwnd, nCmdShow);

    /*
        Este é o coração do nosso programa onde todas as entradas são processadas e
        enviado para WndProc. Observe que GetMessage bloqueia o fluxo de código até receber algo, então
        este loop não produzirá um uso de CPU excessivamente alto
    */
    while(GetMessage(&msg, NULL, 0, 0)) 
    { /* If no error is received... */
        TranslateMessage(&msg); /* Translate key codes to chars if present */
        DispatchMessage(&msg); /* Send it to WndProc */
    }
    return msg.wParam;
}
#define ID_Depositar 1001
#define ID_Sacar 1002

HINSTANCE g_inst;
HWND EditNum1,EditNum2,EditTotal,Depositar,Sacar;

void DesenharObjectos(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
{
    EditNum1 = CreateWindowEx (
        WS_EX_CLIENTEDGE,"EDIT","",
        WS_VISIBLE|WS_CHILD|WS_BORDER|ES_RIGHT ,
        20, 120, 200, 30,
        hwnd,NULL,g_inst,NULL);
        
    EditNum2 = CreateWindowEx (
        WS_EX_CLIENTEDGE,"EDIT", "",
        WS_VISIBLE|WS_CHILD|WS_BORDER,
        260, 120, 200, 30,
        hwnd, NULL, g_inst, NULL );

    EditTotal = CreateWindowEx (
        WS_EX_CLIENTEDGE,"EDIT", "",
        WS_VISIBLE|WS_CHILD|WS_BORDER,
        400, 20, 200, 30,
        hwnd, NULL, g_inst, NULL );
        
    Depositar = CreateWindowEx (
        0, "BUTTON", "Depositar",
        WS_VISIBLE|WS_CHILD,
        20, 160, 200, 30,
        hwnd,(HMENU)ID_Depositar, g_inst, NULL);
        
    Sacar = CreateWindowEx (
        0, "BUTTON", "Sacar",
        WS_VISIBLE|WS_CHILD,
        260, 160, 200, 30,
        hwnd,(HMENU)ID_Sacar, g_inst, NULL);

    SendMessage((HWND) EditNum1,(UINT) WM_SETFONT,(WPARAM) 0,(LPARAM) lParam);
    SendMessage((HWND) EditNum2,(UINT) WM_SETFONT, (WPARAM) 0,(LPARAM) lParam);
    SendMessage((HWND) EditTotal,(UINT) WM_SETFONT, (WPARAM) 0,(LPARAM) lParam);

    SendMessage((HWND) Depositar,(UINT) WM_SETFONT, (WPARAM) 0,(LPARAM) lParam);
    SendMessage((HWND) Sacar,(UINT) WM_SETFONT, (WPARAM) 0,(LPARAM) lParam);
}

char s_valor1[20] = "0", s_valor2[20] = "0", s_total[20] = "0";
float valor1, valor2, total, novoDeposito, novoSacar;

LRESULT CALLBACK WndProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam) {
    switch(message) {
        case WM_CREATE: 
            DesenharObjectos(hwnd,message,wParam,lParam);
        break;
        case WM_COMMAND:
            
            if ((HIWORD(wParam) == BN_CLICKED))
            {

                SendMessage((HWND)EditNum1,(UINT)EM_GETLINE,(WPARAM)1,(LPARAM) &s_valor1);

                SendMessage((HWND)EditNum2,(UINT)EM_GETLINE,(WPARAM)1,(LPARAM) &s_valor2);

                   valor1 = atof(s_valor1);
                valor2 = atof(s_valor2);

                switch (LOWORD(wParam))
                {
                    case ID_Depositar:
                        if(valor1>0){
                        MessageBox (NULL,"Parabens Deposito efetuado com sucesso \n voce acabou de Depositar", "Resultado", MB_OK);
                        novoDeposito = total;
                        novoDeposito = total + valor1;
                        total = novoDeposito;
                        SendMessage((HWND)EditNum1,(UINT)WM_SETTEXT,(WPARAM)1,(LPARAM) "");
                    }else{
                        MessageBox (NULL, "Erro Digite um valor", "Resultado", MB_OK);
                    }
                    break;
                    case ID_Sacar:
                        if(valor2<=total){
                            
                        MessageBox (NULL,"Parabens Saque efetuado com sucesso \n voce acabou de Sacar", "Resultado", MB_OK);
                        novoSacar = total;
                        novoSacar = total - valor2;
                        total = novoSacar;
                        SendMessage((HWND)EditNum2,(UINT)WM_SETTEXT,(WPARAM)1,(LPARAM) "");
                    }else if(valor2>total){
                        MessageBox (NULL, "Saldo insuficiente", "Resultado", MB_OK);
                        SendMessage((HWND)EditNum2,(UINT)WM_SETTEXT,(WPARAM)1,(LPARAM) "");
                    }else{
                        MessageBox (NULL, "Erro", "Resultado", MB_OK);
                    }
                    break;    
                }

                ftoa(total,s_total,2);

                SendMessage((HWND) EditTotal, (UINT) WM_SETTEXT, (WPARAM) 0, (LPARAM) &s_total);

            }
            
        break;    
        /* Upon destruction, tell the main thread to stop */
        case WM_DESTROY: {
            PostQuitMessage(0);
            break;
        }
        
        /* Todas as outras mensagens (muitas delas) são processadas usando procedimentos padrão */
        default:
            return DefWindowProc(hwnd, message, wParam, lParam);
    }
    return 0;
}

 

 

Link para o comentário
Compartilhar em outros sites

Crie uma conta ou entre para comentar

Você precisa ser um usuário 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 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

×
×
  • Criar novo...

 

GRÁTIS: ebook Redes Wi-Fi – 2ª Edição

EBOOK GRÁTIS!

CLIQUE AQUI E BAIXE AGORA MESMO!