SetTimer(hwnd, ID_MS, 3000, TimerProc);


#include <windows.h>
#include "resource.h"

#define ID_MS 1

LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM);

void CALLBACK TimerProc(HWND, UINT, UINT, DWORD);

static char font[50] = "Verdana";

char vs[] = "Apocalipse 22:16";
char ttl[]="hBrush=CreateSolidBrush(fFlipFlop?RGB(99, 0, 99):RGB(0, 89, 255));";

static HFONT tamanhoDaFonte;

int WINAPI WinMain(HINSTANCE hI, HINSTANCE hPI, PSTR szCL, int iCS) {
    static char szAppName[] = "Temporizador";
    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, IDI_ICON);
    wndclass.hCursor       = LoadCursor(NULL, IDC_ARROW);
    wndclass.hbrBackground = (HBRUSH) GetStockObject(WHITE_BRUSH);
    wndclass.lpszMenuName  = NULL;
    wndclass.lpszClassName = szAppName;

    if(!RegisterClass(&wndclass)) {
        MessageBox(
            NULL,
            TEXT("This program requires Windows NT"),
            szAppName,
            MB_ICONERROR
        );
        return 0;
    }

    hwnd = CreateWindow(
        szAppName, ttl, WS_OVERLAPPEDWINDOW,
        CW_USEDEFAULT, CW_USEDEFAULT, 500, 300,
        NULL, NULL, hI, NULL
    );

    ShowWindow(hwnd, iCS);
    UpdateWindow(hwnd);

    while(GetMessage(&msg, NULL, 0, 0)) {
        TranslateMessage(&msg);
        DispatchMessage (&msg);
        FreeConsole();
    }
    return msg.wParam;
}

LRESULT CALLBACK WndProc(HWND hwnd, UINT msg, WPARAM wP, LPARAM lParam) {
    HDC         hdc;
    PAINTSTRUCT ps;
    switch(msg) {
        case WM_CREATE:
            SetTimer(hwnd, ID_MS, 3000, TimerProc);
            return 0;
        case WM_PAINT:
            hdc = BeginPaint(hwnd, &ps);

            tamanhoDaFonte = CreateFontA(
                58, 0, 0, 0, FW_EXTRABOLD,
                1, 0, 0, 0, 0,
                0, 0, 0, font
            );

            SelectObject(hdc, tamanhoDaFonte);
            SetTextColor(hdc, RGB(0, 120, 120));
            TextOut(hdc, 10, 80, vs, strlen(vs));

            EndPaint(hwnd, &ps);
            return 0;
        case WM_DESTROY:
            KillTimer(hwnd, ID_MS);
            PostQuitMessage(0);
            return 0;
    }
    return DefWindowProc(hwnd, msg, wP, lParam);
}

void CALLBACK TimerProc(HWND hwnd, UINT msg, UINT iTimerID, DWORD dwTime) {
    static BOOL fFlipFlop = FALSE;
    HBRUSH hBrush;
    HDC    hdc;
    RECT   rect;

    MessageBeep(-1);
    fFlipFlop = !fFlipFlop;

    GetClientRect(hwnd, &rect);

    hdc   = GetDC(hwnd);
    hBrush=CreateSolidBrush(fFlipFlop?RGB(99, 0, 99):RGB(0, 89, 255));

    FillRect(hdc, &rect, hBrush);
    ReleaseDC(hwnd, hdc);
    DeleteObject(hBrush);
}


/********************Arquivo: resource.h********************/

#define IDI_ICON " "


/********************Arquivo: resource.rc********************/

#include "afxres.h"
#include "resource.h"

IDI_ICON ICON "project1.ico"

Comentários