main.html

#include <windows.h>
#include "resource.h"
#define ID_TIMER 1
LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM);
int WINAPI WinMain(HINSTANCE hI, HINSTANCE hPI, PSTR szCL, int iCS) {
static TCHAR nome[] = TEXT("Bounce");
HWND hwnd;
MSG msg;
WNDCLASS wndclass;
wndclass.style = CS_HREDRAW | CS_VREDRAW;
wndclass.lpfnWndProc = WndProc;
wndclass.cbClsExtra = 0;
wndclass.cbWndExtra = 0;
wndclass.hInstance = hI;
wndclass.hIcon = LoadIcon(hI, ICONE);
wndclass.hCursor = LoadCursor(NULL, IDC_ARROW);
wndclass.hbrBackground = (HBRUSH) GetStockObject(WHITE_BRUSH);
wndclass.lpszMenuName = NULL;
wndclass.lpszClassName = nome;
if(!RegisterClass(&wndclass)) {
MessageBox(NULL, TEXT("Error!"), nome, MB_ICONERROR);
return 0;
}
hwnd = CreateWindow(
nome, "Programação para Windows", WS_OVERLAPPEDWINDOW,
CW_USEDEFAULT, CW_USEDEFAULT, 400, 400,
NULL, NULL, hI, NULL
);
ShowWindow(hwnd, iCS);
UpdateWindow(hwnd);
while(GetMessage(&msg, NULL, 0, 0)) {
TranslateMessage(&msg);
DispatchMessage (&msg);
}
return msg.wParam;
}
LRESULT CALLBACK WndProc(HWND hwnd, UINT msg, WPARAM wP, LPARAM lP) {
static HBITMAP hBmp;
static int cxClient, cyClient, xCtr, yCtr, cxTotal, cyTotal,
cxRadius, cyRadius, cxMove, cyMove, xPixel, yPixel;
HBRUSH hBrush;
HDC hdc, hdc2;
int iScale;
switch(msg) {
case WM_CREATE:
hdc = GetDC(hwnd);
xPixel = GetDeviceCaps(hdc, ASPECTX);
yPixel = GetDeviceCaps(hdc, ASPECTY);
ReleaseDC(hwnd, hdc);
SetTimer(hwnd, ID_TIMER, 20, NULL);
return 0;
case WM_SIZE:
xCtr = (cxClient = LOWORD(lP)) / 2;
yCtr = (cyClient = HIWORD(lP)) / 2;
iScale = min(
cxClient * xPixel, cyClient * yPixel
) / 16;
cxRadius = iScale / xPixel;
cyRadius = iScale / yPixel;
cxMove = max(1, cxRadius / 2);
cyMove = max(1, cyRadius / 2);
cxTotal = 2 * (cxRadius + cxMove);
cyTotal = 2 * (cyRadius + cyMove);
if(hBmp) {
DeleteObject(hBmp);
}
hdc = GetDC(hwnd);
hdc2 = CreateCompatibleDC(hdc);
hBmp = CreateCompatibleBitmap(
hdc, cxTotal, cyTotal
);
ReleaseDC(hwnd, hdc);
SelectObject(hdc2, hBmp);
Rectangle(hdc2, -1, -1, cxTotal + 1, cyTotal + 1);
hBrush = CreateHatchBrush(HS_DIAGCROSS, 0L);
SelectObject(hdc2, hBrush);
SetBkColor(hdc2, RGB(0, 243, 60));
Ellipse(
hdc2, cxMove, cyMove,
cxTotal - cxMove, cyTotal - cyMove
);
DeleteDC(hdc2);
DeleteObject(hBrush);
return 0;
case WM_TIMER:
if(!hBmp) {
break;
}
hdc = GetDC(hwnd);
hdc2 = CreateCompatibleDC(hdc);
SelectObject(hdc2, hBmp);
BitBlt(
hdc, xCtr - cxTotal / 2,
yCtr - cyTotal / 2, cxTotal,
cyTotal, hdc2, 0, 0, SRCCOPY
);
ReleaseDC(hwnd, hdc);
DeleteDC(hdc2);
xCtr += cxMove;
yCtr += cyMove;
if((xCtr+cxRadius>=cxClient)||(xCtr-cxRadius<=0)) {
cxMove = -cxMove;
}
if((yCtr+cyRadius>=cyClient)||(yCtr-cyRadius<=0)) {
cyMove = -cyMove;
}
return 0;
case WM_DESTROY:
if(hBmp) {
DeleteObject(hBmp);
}
KillTimer(hwnd, ID_TIMER);
PostQuitMessage(0);
return 0;
}
return DefWindowProc(hwnd, msg, wP, lP);
}
resourceh.html
#define ICONE 100
resource.html
#include "resource.h"
#include "afxres.h"
ICONE ICON "icon3.ico"
Comentários
Postar um comentário