我用 C 语言开发了蒸汽表方程求解器……但是在黑屏控制台中输入值很无聊。
所以我非常想用 C 创建简单的 GUI。
我搜索了hello world代码,都很长。但这是我唯一理解的。
#include <windows.h>
int main()
{
MessageBoxA( NULL, "Hello World!", "Hello", MB_OK );
}
通过使用 C 的 gui 构建器,我得到了这段代码,现在我在想如何在单击 COMMANDBUTTON1 时扫描 TEXTBOX1 和 TEXTBOX2 的值并在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;
}
我尝试了很多次,但都失败了。即使你们给我好的网站链接,我也会很感激的。