int res = atoi(t1)*atoi(t2);

#if defined(UNICODE) && !defined(_UNICODE)
    #define _UNICODE
#elif defined(_UNICODE) && !defined(UNICODE)
    #define UNICODE
#endif

#include <tchar.h>
#include <windows.h>
#include <math.h>
#include <stdio.h>
#include "resource.h"


#define ID_BUTTON  1

static HWND num1, num2, t;


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

void addMenus(HWND);

HMENU eMenu;

static char font[50] = "Verdana";

char vs[] = "Apocalipse 22:16";

static HFONT tamanhoDaFonte;

TCHAR szClassName[ ] = _T("CodeBlocksWindowsApp");


int WINAPI WinMain (HINSTANCE hI, HINSTANCE hPI, LPSTR lpszArg, int nCS) {
    HWND       hwnd;
    MSG        messages;
    WNDCLASSEX wincl;

    /* The Window structure */
    wincl.hInstance     = hI;
    wincl.lpszClassName = szClassName;
    wincl.lpfnWndProc   = WindowProcedure;
    wincl.style         = CS_DBLCLKS;
    wincl.cbSize        = sizeof(WNDCLASSEX);

    /* Use default icon and mouse-pointer */
    wincl.hIcon        = LoadIcon(hI, ICONE);
    wincl.hIconSm      = LoadIcon(NULL, ICONE);
    wincl.hCursor      = LoadCursor (NULL, IDC_ARROW);
    wincl.lpszMenuName = NULL;
    wincl.cbClsExtra   = 0;
    wincl.cbWndExtra   = 0;
    wincl.hbrBackground = GetSysColorBrush(COLOR_3DFACE);

    if (!RegisterClassEx(&wincl))
        return 0;



    hwnd = CreateWindowEx (
        0,                   /* Extended possibilites for variation */
        szClassName,
        _T("int n1 = GetWindowTextLength(num1)+1;"), /* Title Text */
        WS_OVERLAPPEDWINDOW,
        CW_USEDEFAULT,       /* Windows decides the position */
        CW_USEDEFAULT,       /*where the window ends up on the screen*/
        500,
        300,
        HWND_DESKTOP,        /*The window is a child-window to desktop*/
        NULL,                /* No menu */
        hI,                  /* Program Instance handler */
        NULL
    );

    ShowWindow (hwnd, nCS);

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

LRESULT CALLBACK WindowProcedure(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lP) {
    HDC         hdc;
    PAINTSTRUCT ps;
    switch(msg) {
        case WM_CREATE:
            addMenus(hwnd);

            CreateWindow(
                TEXT("static"), TEXT("x"), WS_VISIBLE | WS_CHILD,
                116, 50, 480, 20,
                hwnd, NULL, NULL, NULL
            );

            num1 = CreateWindow(
                TEXT("edit"), TEXT(""), WS_VISIBLE | WS_CHILD,
                30, 50, 80, 20,
                hwnd, NULL, NULL, NULL
            );

            num2 = CreateWindow(
                TEXT("edit"), TEXT(""), WS_VISIBLE | WS_CHILD,
                130, 50, 80, 20,
                hwnd, NULL, NULL, NULL
            );

            CreateWindow(
                TEXT("button"), TEXT("Calcular"), WS_VISIBLE | WS_CHILD,
                220, 50, 80, 20,
                hwnd, (HMENU) ID_BUTTON, NULL, NULL
            );

            t = CreateWindow(
                TEXT("edit"), TEXT(""), WS_VISIBLE | WS_CHILD,
                320, 50, 80, 20,
                hwnd, NULL, NULL, NULL
            );
            break;

        case WM_COMMAND:
            if(LOWORD(wParam)==ID_BUTTON) {
                int n1 = GetWindowTextLength(num1)+1;
                int n2 = GetWindowTextLength(num2)+1;

                static char t1[40];
                static char t2[40];

                GetWindowText(num1, t1, n1);
                GetWindowText(num2, t2, n2);

                int res = atoi(t1)*atoi(t2);


                char tam[40];

                itoa(res, tam, 10);

                SetWindowText(t, tam);
                return 0;
            }
            break;
        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, 160, vs, strlen(vs));

            EndPaint(hwnd, &ps);
            return 0;
        case WM_DESTROY:
            PostQuitMessage(0);
            break;
        default:
            return DefWindowProc(hwnd, msg, wParam, lP);
    }

    return 0;
}

void addMenus(HWND hwnd) {
    eMenu = CreateMenu();

    HMENU sub = CreateMenu();

    AppendMenu(sub, MF_STRING, NULL, "Sub 1");
    AppendMenu(sub, MF_STRING, NULL, "Sub 2");

    AppendMenu(eMenu, MF_STRING, 0, "MENUITEM");
    AppendMenu(eMenu, MF_STRING, NULL, "MENUITEM");
    AppendMenu(eMenu, MF_POPUP, (UINT_PTR) sub, "POPUP");
    AppendMenu(eMenu, MF_STRING, 3, "MENUITEM");

    SetMenu(hwnd, eMenu);
}


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

#define ICONE " "


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

#include "resource.h"

ICONE ICON "icone.ico"

Comentários