c语言 createwindow 文本框,简单的c编程gui

本文介绍了一位开发者使用C语言和GUI库创建蒸汽表方程求解器的过程,目标是实现一个简单的图形用户界面。文章讨论了如何在点击按钮后从两个文本框读取值,并在第三个文本框中显示输出。尽管面临挑战,作者寻求帮助以完成GUI的交互功能。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

我用C语言开发了蒸汽表方程求解器……但是在黑屏控制台中输入值很无聊.

所以我非常想在C中创建简单的GUI.

我搜索了你好的世界代码,都很长.但这是我理解的唯一一个.

#include

int main()

{

MessageBoxA( NULL, "Hello World!", "Hello", MB_OK );

}

通过使用gui构建器来获取C,我得到了这段代码,现在我正在考虑如何在单击COMMANDBUTTON1时从TEXTBOX1和TEXTBOX2中扫描值并在TEXTBOX3中显示输出?

#define WIN32_LEAN_AND_MEAN

#include

#include

#include

#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;

}

我尝试了很多次,但都失败了.即使你们给我链接好的网站,我也会很高兴.

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值