Ir ao conteúdo
  • Cadastre-se

kisne

Membro Júnior
  • Posts

    9
  • Cadastrado em

  • Última visita

Reputação

3
  1. <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; } >
  2. kisne

    C Erro ftoa não definido

    um circuito oscilado usando capacitor e um indutor sim, eu uso o dev c++ valeu ai pela ajuda, eu uso o dev c++
  3. Esto desenvolvendo para fim didático uma interface que calcula um capacitor e indutor pra me dar o valor da frequência no código bota para fazer a transformação de string para ponto flutuante depois de volta para string no meu código vem esses erros C:\Users\Kisne\AppData\Local\Temp\cc1sZSvM.o Calculos eletronicos e eletricos.c:(.text+0x433): undefined reference to `_imp__GetStockObject@4' C:\Users\Kisne\AppData\Local\Temp\cc1sZSvM.o Calculos eletronicos e eletricos.c:(.text+0x46b): undefined reference to `_imp__GetStockObject@4' C:\Users\Kisne\AppData\Local\Temp\cc1sZSvM.o Calculos eletronicos e eletricos.c:(.text+0x4a3): undefined reference to `_imp__GetStockObject@4' C:\Users\Kisne\AppData\Local\Temp\cc1sZSvM.o Calculos eletronicos e eletricos.c:(.text+0x4db): undefined reference to `_imp__GetStockObject@4' C:\Users\Kisne\AppData\Local\Temp\cc1sZSvM.o Calculos eletronicos e eletricos.c:(.text+0x62f): undefined reference to `ftoa' C:\Users\Kisne\Documents\Novos projetos c\collect2.exe [Error] ld returned 1 exit status aqui está meu código, pelo amor de Deus alguém pode me da um alô. #include <Windows.h> #include <stdlib.h> #include <math.h> #include <stdio.h> LRESULT CALLBACK WindowProcedure (HWND, UINT, WPARAM, LPARAM); int WINAPI WinMain (HINSTANCE hThisInstance, HINSTANCE hPrevInstance, LPSTR lpszArgument, int nFunsterStil) { HWND hwnd; MSG messages; WNDCLASSEX wincl; wincl.hInstance = hThisInstance; wincl.lpszClassName = "WindowsApp"; 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) COLOR_BACKGROUND; if (!RegisterClassEx (&wincl)) return 0; hwnd = CreateWindowEx ( 0, "WindowsApp", "Calculadora", WS_OVERLAPPEDWINDOW, 350, 250, 320, 300, HWND_DESKTOP, NULL, hThisInstance, NULL ); ShowWindow (hwnd, nFunsterStil); while (GetMessage (&messages, NULL, 0, 0)) { TranslateMessage(&messages); DispatchMessage(&messages); } return messages.wParam; } #define ID_BUTTONok 1001 HINSTANCE g_inst; HWND EditNum1,EditNum2,EditTotal,ButtonOk; 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, 30, 100, 20, hwnd,NULL,g_inst,NULL); EditNum2 = CreateWindowEx ( WS_EX_CLIENTEDGE,"EDIT", "", WS_VISIBLE|WS_CHILD|WS_BORDER, 20, 50, 100, 20, hwnd, NULL, g_inst, NULL ); EditTotal = CreateWindowEx ( WS_EX_CLIENTEDGE,"EDIT", "", WS_VISIBLE|WS_CHILD|WS_BORDER, 160, 30, 100, 20, hwnd, NULL, g_inst, NULL ); CreateWindowEx ( 0,"STATIC","H", WS_VISIBLE|WS_CHILD, 5, 30, 10, 20, hwnd,NULL,g_inst,NULL); CreateWindowEx ( 0, "STATIC", "C", WS_VISIBLE|WS_CHILD, 5, 50, 10, 20, hwnd,NULL,g_inst, NULL); ButtonOk = CreateWindowEx ( 0, "BUTTON", "OK", WS_VISIBLE|WS_CHILD, 120, 30, 40, 40, hwnd,(HMENU)ID_BUTTONok, g_inst, NULL); SendMessage((HWND) EditNum1,(UINT) WM_SETFONT,(WPARAM) GetStockObject(DEFAULT_GUI_FONT),(LPARAM) lParam); SendMessage((HWND) EditNum2,(UINT) WM_SETFONT, (WPARAM) GetStockObject(DEFAULT_GUI_FONT),(LPARAM) lParam); SendMessage((HWND) EditTotal,(UINT) WM_SETFONT, (WPARAM) GetStockObject(DEFAULT_GUI_FONT),(LPARAM) lParam); SendMessage((HWND) ButtonOk,(UINT) WM_SETFONT, (WPARAM) GetStockObject(DEFAULT_GUI_FONT),(LPARAM) lParam); } char s_valor1[20] = "0", s_valor2[20] = "0", s_total[20] = "0"; float valor1, valor2, total; LRESULT CALLBACK WindowProcedure (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_BUTTONok: total = (1/(6.28*(sqrt(valor1 * valor2)))); break; } total = ftoa(s_total); SendMessage( (HWND) EditTotal, (UINT) WM_SETTEXT, (WPARAM) 0, (LPARAM) &s_total ); } break; case WM_DESTROY: PostQuitMessage (0); break; default: return DefWindowProc (hwnd, message, wParam, lParam); } return 0; }
  4. kisne

    C Raiz quadrada

    Nao porque por me darem as raizes que sao exatas em decimal eu quero separado exato com resultado exato e os nao como sao, em decimais. Mais uma vez muito obrigado por me responder
  5. kisne

    C Raiz quadrada

    Opa, obrigado por me responder bem essa parte do código que quando difere do zero ele faz outra equaçao para calcula a parte fracionaria dos que nao tem raiz exata. if(a==0){ return n; }else { int b= a*100; // b equivalente a * 100 int k = 0; // int c= (n*20)+1; // c é o n transformado em equivalente ao i while (b>=c){ b=b-c; c=c+2; k=k+1; } float e= k/(float)10; float d= n + e; printf("A Raiz Quadrada é %f\n", d); } } O código anterior quando nao tinha a chamada a funçao raiz me dava os calculos normais, só quando criei essa funcao fora do main vem os resultados em float e logo abaixo em inteiro só que nao era pra vim nada, e vem um numero nada ver.
  6. kisne

    C Raiz quadrada

    Olá, bom dia sou um entusiasta em programação preciso de uma ajuda, sei que esse tópico tem já um tempo eu tenho um código que me da a raiz quadrada de um numero sendo ele raiz inteira ou decimais só que no resultado das decimais ele me da o decimal e um segundo resultado inteiro errada alguém pode me da um alo onde estou errando #include <stdio.h> #include <stdlib.h> int raiz (int a){ int n=0; /* Código extraido da equaçao de pell da qual permite encontrar a parte inteira de uma Raiz*/ int i=1; /* quadrada simplesmente subtraindo inteiros ímpares. Exemplo: Raiz de 19.*/ while(a>=i){ /* 1. 19 - 1 = 18 Como 3 é menor que 9 a sequencia para aqui*/ a=a-i; /* 2. 18 - 3 = 15 Como 4 subtrações foram efetuadas, entao a*/ i=i+2; /* 3. 15 - 5 = 10 resposta é 4.*/ n=n+1; /* 4. 10 - 7 = 3*/ } } if(a==0){ return n; }else { int b= a*100; // b equivalente a * 100 int k = 0; // int c= (n*20)+1; // c é o n transformado em equivalente ao i while (b>=c){ b=b-c; c=c+2; k=k+1; } float e= k/(float)10; float d= n + e; printf("A Raiz Quadrada é %f\n", d); } } int input( char mensagem[]) { int entrada; printf("%s",mensagem); scanf("%d",&entrada); return entrada; } int main(int argc, char *argv[]) { int valor; while (1) { valor = input("Digite o número para tirar raiz ou 0 para terminar"); if (!valor) break; printf("A Raiz quadrada é %d\n:", raiz(valor)); } return 0; }
  7. Valeu pela resposta, o 0 esqueci quando tava fazendo os botões kkk, é que eu gosto aprende bem do inicio mesmo porque tipo fazendo uma analogia nao tem como você aprender o funcionamento da construçao interna de circuito integrado sem você enteder primeiro de diodo e transistor de quais sao feitos os Cis, por isso prefiro mexer com essas nivell mais baixos, nao sei se to certo mais esses aqui que você cito me das as coisas mais mastigadas .
  8. #include <windows.h> #include <stdlib.h> LRESULT CALLBACK WindowProcedure (HWND, UINT, WPARAM, LPARAM); //função WinMain int WINAPI WinMain (HINSTANCE hThisInstance, HINSTANCE hPrevInstance, LPSTR lpszArgument, int nFunsterStil) { HWND hwnd; //handle MSG messages; //mensagem WNDCLASSEX wincl; //classe wincl.hInstance = hThisInstance; wincl.lpszClassName = "WindowsApp"; 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); //cursor default wincl.lpszMenuName = NULL; wincl.cbClsExtra = 0; wincl.cbWndExtra = 0; wincl.hbrBackground = (HBRUSH) COLOR_BACKGROUND; //cor do background if (!RegisterClassEx (&wincl)) return 0; hwnd = CreateWindowEx ( //criar a janela 0, "WindowsApp", "Calculadora", //titulo da janela WS_OVERLAPPEDWINDOW, //estilo da janela 350, //X em relação ao desktop 250, //y em relação ao desktop 500, //largura da janela 600, //altura da janela HWND_DESKTOP, NULL, hThisInstance, NULL ); ShowWindow (hwnd, nFunsterStil); //mostrar a janela while (GetMessage (&messages, NULL, 0, 0)) { TranslateMessage(&messages); DispatchMessage(&messages); } return messages.wParam; } /* Parte 2 do Tut */ #define ID_BUTTON1 1001 #define ID_BUTTON2 1002 #define ID_BUTTON3 1003 #define ID_BUTTONdividir 1010 #define ID_BUTTON4 1004 #define ID_BUTTON5 1005 #define ID_BUTTON6 1006 #define ID_BUTTONvezes 1011 #define ID_BUTTON7 1007 #define ID_BUTTON8 1008 #define ID_BUTTON9 1009 #define ID_BUTTONmenos 1012 #define ID_BUTTONporcentagem 1013 #define ID_BUTTONponto 1014 #define ID_BUTTONmais 1015 #define ID_BUTTONigual 1016 HINSTANCE g_inst; HWND EditTotal,Button1,Button2,Button3,ButtonDividir,Button4,Button5,Button6,ButtonVezes,Button7,Button8,Button9,ButtonMenos,ButtonPorcentagem,ButtonPonto,ButtonMais,ButtonIgual; //esta função só serve para criar o conteudo dentro da janela principal (nao tem retorno) //irá criar duas EDITs e 4 BUTTONS, e mudar os respectivos tipos de letra de cada um void DesenharObjectos(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam) { EditTotal = CreateWindowEx ( WS_EX_CLIENTEDGE,"EDIT", "", WS_VISIBLE|WS_CHILD, 30, 30, 400, 150, hwnd, NULL, g_inst, NULL ); Button1 = CreateWindowEx ( WS_EX_CLIENTEDGE, "BUTTON", "1", WS_VISIBLE|WS_CHILD, 30, 200, 50, 50, hwnd,(HMENU)ID_BUTTON1,g_inst,NULL); Button2 = CreateWindowEx ( WS_EX_CLIENTEDGE, "BUTTON", "2", WS_VISIBLE|WS_CHILD, 90, 200, 50, 50, hwnd,(HMENU)ID_BUTTON2,g_inst,NULL); Button3 = CreateWindowEx ( WS_EX_CLIENTEDGE, "BUTTON", "3", WS_VISIBLE|WS_CHILD, 150, 200, 50, 50, hwnd,(HMENU)ID_BUTTON3,g_inst,NULL); ButtonDividir = CreateWindowEx ( WS_EX_CLIENTEDGE, "BUTTON", "/", WS_VISIBLE|WS_CHILD, 250, 200, 50, 50, hwnd,(HMENU)ID_BUTTONdividir, g_inst, NULL); Button4 = CreateWindowEx ( WS_EX_CLIENTEDGE, "BUTTON", "4", WS_VISIBLE|WS_CHILD, 30, 260, 50, 50, hwnd, (HMENU)ID_BUTTON4,g_inst,NULL); Button5 = CreateWindowEx ( WS_EX_CLIENTEDGE, "BUTTON", "5", WS_VISIBLE|WS_CHILD, 90, 260, 50, 50, hwnd,(HMENU)ID_BUTTON5,g_inst,NULL); Button6 = CreateWindowEx ( WS_EX_CLIENTEDGE,"BUTTON", "6", WS_VISIBLE|WS_CHILD, 150, 260, 50, 50, hwnd,(HMENU)ID_BUTTON6,g_inst,NULL); ButtonVezes = CreateWindowEx ( WS_EX_CLIENTEDGE,"BUTTON", "*", WS_VISIBLE|WS_CHILD, 250, 260, 50, 50, hwnd,(HMENU)ID_BUTTONvezes,g_inst, NULL ); Button7 = CreateWindowEx ( WS_EX_CLIENTEDGE, "BUTTON", "7", WS_VISIBLE|WS_CHILD, 30, 320, 50, 50, hwnd,(HMENU)ID_BUTTON7,g_inst,NULL); Button8 = CreateWindowEx ( WS_EX_CLIENTEDGE, "BUTTON", "8", WS_VISIBLE|WS_CHILD, 90, 320, 50, 50, hwnd,(HMENU)ID_BUTTON8,g_inst,NULL); Button9 = CreateWindowEx ( WS_EX_CLIENTEDGE, "BUTTON", "9", WS_VISIBLE|WS_CHILD, 150, 320, 50, 50, hwnd,(HMENU)ID_BUTTON9,g_inst,NULL); ButtonMenos = CreateWindowEx ( WS_EX_CLIENTEDGE, "BUTTON", "-", WS_VISIBLE|WS_CHILD, 250, 320, 50, 50, hwnd,(HMENU)ID_BUTTONmenos,g_inst,NULL); ButtonPorcentagem = CreateWindowEx ( WS_EX_CLIENTEDGE, "BUTTON", "%", WS_VISIBLE|WS_CHILD, 30, 380, 50, 50, hwnd,(HMENU)ID_BUTTONporcentagem,g_inst,NULL); ButtonPonto = CreateWindowEx ( WS_EX_CLIENTEDGE, "BUTTON", ".", WS_VISIBLE|WS_CHILD, 90, 380, 50, 50,hwnd,(HMENU)ID_BUTTONponto,g_inst, NULL); ButtonMais = CreateWindowEx ( WS_EX_CLIENTEDGE, "BUTTON", "+", WS_VISIBLE|WS_CHILD, 150, 380, 50, 50, hwnd,(HMENU)ID_BUTTONmais,g_inst,NULL); ButtonIgual = CreateWindowEx ( WS_EX_CLIENTEDGE, "BUTTON", "=", WS_VISIBLE|WS_CHILD, 250, 380, 50, 50, hwnd,(HMENU)ID_BUTTONigual,g_inst,NULL); SendMessage((HWND) EditTotal,(UINT) WM_SETFONT, (WPARAM) 0,(LPARAM) lParam); SendMessage((HWND) Button1,(UINT) WM_SETFONT, (WPARAM) 0,(LPARAM) lParam); SendMessage((HWND) Button2,(UINT) WM_SETFONT, (WPARAM) 0,(LPARAM) lParam); SendMessage((HWND) Button3,(UINT) WM_SETFONT, (WPARAM) 0,(LPARAM) lParam); SendMessage((HWND) ButtonDividir,(UINT) WM_SETFONT, (WPARAM) 0,(LPARAM) lParam); SendMessage((HWND) Button4,(UINT) WM_SETFONT, (WPARAM) 0,(LPARAM) lParam); SendMessage((HWND) Button5,(UINT) WM_SETFONT, (WPARAM) 0,(LPARAM) lParam); SendMessage((HWND) Button6,(UINT) WM_SETFONT, (WPARAM) 0,(LPARAM) lParam); SendMessage((HWND) ButtonVezes,(UINT) WM_SETFONT, (WPARAM) 0,(LPARAM) lParam); SendMessage((HWND) Button7,(UINT) WM_SETFONT, (WPARAM) 0,(LPARAM) lParam); SendMessage((HWND) Button8,(UINT) WM_SETFONT, (WPARAM) 0,(LPARAM) lParam); SendMessage((HWND) Button9,(UINT) WM_SETFONT, (WPARAM) 0,(LPARAM) lParam); SendMessage((HWND) ButtonMenos,(UINT) WM_SETFONT, (WPARAM) 0,(LPARAM) lParam); SendMessage((HWND) ButtonPorcentagem,(UINT) WM_SETFONT, (WPARAM) 0,(LPARAM) lParam); SendMessage((HWND) ButtonPonto,(UINT) WM_SETFONT, (WPARAM) 0,(LPARAM) lParam); SendMessage((HWND) ButtonMais,(UINT) WM_SETFONT, (WPARAM) 0,(LPARAM) lParam); SendMessage((HWND) ButtonIgual,(UINT) WM_SETFONT, (WPARAM) 0,(LPARAM) lParam); } //Parte 3 do Tut int a = 1; char s_valor1[20] = "0", s_valor2[20] = "0", s_total[20] = "0"; int valor1, valor2, total; //função WindowProcedure LRESULT CALLBACK WindowProcedure (HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam) { switch (message) { case WM_CREATE: //Parte 2 do Tut DesenharObjectos(hwnd,message,wParam,lParam); break; case WM_COMMAND: /* Parte 3 do Tut */ if ((HIWORD(wParam) == BN_CLICKED)) { switch (LOWORD(wParam)) { case ID_BUTTON1: Button1; break; case ID_BUTTON2: Button2; break; case ID_BUTTON3: Button3; break; case ID_BUTTONdividir: ButtonDividir; break; case ID_BUTTON4: Button4; break; case ID_BUTTON5: Button5; break; case ID_BUTTON6: Button6; break; case ID_BUTTONvezes: ButtonVezes; break; case ID_BUTTON7: Button7; break; case ID_BUTTON8: Button8; break; case ID_BUTTON9: Button9; break; case ID_BUTTONmenos: ButtonMenos; break; case ID_BUTTONporcentagem: ButtonPorcentagem; break; case ID_BUTTONponto: ButtonPonto; break; case ID_BUTTONmais: ButtonMais; break; case ID_BUTTONigual: ButtonIgual; break; } SendMessage( (HWND) EditTotal, (UINT) WM_SETTEXT, (WPARAM) 0, (LPARAM) &s_valor1 ); SendMessage((HWND)valor1,(UINT)EM_GETLINE,(WPARAM)1,(LPARAM) &s_valor1); switch (LOWORD(wParam)) { case ID_BUTTON1: Button1; break; case ID_BUTTON2: Button2; break; case ID_BUTTON3: Button3; break; case ID_BUTTONdividir: ButtonDividir; break; case ID_BUTTON4: Button4; break; case ID_BUTTON5: Button5; break; case ID_BUTTON6: Button6; break; case ID_BUTTONvezes: ButtonVezes; break; case ID_BUTTON7: Button7; break; case ID_BUTTON8: Button8; break; case ID_BUTTON9: Button9; break; case ID_BUTTONmenos: ButtonMenos; break; case ID_BUTTONporcentagem: ButtonPorcentagem; break; case ID_BUTTONponto: ButtonPonto; break; case ID_BUTTONmais: ButtonMais; break; case ID_BUTTONigual: ButtonIgual; break; } SendMessage((HWND)valor2,(UINT)EM_GETLINE,(WPARAM)1,(LPARAM) &s_valor2); valor1 = atoi(s_valor1); valor2 = atoi(s_valor2); switch (LOWORD(wParam)) { case ID_BUTTONmais: total = valor1+valor2; break; case ID_BUTTONmenos: total = valor1-valor2; break; case ID_BUTTONvezes: total = valor1*valor2; break; case ID_BUTTONdividir: total = valor1 / valor2; break; } //switch (LOWORD(wParam)) itoa (total,s_total,10); SendMessage( (HWND) EditTotal, (UINT) WM_SETTEXT, (WPARAM) 0, (LPARAM) &s_total ); } //if ((HIWORD(wParam) == BN_CLICKED)) break; case WM_DESTROY: PostQuitMessage (0); break; default: return DefWindowProc (hwnd, message, wParam, lParam); }//switch (message) return 0; } Ola, sou bem iniciante em programaçao queria saber se alguem poderia me dar uma ajuda to com esse código em que a janela e os botões ta tudo certo mas to com dificuldades na parte de comando, em que eu uso apenas uma editbox , e cada botao clicado apareça o numero e o operador escolido la e a apertar o botao "igual" venha o resultado como uma calculadora mesmo. alguem poderia me ajudar nessa parte do código uso o devc++. < #include <windows.h> #include <stdlib.h> LRESULT CALLBACK WindowProcedure (HWND, UINT, WPARAM, LPARAM); //função WinMain int WINAPI WinMain (HINSTANCE hThisInstance, HINSTANCE hPrevInstance, LPSTR lpszArgument, int nFunsterStil) { HWND hwnd; //handle MSG messages; //mensagem WNDCLASSEX wincl; //classe wincl.hInstance = hThisInstance; wincl.lpszClassName = "WindowsApp"; 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); //cursor default wincl.lpszMenuName = NULL; wincl.cbClsExtra = 0; wincl.cbWndExtra = 0; wincl.hbrBackground = (HBRUSH) COLOR_BACKGROUND; //cor do background if (!RegisterClassEx (&wincl)) return 0; hwnd = CreateWindowEx ( //criar a janela 0, "WindowsApp", "Calculadora", //titulo da janela WS_OVERLAPPEDWINDOW, //estilo da janela 350, //X em relação ao desktop 250, //y em relação ao desktop 500, //largura da janela 600, //altura da janela HWND_DESKTOP, NULL, hThisInstance, NULL ); ShowWindow (hwnd, nFunsterStil); //mostrar a janela while (GetMessage (&messages, NULL, 0, 0)) { TranslateMessage(&messages); DispatchMessage(&messages); } return messages.wParam; } /* Parte 2 do Tut */ #define ID_BUTTON1 1001 #define ID_BUTTON2 1002 #define ID_BUTTON3 1003 #define ID_BUTTONdividir 1010 #define ID_BUTTON4 1004 #define ID_BUTTON5 1005 #define ID_BUTTON6 1006 #define ID_BUTTONvezes 1011 #define ID_BUTTON7 1007 #define ID_BUTTON8 1008 #define ID_BUTTON9 1009 #define ID_BUTTONmenos 1012 #define ID_BUTTONporcentagem 1013 #define ID_BUTTONponto 1014 #define ID_BUTTONmais 1015 #define ID_BUTTONigual 1016 HINSTANCE g_inst; HWND EditTotal,Button1,Button2,Button3,ButtonDividir,Button4,Button5,Button6,ButtonVezes,Button7,Button8,Button9,ButtonMenos,ButtonPorcentagem,ButtonPonto,ButtonMais,ButtonIgual; //esta função só serve para criar o conteudo dentro da janela principal (nao tem retorno) //irá criar duas EDITs e 4 BUTTONS, e mudar os respectivos tipos de letra de cada um void DesenharObjectos(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam) { EditTotal = CreateWindowEx ( WS_EX_CLIENTEDGE,"EDIT", "", WS_VISIBLE|WS_CHILD, 30, 30, 400, 150, hwnd, NULL, g_inst, NULL ); Button1 = CreateWindowEx ( WS_EX_CLIENTEDGE, "BUTTON", "1", WS_VISIBLE|WS_CHILD, 30, 200, 50, 50, hwnd,(HMENU)ID_BUTTON1,g_inst,NULL); Button2 = CreateWindowEx ( WS_EX_CLIENTEDGE, "BUTTON", "2", WS_VISIBLE|WS_CHILD, 90, 200, 50, 50, hwnd,(HMENU)ID_BUTTON2,g_inst,NULL); Button3 = CreateWindowEx ( WS_EX_CLIENTEDGE, "BUTTON", "3", WS_VISIBLE|WS_CHILD, 150, 200, 50, 50, hwnd,(HMENU)ID_BUTTON3,g_inst,NULL); ButtonDividir = CreateWindowEx ( WS_EX_CLIENTEDGE, "BUTTON", "/", WS_VISIBLE|WS_CHILD, 250, 200, 50, 50, hwnd,(HMENU)ID_BUTTONdividir, g_inst, NULL); Button4 = CreateWindowEx ( WS_EX_CLIENTEDGE, "BUTTON", "4", WS_VISIBLE|WS_CHILD, 30, 260, 50, 50, hwnd, (HMENU)ID_BUTTON4,g_inst,NULL); Button5 = CreateWindowEx ( WS_EX_CLIENTEDGE, "BUTTON", "5", WS_VISIBLE|WS_CHILD, 90, 260, 50, 50, hwnd,(HMENU)ID_BUTTON5,g_inst,NULL); Button6 = CreateWindowEx ( WS_EX_CLIENTEDGE,"BUTTON", "6", WS_VISIBLE|WS_CHILD, 150, 260, 50, 50, hwnd,(HMENU)ID_BUTTON6,g_inst,NULL); ButtonVezes = CreateWindowEx ( WS_EX_CLIENTEDGE,"BUTTON", "*", WS_VISIBLE|WS_CHILD, 250, 260, 50, 50, hwnd,(HMENU)ID_BUTTONvezes,g_inst, NULL ); Button7 = CreateWindowEx ( WS_EX_CLIENTEDGE, "BUTTON", "7", WS_VISIBLE|WS_CHILD, 30, 320, 50, 50, hwnd,(HMENU)ID_BUTTON7,g_inst,NULL); Button8 = CreateWindowEx ( WS_EX_CLIENTEDGE, "BUTTON", "8", WS_VISIBLE|WS_CHILD, 90, 320, 50, 50, hwnd,(HMENU)ID_BUTTON8,g_inst,NULL); Button9 = CreateWindowEx ( WS_EX_CLIENTEDGE, "BUTTON", "9", WS_VISIBLE|WS_CHILD, 150, 320, 50, 50, hwnd,(HMENU)ID_BUTTON9,g_inst,NULL); ButtonMenos = CreateWindowEx ( WS_EX_CLIENTEDGE, "BUTTON", "-", WS_VISIBLE|WS_CHILD, 250, 320, 50, 50, hwnd,(HMENU)ID_BUTTONmenos,g_inst,NULL); ButtonPorcentagem = CreateWindowEx ( WS_EX_CLIENTEDGE, "BUTTON", "%", WS_VISIBLE|WS_CHILD, 30, 380, 50, 50, hwnd,(HMENU)ID_BUTTONporcentagem,g_inst,NULL); ButtonPonto = CreateWindowEx ( WS_EX_CLIENTEDGE, "BUTTON", ".", WS_VISIBLE|WS_CHILD, 90, 380, 50, 50,hwnd,(HMENU)ID_BUTTONponto,g_inst, NULL); ButtonMais = CreateWindowEx ( WS_EX_CLIENTEDGE, "BUTTON", "+", WS_VISIBLE|WS_CHILD, 150, 380, 50, 50, hwnd,(HMENU)ID_BUTTONmais,g_inst,NULL); ButtonIgual = CreateWindowEx ( WS_EX_CLIENTEDGE, "BUTTON", "=", WS_VISIBLE|WS_CHILD, 250, 380, 50, 50, hwnd,(HMENU)ID_BUTTONigual,g_inst,NULL); SendMessage((HWND) EditTotal,(UINT) WM_SETFONT, (WPARAM) 0,(LPARAM) lParam); SendMessage((HWND) Button1,(UINT) WM_SETFONT, (WPARAM) 0,(LPARAM) lParam); SendMessage((HWND) Button2,(UINT) WM_SETFONT, (WPARAM) 0,(LPARAM) lParam); SendMessage((HWND) Button3,(UINT) WM_SETFONT, (WPARAM) 0,(LPARAM) lParam); SendMessage((HWND) ButtonDividir,(UINT) WM_SETFONT, (WPARAM) 0,(LPARAM) lParam); SendMessage((HWND) Button4,(UINT) WM_SETFONT, (WPARAM) 0,(LPARAM) lParam); SendMessage((HWND) Button5,(UINT) WM_SETFONT, (WPARAM) 0,(LPARAM) lParam); SendMessage((HWND) Button6,(UINT) WM_SETFONT, (WPARAM) 0,(LPARAM) lParam); SendMessage((HWND) ButtonVezes,(UINT) WM_SETFONT, (WPARAM) 0,(LPARAM) lParam); SendMessage((HWND) Button7,(UINT) WM_SETFONT, (WPARAM) 0,(LPARAM) lParam); SendMessage((HWND) Button8,(UINT) WM_SETFONT, (WPARAM) 0,(LPARAM) lParam); SendMessage((HWND) Button9,(UINT) WM_SETFONT, (WPARAM) 0,(LPARAM) lParam); SendMessage((HWND) ButtonMenos,(UINT) WM_SETFONT, (WPARAM) 0,(LPARAM) lParam); SendMessage((HWND) ButtonPorcentagem,(UINT) WM_SETFONT, (WPARAM) 0,(LPARAM) lParam); SendMessage((HWND) ButtonPonto,(UINT) WM_SETFONT, (WPARAM) 0,(LPARAM) lParam); SendMessage((HWND) ButtonMais,(UINT) WM_SETFONT, (WPARAM) 0,(LPARAM) lParam); SendMessage((HWND) ButtonIgual,(UINT) WM_SETFONT, (WPARAM) 0,(LPARAM) lParam); } //Parte 3 do Tut int a = 1; char s_valor1[20] = "0", s_valor2[20] = "0", s_total[20] = "0"; int valor1, valor2, total; //função WindowProcedure LRESULT CALLBACK WindowProcedure (HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam) { switch (message) { case WM_CREATE: //Parte 2 do Tut DesenharObjectos(hwnd,message,wParam,lParam); break; case WM_COMMAND: /* Parte 3 do Tut */ if ((HIWORD(wParam) == BN_CLICKED)) { switch (LOWORD(wParam)) { case ID_BUTTON1: Button1; break; case ID_BUTTON2: Button2; break; case ID_BUTTON3: Button3; break; case ID_BUTTONdividir: ButtonDividir; break; case ID_BUTTON4: Button4; break; case ID_BUTTON5: Button5; break; case ID_BUTTON6: Button6; break; case ID_BUTTONvezes: ButtonVezes; break; case ID_BUTTON7: Button7; break; case ID_BUTTON8: Button8; break; case ID_BUTTON9: Button9; break; case ID_BUTTONmenos: ButtonMenos; break; case ID_BUTTONporcentagem: ButtonPorcentagem; break; case ID_BUTTONponto: ButtonPonto; break; case ID_BUTTONmais: ButtonMais; break; case ID_BUTTONigual: ButtonIgual; break; } SendMessage( (HWND) EditTotal, (UINT) WM_SETTEXT, (WPARAM) 0, (LPARAM) &s_valor1 ); SendMessage((HWND)valor1,(UINT)EM_GETLINE,(WPARAM)1,(LPARAM) &s_valor1); switch (LOWORD(wParam)) { case ID_BUTTON1: Button1; break; case ID_BUTTON2: Button2; break; case ID_BUTTON3: Button3; break; case ID_BUTTONdividir: ButtonDividir; break; case ID_BUTTON4: Button4; break; case ID_BUTTON5: Button5; break; case ID_BUTTON6: Button6; break; case ID_BUTTONvezes: ButtonVezes; break; case ID_BUTTON7: Button7; break; case ID_BUTTON8: Button8; break; case ID_BUTTON9: Button9; break; case ID_BUTTONmenos: ButtonMenos; break; case ID_BUTTONporcentagem: ButtonPorcentagem; break; case ID_BUTTONponto: ButtonPonto; break; case ID_BUTTONmais: ButtonMais; break; case ID_BUTTONigual: ButtonIgual; break; } SendMessage((HWND)valor2,(UINT)EM_GETLINE,(WPARAM)1,(LPARAM) &s_valor2); valor1 = atoi(s_valor1); valor2 = atoi(s_valor2); switch (LOWORD(wParam)) { case ID_BUTTONmais: total = valor1+valor2; break; case ID_BUTTONmenos: total = valor1-valor2; break; case ID_BUTTONvezes: total = valor1*valor2; break; case ID_BUTTONdividir: total = valor1 / valor2; break; } //switch (LOWORD(wParam)) itoa (total,s_total,10); SendMessage( (HWND) EditTotal, (UINT) WM_SETTEXT, (WPARAM) 0, (LPARAM) &s_total ); } //if ((HIWORD(wParam) == BN_CLICKED)) break; case WM_DESTROY: PostQuitMessage (0); break; default: return DefWindowProc (hwnd, message, wParam, lParam); }//switch (message) 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

×
×
  • Criar novo...