main.html
#include <windows.h>
#include <stdio.h>
#include <tchar.h>
#include "resource.h"
#pragma comment(lib, "user32.lib")
#define BTN1 1
#define BTN2 2
#define BTN3 3
#define DCS 4
void addMenus(HWND);
static HWND nome, nome2, num1, num2, num3, num4, resultado;
HMENU hMenu;
char txt[] = {"Média Escolar"};
char descricao[] = {
" C para Windows\n C para Linux\n C para App Móveis\n C Padrão ANSI"
};
char descricao2[] = {
"Doação Voluntária - PIX: marcio_br@protonmail.com"
};
TCHAR szBuffer[20], szBuffer2[20];
LRESULT CALLBACK WndProc(HWND hwnd, UINT msg, WPARAM wP, LPARAM lParam) {
static COLORREF cr, crLast;
static HDC hdcScreen;
HDC hdc;
PAINTSTRUCT ps;
POINT pt;
RECT rc;
TCHAR szBuffer[16];
int vCores[3] = {COLOR_WINDOW, COLOR_ACTIVECAPTION, COLOR_INFOBK};
DWORD CorPadraoDoSistema[3];
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("Dados Cor de Fundo"), WS_VISIBLE | WS_CHILD,
10, 90, 150, 40,
hwnd, (HMENU) BTN1, NULL, NULL
);
CreateWindow(
TEXT("button"), TEXT("Sair"), WS_VISIBLE | WS_CHILD,
180, 90, 90, 40,
hwnd, (HMENU) BTN2, NULL, NULL
);
nome2 = CreateWindow(
TEXT("static"), descricao2, WS_VISIBLE | WS_CHILD,
10, 180, 380, 20,
hwnd, NULL, NULL, NULL
);
CreateWindow(TEXT("static"), descricao, WS_VISIBLE | WS_CHILD,
340, 20, 180, 80,
hwnd, NULL, NULL, NULL);
CreateWindowW(
L"static", L"1 Nota: ", WS_VISIBLE | WS_CHILD,
10, 220, 60, 20,
hwnd, NULL, NULL, NULL
);
num1 = CreateWindow(
TEXT("edit"), TEXT(""), WS_VISIBLE | WS_CHILD | WS_BORDER,
74, 220, 50, 20,
hwnd, NULL, NULL, NULL
);
CreateWindowW(
L"static", L"2 Nota: ", WS_VISIBLE | WS_CHILD,
130, 220, 60, 20,
hwnd, NULL, NULL, NULL
);
num2 = CreateWindow(
TEXT("edit"), TEXT(""), WS_VISIBLE | WS_CHILD | WS_BORDER,
196, 220, 50, 20,
hwnd, NULL, NULL, NULL
);
CreateWindowW(
L"static", L"3 Nota: ", WS_VISIBLE | WS_CHILD,
256, 220, 60, 20,
hwnd, NULL, NULL, NULL
);
num3 = CreateWindow(
TEXT("edit"), TEXT(""), WS_VISIBLE | WS_CHILD | WS_BORDER,
322, 220, 50, 20,
hwnd, NULL, NULL, NULL
);
CreateWindowW(
L"static", L"4 Nota: ", WS_VISIBLE | WS_CHILD,
386, 220, 60, 20,
hwnd, NULL, NULL, NULL
);
num4 = CreateWindow(
TEXT("edit"), TEXT(""), WS_VISIBLE | WS_CHILD | WS_BORDER,
452, 220, 50, 20,
hwnd, NULL, NULL, NULL
);
CreateWindow(
TEXT("button"), TEXT("Calcular"), WS_VISIBLE | WS_CHILD | WS_BORDER,
10, 270, 100, 20,
hwnd, (HMENU) BTN3, NULL, NULL
);
CreateWindow(
TEXT("static"), TEXT("Resultado:"), WS_VISIBLE | WS_CHILD,
280, 270, 100, 20,
hwnd, NULL, NULL, NULL
);
resultado = CreateWindow(
TEXT("edit"), TEXT(""), WS_VISIBLE | WS_CHILD,
404, 270, 100, 20,
hwnd, NULL, NULL, NULL
);
return 0;
case WM_COMMAND:
if(LOWORD(wP)==BTN1) {
CorPadraoDoSistema[1] = GetSysColor(vCores[1]);
wsprintf(
szBuffer2, TEXT("Cor de fundo: %02X %02X %02X "),
GetRValue(CorPadraoDoSistema[1]),
GetGValue(CorPadraoDoSistema[1]),
GetBValue(CorPadraoDoSistema[1])
);
MessageBox(NULL, szBuffer2, "Cor Padrão", MB_OK);
return 0;
}
if(LOWORD(wP)==BTN2) {
exit(0);
}
if(LOWORD(wP)==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);
float res = (atof(t1)+atof(t2)+atof(t3)+atof(t4))/4;
char tam[30];
sprintf(tam, "%.2f", res);
SetWindowText(resultado, tam);
FILE *arq;
arq=fopen("Teste.txt", "w+");
fwrite(tam, sizeof(arq),10,arq);
fclose(arq);
}
if(LOWORD(wP)==DCS) {
CorPadraoDoSistema[0] = GetSysColor(vCores[0]);
SetSysColors(3, vCores, CorPadraoDoSistema);
wsprintf(
szBuffer, TEXT(" %02X %02X %02X "),
GetRValue(CorPadraoDoSistema[0]),
GetGValue(CorPadraoDoSistema[0]),
GetBValue(CorPadraoDoSistema[0])
);
MessageBox(NULL, szBuffer, "Cor Padrão", MB_OK);
}
return 0;
case WM_DESTROY: {
PostQuitMessage(0);
break;
}
default:
return DefWindowProc(hwnd, msg, wP, lParam);
}
return 0;
}
int WINAPI WinMain(HINSTANCE hI, HINSTANCE hPI, LPSTR szCL, int iCS) {
WNDCLASSEX wc; HWND hwnd;
MSG msg; memset(&wc,0,sizeof(wc));
wc.cbSize = sizeof(WNDCLASSEX);
wc.lpfnWndProc = WndProc;
wc.hInstance = hI;
wc.hCursor = LoadCursor(NULL, IDC_ARROW);
wc.hbrBackground = GetSysColorBrush(COLOR_ACTIVECAPTION);
wc.lpszClassName = "WindowClass";
wc.hIcon = LoadIcon(hI, ICONE);
wc.hIconSm = LoadIcon(hI, ICONE);
if(!RegisterClassEx(&wc)) {
MessageBox(
NULL,
"Window Registration Failed!",
"Error!",
MB_ICONEXCLAMATION | MB_OK
);
return 0;
}
hwnd = CreateWindowEx(
WS_EX_CLIENTEDGE,"WindowClass",txt,WS_VISIBLE|WS_OVERLAPPEDWINDOW,
CW_USEDEFAULT, CW_USEDEFAULT, 580, 375,
NULL,NULL,hI,NULL
);
if(hwnd == NULL) {
MessageBox(
NULL,
"Window Creation Failed!",
"Error!",
MB_ICONEXCLAMATION | MB_OK
);
return 0;
}
while(GetMessage(&msg, NULL, 0, 0) > 0) { TranslateMessage(&msg); DispatchMessage(&msg); }
return msg.wParam;
}
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, DCS, "Default");
AppendMenu(hMenu, MF_STRING, NULL, "Keyboard");
SetMenu(hwnd, hMenu);
}
resource.html
#define ICONE 17
resourcerc.html
#include "resource.h"
#include "afxres.h"
ICONE ICON "project1.ico"
Comentários
Postar um comentário