Simple c gui programming

I developed a solution to the equation of a paired table in C ... but entering values ​​into the black console of the screen is boring.

Therefore, I strictly wanted to create a simple GUI in C.

I was looking for welcome codes of the world, all were quite long. But that was the only one that I understood.

#include <windows.h>

int main()
{
MessageBoxA( NULL, "Hello World!", "Hello", MB_OK );
}

Using the gui creator for C, I got this code, now I was thinking how to check the values ​​from TEXTBOX1 and TEXTBOX2 on Pressing COMMANDBUTTON1 and display the output in TEXTBOX3 ?

#define WIN32_LEAN_AND_MEAN

#include <windows.h>
#include <windowsx.h>
#include <commctrl.h>
#include "hello.auto.h"


HWND hwnd_Label1, hwnd_Label2, hwnd_TextBox1, hwnd_TextBox2, hwnd_CommandButton1,
hwnd_TextBox3;

HFONT MSSansSerif_8pt;



void CreateChildWindows(HWND hwndMainWindow, HINSTANCE hInstance)
{
InitCommonControls();

MSSansSerif_8pt = CreateFont(-11,0,0,0,FW_NORMAL,0,0,0,0,0,0,0,0,"MS Sans Serif");

hwnd_Label1 = CreateWindowEx(0, "Static", "Pressure",
    WS_CHILD | WS_VISIBLE,
    11, 55, 95, 38, hwndMainWindow,
    (HMENU)Label1, hInstance, NULL);

SetWindowFont(hwnd_Label1, MSSansSerif_8pt, TRUE);

hwnd_Label2 = CreateWindowEx(0, "Static", "Temperature",
    WS_CHILD | WS_VISIBLE,
    11, 110, 95, 38, hwndMainWindow,
    (HMENU)Label2, hInstance, NULL);

SetWindowFont(hwnd_Label2, MSSansSerif_8pt, TRUE);

hwnd_TextBox1 = CreateWindowEx(WS_EX_CLIENTEDGE, "Edit" , NULL,
    WS_CHILD | ES_WANTRETURN | WS_VISIBLE,
    187, 55, 83, 35, hwndMainWindow,
    (HMENU)TextBox1, hInstance, NULL);

SetWindowFont(hwnd_TextBox1, MSSansSerif_8pt, TRUE);

hwnd_TextBox2 = CreateWindowEx(WS_EX_CLIENTEDGE, "Edit" , NULL,
    WS_CHILD | ES_WANTRETURN | WS_VISIBLE,
    187, 99, 83, 35, hwndMainWindow,
    (HMENU)TextBox2, hInstance, NULL);

SetWindowFont(hwnd_TextBox2, MSSansSerif_8pt, TRUE);

hwnd_CommandButton1 = CreateWindowEx(0, "Button", "CommandButton1",
    WS_CHILD | BS_MULTILINE | BS_PUSHBUTTON | WS_VISIBLE,
    308, 77, 117, 52, hwndMainWindow,
    (HMENU)CommandButton1, hInstance, NULL);


SetWindowFont(hwnd_CommandButton1, MSSansSerif_8pt, TRUE);

hwnd_TextBox3 = CreateWindowEx(WS_EX_CLIENTEDGE, "Edit" , NULL,
    WS_CHILD | ES_WANTRETURN | WS_VISIBLE,
    66, 220, 385, 35, hwndMainWindow,
    (HMENU)TextBox3, hInstance, NULL);

SetWindowFont(hwnd_TextBox3, MSSansSerif_8pt, TRUE);

return;
}



HWND GetItem(int nIDDlgItem)
{
switch(nIDDlgItem)
{
    case -1:
        return GetParent(hwnd_Label1);
    case Label1:
        return hwnd_Label1;
    case Label2:
        return hwnd_Label2;
    case TextBox1:
        return hwnd_TextBox1;
    case TextBox2:
        return hwnd_TextBox2;
    case CommandButton1:
        return hwnd_CommandButton1;
    case TextBox3:
        return hwnd_TextBox3;
    default: return NULL;
}
}



void Form_Unload(HWND hMainWnd)
{
DeleteFont(MSSansSerif_8pt);
return;
}

I tried many times, but could not. Even if you give me links to good sites, then I will be grateful.

+5
source share
2 answers

Win32 API, C. , , , . , ( ) Windows. 5- , , Win32.

, , " Win32". (, ANSI Unicode), - . , , -, - . byForger - , .

, GUI ( ) , . , , . , C, .


, hwnd_TextBoxX, X - 1 3. , , , hwnd (wnd), .

Win32 API GetWindowText, . (hwnd), , . C - , C, .

, , , , SetWindowText , (hwnd) , .

:

// Get the text displayed in textbox 1
TCHAR szBuffer[100];
GetWindowText(hwnd_TextBox1, szBuffer, 100);

// Display that text in textbox 3
SetWindowText(hwnd_TextBox3, szBuffer);

, Win32 "" -window-. , , (, ), - , , .

, BN_CLICKED WM_COMMAND. WM_COMMAND (WndProc), , lParam (hwnd) HIWORD(wParam) .

, . " ".

+7

GUI-, API Win32, , . - . , . , .

main WinMain. . .

, "", "". WinAPI "", "", "". "" . (HWND). , CreateWindow. , CreateChildWindows, GUI . ( ) .

. , . , . . , WM_COMMAND, . , WinMain, - , WndProc .

, , . , , GUI:)

+1

All Articles