如何能夠用c語言編寫一個可視化的界面?
//調用api函數創建窗口
//示例:
#include <windows.h>
LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM);//窗口過程函數
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, PSTR szCmdLine, int iCmdShow)
{
static TCHAR szAppName[] = TEXT("MyWindows");//定義窗口類名
HWND hwnd;//窗口句柄
MSG msg; //
WNDCLASS wndclass; //窗口類
wndclass.style = CS_HREDRAW | CS_VREDRAW;//指定窗口類型,各種“類風格”(詳見下方↓)可以使用按位或操作符組合起來
wndclass.lpfnWndProc = WndProc;//指定窗口過程(必須是回調函數)
wndclass.cbClsExtra = 0;//預留的額外空間,一般為 0
wndclass.cbWndExtra = 0;//預留的額外空間,一般為 0
wndclass.hInstance = hInstance;//應用程序的實例句柄
wndclass.hIcon = LoadIcon(NULL, IDI_APPLICATION);//為所有基于該窗口類的窗口設定一個圖標
wndclass.hCursor = LoadCursor(NULL, IDC_ARROW);//為所有基于該窗口類的窗口設定一個鼠標指針
wndclass.hbrBackground = (HBRUSH)GetStockObject(WHITE_BRUSH);//指定窗口背景色
wndclass.lpszMenuName = NULL;//指定窗口菜單
wndclass.lpszClassName = szAppName;//指定窗口類名
if (!RegisterClass(&wndclass))//注冊窗口
{
MessageBox(NULL, TEXT("這個程序需要在 Windows NT 才能執行!"), szAppName, MB_ICONERROR);
return 0;
}
hwnd = CreateWindow(szAppName, //創建窗口
TEXT("windows"),
WS_OVERLAPPEDWINDOW,
CW_USEDEFAULT,
CW_USEDEFAULT,
CW_USEDEFAULT,
CW_USEDEFAULT,
NULL,
NULL,
hInstance,
NULL);
ShowWindow(hwnd, iCmdShow); //顯示窗口
UpdateWindow(hwnd); //更新窗口,重繪
while (GetMessage(&msg, NULL, 0, 0)) //獲得消息
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
return msg.wParam;
}
LRESULT CALLBACK WndProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)//回調函數
{
HDC hdc;
PAINTSTRUCT ps;
rect rect;
switch (message)
{
case WM_PAINT:
hdc = BeginPaint(hwnd, &ps);
GetClientRect(hwnd, &rect);
DrawText(hdc, TEXT("第一個c語言窗口程序!"), -1, &rect,
DT_SINGLELINE | DT_CENTER | DT_VCENTER);
EndPaint(hwnd, &ps);
return 0;
case WM_DESTROY:
PostQuitMessage(0);
return 0;
}
return DefWindowProc(hwnd, message, wParam, lParam);
}