main.html
#include <windows.h>
#include <stdio.h>
#include "resource.h"
#define ID_BTN_1 1
void Controles(HWND);
static HWND r, massa, altura, calcular;
HFONT hFonte1, hFonte2;
LRESULT CALLBACK WndProc(HWND hwnd, UINT msg, WPARAM wP, LPARAM lP) {
switch(msg) {
case WM_SIZE:
Controles(hwnd);
hFonte1 = CreateFont(
28,0,0,0,0,FALSE,0,0,0,0,0,0,0,"Impact"
);
hFonte2 = CreateFont(
34,0,0,0,0,FALSE,0,0,0,0,0,0,0,"Impact"
);
SendMessage(calcular, WM_SETFONT, hFonte1, TRUE);
SendMessage(r, WM_SETFONT, hFonte2, TRUE);
return 0;
case WM_COMMAND:
if(LOWORD(wP)==ID_BTN_1) {
int ms = GetWindowTextLength(massa)+1;
int at = GetWindowTextLength(altura)+1;
static char c1[50], c2[50];
GetWindowText(massa, c1, ms);
GetWindowText(altura, c2, at);
float res = (atof(c1) / (atof(c2)*atof(c2)));
static char resultado[500];
sprintf(resultado, "%.2f", res);
SetWindowText(r, resultado);
}
return 0;
case WM_DESTROY: {
PostQuitMessage(0);
break;
}
default:
return DefWindowProc(hwnd, msg, wP, lP);
}
return 0;
}
int WINAPI WinMain(HINSTANCE hI, HINSTANCE hPI, LPSTR lpCmdLine, 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 = (HBRUSH)(COLOR_INACTIVECAPTION+1);
wc.lpszClassName = "WindowClass";
wc.hIcon = LoadIcon(hI, IDI_ICON);
wc.hIconSm = LoadIcon(NULL, IDI_ICON);
if(!RegisterClassEx(&wc)) {
MessageBox(
NULL,
"Window Registration Failed!",
"Error!",
MB_ICONEXCLAMATION | MB_OK
);
return 0;
}
hwnd = CreateWindowEx(
WS_EX_CLIENTEDGE, "WindowClass", "IMC:", WS_VISIBLE | WS_OVERLAPPEDWINDOW,
CW_USEDEFAULT, CW_USEDEFAULT, 280, 250,
NULL, NULL, hI, NULL
);
if(hwnd == NULL) {
MessageBox(
NULL,
"Window Registration Failed!",
"Error!",
MB_ICONEXCLAMATION | MB_OK
);
return 0;
}
while(GetMessage(&msg, NULL, 0, 0) > 0) { TranslateMessage(&msg); DispatchMessage(&msg); }
return msg.wParam;
}
void Controles(HWND hwnd) {
CreateWindow(
TEXT("static"), TEXT("Peso"), WS_VISIBLE | WS_CHILD,
10, 40, 100, 20,
hwnd, NULL, NULL, NULL
);
massa = CreateWindow(
TEXT("edit"), TEXT(""), WS_VISIBLE | WS_CHILD,
140, 40, 100, 20,
hwnd, NULL, NULL, NULL
);
CreateWindow(
TEXT("static"), TEXT("Altura"), WS_VISIBLE | WS_CHILD,
10, 80, 100, 20,
hwnd, NULL, NULL, NULL
);
altura = CreateWindow(
TEXT("edit"), TEXT(""), WS_VISIBLE | WS_CHILD,
140, 80, 100, 20,
hwnd, NULL, NULL, NULL
);
calcular = CreateWindow(
TEXT("button"), TEXT("Calcular"), WS_VISIBLE | WS_CHILD,
10, 120, 100, 40,
hwnd, (HMENU) ID_BTN_1, NULL, NULL
);
r = CreateWindow(
TEXT("edit"), TEXT(""), WS_VISIBLE | WS_CHILD,
140, 120, 100, 40,
hwnd, NULL, NULL, NULL
);
}
resource.html
#define IDI_ICON 1
resourcerc.html
#include "afxres.h"
#include "resource.h"
IDI_ICON ICON "project1.ico"
Comentários
Postar um comentário