int len = GetWindowTextLength(nome)+1;

int len = GetWindowTextLength(nome)+1;
#if defined(UNICODE) && !defined(_UNICODE) #define _UNICODE #elif defined(_UNICODE) && !defined(UNICODE) #define UNICODE #endif #include <windows.h> #include <math.h> #include <stdio.h> #include <tchar.h> #include <stdlib.h> #include "Frase.h" #define BTN1 1 #define BTN2 2 #define BTN3 3 static HWND nome, nome2, num1, num2, num3, num4, resultado; LRESULT CALLBACK WindowProcedure(HWND, unsigned int, WPARAM, LPARAM); void addMenus(HWND); HMENU hMenu; TCHAR szClassName[ ] = _T("UINT"); int WINAPI WinMain(HINSTANCE hTI,HINSTANCE hPI, LPSTR lpszArgument, int nCmdShow) { HWND hwnd; MSG messages; WNDCLASSEX wincl; memset(&wincl, 0, sizeof(wincl)); wincl.hInstance = hTI; wincl.lpszClassName = szClassName; wincl.lpfnWndProc = WindowProcedure; wincl.style = CS_DBLCLKS; wincl.cbSize = sizeof (WNDCLASSEX); wincl.hIcon = LoadIcon(NULL, IDI_QUESTION); wincl.hIconSm = LoadIcon(NULL, IDI_QUESTION); wincl.hCursor = LoadCursor(NULL, IDC_ARROW); wincl.lpszMenuName = NULL; wincl.cbClsExtra = 0; wincl.cbWndExtra = 0; wincl.hbrBackground = GetSysColorBrush(7); if(!RegisterClassEx (&wincl)) { return 0; } hwnd = CreateWindowEx ( 0, szClassName, _T("GetSysColorBrush"), WS_OVERLAPPEDWINDOW, CW_USEDEFAULT, CW_USEDEFAULT, 1036, 375, HWND_DESKTOP, NULL, hTI, NULL ); ShowWindow(hwnd, nCmdShow); while (GetMessage (&messages, NULL, 0, 0)) { TranslateMessage(&messages); DispatchMessage(&messages); FreeConsole(); } return messages.wParam; } LRESULT CALLBACK WindowProcedure(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam) { switch(msg) { case WM_CREATE: addMenus(hwnd); nome = CreateWindowW( L"static", L"Calcular a Media de 4 Notas", WS_VISIBLE | WS_CHILD, 10, 20, 260, 20, hwnd, NULL, NULL, NULL ); CreateWindow( TEXT("button"), TEXT(" -> "), WS_VISIBLE | WS_CHILD, 10, 90, 80, 40, hwnd, (HMENU) BTN1, NULL, NULL ); CreateWindow(TEXT("button"), TEXT("Arquivo Externo"), WS_VISIBLE | WS_CHILD, 110, 90, 160, 40, hwnd, (HMENU) BTN2, NULL, NULL); nome2 = CreateWindow( TEXT("static"), DANIEL, WS_VISIBLE | WS_CHILD, 10, 180, 1000, 20, hwnd, NULL, NULL, NULL ); CreateWindow( TEXT("static"),"\n\nLinguagem C/C++",WS_VISIBLE|WS_CHILD, 850, 20, 160, 80, hwnd, NULL, NULL, NULL ); CreateWindowW( L"static", L"1 Nota: ", WS_VISIBLE | WS_CHILD, 10, 240, 60, 20, hwnd, NULL, NULL, NULL ); num1 = CreateWindow( TEXT("edit"), TEXT(""), WS_VISIBLE | WS_CHILD | WS_BORDER, 74, 240, 50, 20, hwnd, NULL, NULL, NULL ); CreateWindowW( L"static", L"2 Nota: ", WS_VISIBLE | WS_CHILD, 130, 240, 60, 20, hwnd, NULL, NULL, NULL ); num2 = CreateWindow( TEXT("edit"), TEXT(""), WS_VISIBLE | WS_CHILD | WS_BORDER, 196, 240, 50, 20, hwnd, NULL, NULL, NULL ); CreateWindowW(L"static", L"3 Nota: ", WS_VISIBLE | WS_CHILD, 256, 240, 60, 20, hwnd, NULL, NULL, NULL); num3 = CreateWindow(TEXT("edit"), TEXT(""), WS_VISIBLE | WS_CHILD | WS_BORDER, 322, 240, 50, 20, hwnd, NULL, NULL, NULL); CreateWindowW(L"static", L"4 Nota: ", WS_VISIBLE | WS_CHILD, 386, 240, 60, 20, hwnd, NULL, NULL, NULL); num4 = CreateWindow(TEXT("edit"), TEXT(""), WS_VISIBLE | WS_CHILD | WS_BORDER, 452, 240, 50, 20, hwnd, NULL, NULL, NULL); CreateWindow( TEXT("button"), TEXT("Calcular"), WS_VISIBLE | WS_CHILD | WS_BORDER, 620, 240, 100, 20, hwnd, (HMENU) BTN3, NULL, NULL ); CreateWindow( TEXT("static"), TEXT("Resultado:"), WS_VISIBLE | WS_CHILD, 800, 240, 100, 20, hwnd, NULL, NULL, NULL ); resultado = CreateWindow( TEXT("edit"), TEXT(""), WS_VISIBLE | WS_CHILD, 910, 240, 100, 20, hwnd, NULL, NULL, NULL ); break; case WM_COMMAND: if(LOWORD(wParam)==BTN1) { int len = GetWindowTextLength(nome)+1; static char title[500]; GetWindowText(nome, title, len); MessageBox(NULL, title, "", MB_OK); return 0; } if(LOWORD(wParam)==BTN2) { int com = GetWindowTextLength(nome)+1; static char titulo[500], CON2[200]; GetWindowText(nome2, titulo, com); FILE *fp; fp = fopen("arquivo.txt", "r"); fgets(CON2, 126, fp); MessageBox(NULL, CON2, "", MB_OK); SetWindowText(nome2, CON2); return 0; } if(LOWORD(wParam)==BTN3) { int n1 = GetWindowTextLength(num1)+1; int n2 = GetWindowTextLength(num2)+1; int n3 = GetWindowTextLength(num3)+1; int n4 = GetWindowTextLength(num4)+1; static char t1[50], t2[50], t3[50], t4[50]; GetWindowText(num1, t1, n1); GetWindowText(num2, t2, n2); GetWindowText(num3, t3, n3); GetWindowText(num4, t4, n4); if(atoi(t1)==NULL) { MessageBox(NULL, "Campo 1, vazio!", "Alerta", MB_OK); exit(0); } if(atoi(t2)==NULL) { MessageBox(NULL, "Campo 2, vazio!", "Alerta", MB_OK); exit(0); } if(atoi(t3)==NULL) { MessageBox(NULL, "Campo 3, vazio!", "Alerta", MB_OK); exit(0); } if(atoi(t4)==NULL) { MessageBox(NULL, "Campo 4, vazio!", "Alerta", MB_OK); exit(0); } float res = (atof(t1)+atof(t2)+atof(t3)+atof(t4))/4; char tam[30]; sprintf(tam, "%.2f", res); SetWindowText(resultado, tam); if(atoi(tam) >= 6) { MessageBox(NULL, "Aluno Aprovado", "Condição", MB_OK); } } break; case WM_DESTROY: PostQuitMessage (0); break; default: /* for messages that we don't deal with */ return DefWindowProc(hwnd, msg, wParam, lParam); } return 0; } void addMenus(HWND hwnd) { hMenu = CreateMenu(); HMENU hFileMenu = CreateMenu(); AppendMenu(hMenu, MF_STRING, NULL, "Arquivo"); AppendMenu(hMenu, MF_STRING, NULL, "Ajuda"); AppendMenu(hMenu, MF_STRING, NULL, "Propriedade"); AppendMenu(hMenu, MF_STRING, NULL, "Restart"); AppendMenu(hMenu, MF_STRING, NULL, "Keyboard"); SetMenu(hwnd, hMenu); }

Comentários