Calcula o maior dos valores nos campos num1, num2 e num3, o resultado estará armazenado na variável valorfinal através da função sprintf

main.html
#include <windows.h>
#include <stdio.h>

#define BTN_BUSCA 1

void Controles(HWND);
int mm(int, int, int);

static HWND num1, num2, num3, r;

LRESULT CALLBACK WndProc(HWND hwnd, UINT msg, WPARAM wP, LPARAM lP) {
    switch(msg) {
        case WM_CREATE:
            Controles(hwnd);
            return 0;
        case WM_COMMAND:
            if(LOWORD(wP)==BTN_BUSCA) {
                int n1 = GetWindowTextLength(num1)+1;
                int n2 = GetWindowTextLength(num2)+1;
                int n3 = GetWindowTextLength(num3)+1;
                static char nr1[50], nr2[50], nr3[50], valorfinal[50];
                GetWindowText(num1, nr1, n1);
                GetWindowText(num2, nr2, n2);
                GetWindowText(num3, nr3, n3);
                sprintf(
                    valorfinal,
                    "%d é o maior valor digitado",
                    mm(atoi(nr1), atoi(nr2), atoi(nr3))
                );
                SetWindowText(r, valorfinal);
            }
            return 0;
        /* Upon destruction, tell the main thread to stop */
        case WM_DESTROY: {
            PostQuitMessage(0);
            break;
        }
        default:
            return DefWindowProc(hwnd, msg, wP, lP);
    }
    return 0;
}

void Controles(HWND hwnd) {
    num1 = CreateWindow(
        TEXT("edit"), TEXT(""),WS_VISIBLE|WS_CHILD|WS_BORDER,
        10, 70, 70, 20,
        hwnd, NULL, NULL, NULL
    );
    num2 = CreateWindow(
        TEXT("edit"), TEXT(""),WS_VISIBLE|WS_CHILD|WS_BORDER,
        100, 70, 70, 20,
        hwnd, NULL, NULL, NULL
    );
    num3 = CreateWindow(
        TEXT("edit"), TEXT(""),WS_VISIBLE|WS_CHILD|WS_BORDER,
        190, 70, 70, 20,
        hwnd, NULL, NULL, NULL
    );
    CreateWindow(
        TEXT("button"),TEXT("Calcular"),WS_VISIBLE|WS_CHILD|WS_BORDER,
        280, 70, 70, 20,
        hwnd, (HMENU) BTN_BUSCA, NULL, NULL
    );
    r = CreateWindow(
        TEXT("edit"), TEXT(""),WS_VISIBLE|WS_CHILD|WS_DISABLED,
        370, 70, 180, 20,
        hwnd, NULL, NULL, NULL
    );
}

int mm(int x, int y, int z) {
    int max = x;
    if(y > max) {
        max = y;
    }
    if(z > max) {
        max = z;
    }
    return max;
}

int WINAPI WinMain(HINSTANCE hI, HINSTANCE hPI, LPSTR szCL, int iCS) {
    WNDCLASSEX wc;
    HWND hwnd;
    MSG   msg;
    /* zero out the struct and set the stuff we want to modify */
    memset(&wc,0,sizeof(wc));
    wc.cbSize        = sizeof(WNDCLASSEX);
    wc.lpfnWndProc   = WndProc;
    wc.hInstance     = hI;
    wc.hCursor       = LoadCursor(NULL, IDC_ARROW);
    wc.hbrBackground = GetSysColorBrush(COLOR_WINDOWFRAME);
    wc.lpszClassName = "WindowClass";
    wc.hIcon         = LoadIcon(NULL, IDI_APPLICATION);
    wc.hIconSm       = LoadIcon(NULL, IDI_APPLICATION);

    if(!RegisterClassEx(&wc)) {
        MessageBox(
            NULL,
            "Window Registration Failed!",
            "Error!",
            MB_ICONEXCLAMATION | MB_OK
        );
        return 0;
    }

    hwnd = CreateWindowEx(
        WS_EX_CLIENTEDGE, "WindowClass",
        "Programação para Windows",
        WS_VISIBLE | WS_OVERLAPPEDWINDOW,
        CW_USEDEFAULT, /* x */
        CW_USEDEFAULT, /* y */
        600, /* width */
        210, /* height */
        NULL, NULL, hI, NULL
    );

    if(hwnd == NULL) {
        MessageBox(
            NULL,
            "Window Creation Failed!",
            "Error!",
            MB_ICONEXCLAMATION | MB_OK
        );
        return 0;
    }

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


Comentários