Aproveitando as ferias resolvi estudar um pouco API para C só que so iniciante na linguagem estou tendo alguns problemas. Estou tentando fazer o seguinte, o programa vai receber votos para 4 candidatos e armazenar a quantidades de votos e depois calcular a porcentagem. Eis o código. #include <stdio.h>
#include <conio.h>
#include <windows.h>
#include <windowsx.h>
#include <commctrl.h>
#include <string.h>
#include "testeres.h"
static BOOL CALLBACK DialogFunc(HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lParam);
static char voto[1];
static int cont, cont1, cont2, cont3, cont4;
int APIENTRY WinMain(HINSTANCE hinst, HINSTANCE hinstPrev, LPSTR lpCmdLine, int nCmdShow)
{
WNDCLASS wc;
INITCOMMONCONTROLSEX cc;
memset(&wc,0,sizeof(wc));
wc.lpfnWndProc = DefDlgProc;
wc.cbWndExtra = DLGWINDOWEXTRA;
wc.hInstance = hinst;
wc.hCursor = LoadCursor(NULL, IDC_ARROW);
wc.hbrBackground = (HBRUSH) (COLOR_WINDOW + 1);
wc.lpszClassName = "teste";
RegisterClass(&wc);
memset(&cc,0,sizeof(cc));
cc.dwSize = sizeof(cc);
cc.dwICC = 0xffffffff;
InitCommonControlsEx(&cc);
return DialogBox(hinst, MAKEINTRESOURCE(IDD_MAINDIALOG), NULL, (DLGPROC) DialogFunc);
}
static int InitializeApp(HWND hDlg,WPARAM wParam, LPARAM lParam)
{
return 1;
}
int Pegavoto(HWND hwnd)
{
memset(voto,0,sizeof(voto));
if (GetDlgItemText(hwnd, esc, voto, sizeof(voto))) {
return 1;
}
return 0;
}
static BOOL CALLBACK DialogFunc(HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lParam)
{
switch (msg){
case WM_INITDIALOG:
InitializeApp(hwndDlg,wParam,lParam);
return TRUE;
case WM_COMMAND:{
switch (LOWORD(wParam)) {
case IDOK:
if (Pegavoto(hwndDlg))
while(esc != 'F'){
cont = cont + 1;
switch(esc){
case 'V':
cont1 = cont1 + 1;
break;
case 'A':
cont2 = cont2 +1;
break;
case 'N':
cont3 = cont3 + 1;
break;
case 'B':
cont4 = cont4 +1;
break;
}
MessageBox(hwndDlg,voto,"Voto Confirmado",MB_OK);
return 0;
}
case IDCANCEL:{
EndDialog(hwndDlg,0);
return 1;
}
}
break;
case WM_CLOSE:
EndDialog(hwndDlg,0);
return TRUE;
}
}
return FALSE;
} Não estou conseguindo fazer o laço de repetição com a estrutura while. Consegui apenas uma vez mais não estava conseguindo fazer a incrementação dos contadores. Grato, Alvaro Renan.