
/**Os céus manifestam a glória de Deus e o firmamento anuncia a obra das suas mãos.*/
#include <windows.h>
#include "resource.h"
LRESULT CALLBACK WndProc (HWND, UINT, WPARAM, LPARAM);
BOOL CALLBACK AboutDlgProc(HWND, UINT, WPARAM, LPARAM);
int iCurrentColor = IDC_BLACK, iCurrentFigure = IDC_RECT;
int WINAPI WinMain(HINSTANCE hI, HINSTANCE hPI, PSTR szCL, int iCS) {
static TCHAR nome[] = TEXT("About2");
MSG msg;
HWND hwnd;
WNDCLASS wndclass;
wndclass.style = CS_HREDRAW | CS_VREDRAW;
wndclass.lpfnWndProc = WndProc;
wndclass.cbClsExtra = 0;
wndclass.cbWndExtra = 0;
wndclass.hInstance = hI;
wndclass.hIcon = LoadIcon(hI, nome);
wndclass.hCursor = LoadCursor(NULL, IDC_ARROW);
wndclass.hbrBackground = (HBRUSH) GetStockObject(WHITE_BRUSH);
wndclass.lpszMenuName = nome;
wndclass.lpszClassName = nome;
if(!RegisterClass(&wndclass)) {
MessageBox(NULL,TEXT("Error!"), nome, MB_ICONERROR);
return 0;
}
hwnd = CreateWindow(
nome, TEXT("Pintura"), 0xcf0000,
CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT,
NULL, NULL, hI, NULL
);
ShowWindow(hwnd, iCS);
UpdateWindow(hwnd);
while(GetMessage(&msg, NULL, 0, 0)) {
TranslateMessage(&msg);
DispatchMessage (&msg);
FreeConsole();
}
return msg.wParam;
}
void Pintura(HWND hwnd, int iColor, int iFigure) {
static COLORREF crColor[8] = {
RGB(0, 0, 0), RGB(0, 0, 255),
RGB(0, 255, 0), RGB(0, 255, 255),
RGB(255, 0, 0), RGB(255, 0, 255),
RGB(255, 255, 0), RGB(255, 255, 255)
};
HBRUSH hBrush;
HDC hdc;
RECT rect;
hdc = GetDC(hwnd);
GetClientRect(hwnd, &rect);
hBrush = CreateSolidBrush(crColor[iColor - IDC_BLACK]);
hBrush = (HBRUSH) SelectObject(hdc, hBrush);
if(iFigure == IDC_RECT)
Rectangle(hdc, rect.left, rect.top, rect.right, rect.bottom);
else
Ellipse(hdc, rect.left, rect.top, rect.right, rect.bottom);
DeleteObject(SelectObject(hdc, hBrush));
ReleaseDC(hwnd, hdc);
}
void PaintTheBlock(HWND hCtrl, int iColor, int iFigure) {
InvalidateRect(hCtrl, NULL, TRUE);
UpdateWindow(hCtrl);
Pintura(hCtrl, iColor, iFigure);
}
LRESULT CALLBACK WndProc(HWND hwnd,UINT msg,WPARAM wParam,LPARAM lParam) {
static HINSTANCE hInstance;
PAINTSTRUCT ps;
switch(msg) {
case WM_CREATE:
hInstance = ((LPCREATESTRUCT) lParam)->hInstance;
return 0;
case WM_COMMAND:
switch(LOWORD(wParam)) {
case IDM_APP_ABOUT:
if(DialogBox(hInstance,TEXT("AboutBox"),hwnd,AboutDlgProc))
InvalidateRect(hwnd, NULL, TRUE);
return 0;
}
break;
case WM_PAINT:
BeginPaint(hwnd, &ps);
EndPaint(hwnd, &ps);
Pintura(hwnd, iCurrentColor, iCurrentFigure);
return 0;
case WM_DESTROY:
PostQuitMessage(0);
return 0;
}
return DefWindowProc(hwnd, msg, wParam, lParam);
}
BOOL CALLBACK AboutDlgProc(HWND hDlg,UINT msg,WPARAM wParam,LPARAM lParam) {
static HWND hCtrlBlock;
static int iColor, iFigure;
switch(msg) {
case WM_INITDIALOG:
iColor = iCurrentColor;
iFigure = iCurrentFigure;
CheckRadioButton(hDlg, IDC_BLACK, IDC_WHITE, iColor);
CheckRadioButton(hDlg, IDC_RECT, IDC_ELLIPSE, iFigure);
hCtrlBlock = GetDlgItem(hDlg, IDC_PAINT);
SetFocus(GetDlgItem(hDlg, iColor));
return FALSE;
case WM_COMMAND:
switch(LOWORD(wParam)) {
case IDOK:
iCurrentColor = iColor;
iCurrentFigure = iFigure;
EndDialog(hDlg, TRUE);
return TRUE;
case IDCANCEL:
EndDialog(hDlg, FALSE);
return TRUE;
case IDC_BLACK:
case IDC_RED:
case IDC_GREEN:
case IDC_YELLOW:
case IDC_BLUE:
case IDC_MAGENTA:
case IDC_CYAN:
case IDC_WHITE:
iColor = LOWORD(wParam);
CheckRadioButton(hDlg,IDC_BLACK,IDC_WHITE,LOWORD(wParam));
PaintTheBlock(hCtrlBlock, iColor, iFigure);
return TRUE;
case IDC_RECT:
case IDC_ELLIPSE:
iFigure = LOWORD(wParam);
CheckRadioButton(hDlg,IDC_RECT,IDC_ELLIPSE,LOWORD(wParam));
PaintTheBlock(hCtrlBlock, iColor, iFigure);
return TRUE;
}
break;
case WM_PAINT:
PaintTheBlock(hCtrlBlock, iColor, iFigure);
return 0;
}
return FALSE;
}
/********************Arquivo: resource.h********************/
#define IDC_BLACK 1000
#define IDC_BLUE 1001
#define IDC_GREEN 1002
#define IDC_CYAN 1003
#define IDC_RED 1004
#define IDC_MAGENTA 1005
#define IDC_YELLOW 1006
#define IDC_WHITE 1007
#define IDC_RECT 1008
#define IDC_ELLIPSE 1009
#define IDC_PAINT 1010
#define IDM_APP_ABOUT 1011
#define IDC_STATIC -1
/********************Arquivo: resource.rc********************/
#include "resource.h"
#include "afxres.h"
ABOUTBOX DIALOG DISCARDABLE 32, 32, 200, 234
STYLE DS_MODALFRAME | WS_POPUP | WS_CAPTION
FONT 10, "MS Sans Serif"
BEGIN
ICON "About2.ico", IDC_STATIC, 7,7,20,20
CTEXT "Escolher", IDC_STATIC,57,12,86,8
CTEXT "Cor de Fundo",IDC_STATIC, 7,40,186,8
LTEXT " ", IDC_PAINT,114,67,74,72
GROUPBOX "&Color", IDC_STATIC, 7,60,84,143
RADIOBUTTON "&Black", IDC_BLACK, 16,76,64,8,WS_GROUP | WS_TABSTOP
RADIOBUTTON "B&lue", IDC_BLUE, 16,92,64,8
RADIOBUTTON "&Green", IDC_GREEN, 16,108,64,8
RADIOBUTTON "Cya&n", IDC_CYAN, 16,124,64,8
RADIOBUTTON "&Red", IDC_RED, 16,140,64,8
RADIOBUTTON "&Magenta", IDC_MAGENTA,16,156,64,8
RADIOBUTTON "&Yellow", IDC_YELLOW ,16,172,64,8
RADIOBUTTON "&White", IDC_WHITE,16,188,64,8
GROUPBOX "&Figure", IDC_STATIC,109,156,84,46,WS_GROUP
RADIOBUTTON "Rec&tangle", IDC_RECT,116,172,65,8, WS_GROUP | WS_TABSTOP
RADIOBUTTON "&Ellipse", IDC_ELLIPSE,116,188,64,8
DEFPUSHBUTTON "OK", IDOK, 35,212,50,14, WS_GROUP
PUSHBUTTON "Cancel", IDCANCEL,113,212,50,14, WS_GROUP
END
About2 ICON DISCARDABLE "About2.ico"
About2 MENU DISCARDABLE
BEGIN
POPUP "&Ajuda"
BEGIN
MENUITEM "&Cores", IDM_APP_ABOUT
END
MENUITEM "Exemplo2", 2
MENUITEM "Exemplo3", 3
END
Comentários
Postar um comentário