mobile28365365
用C语言编写的程序,如何制作UI界面
它采用
C生产UI界面需要关联的UI库(例如Windows操作系统本身)来提供UI界面。这是#includewindows的一个简单代码示例:
hLRESULTCALLBACKWndProc(HWND,UINT,WPARAM,LPARAM); intWINAPIWinMain(HINSTANCEhinstance,HINSTANCEhprevinstance,LPSTRline,intcmd / GCS / GCC)
Style = CS_HREDRAW | CS_VREDRAW。WNDCLASS
lpfnWndProc = WndProc; Wndclass
cbClsExtra = 0; Wndclass
cbWndExtra = 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 = AppName; if(!
RegisterClass(&wndclass)){MessageBox(NULL,TEXT(此程序需要Windows NT)。
),AppName,MB_ICONERROR)。returnw;}hwnd = CreateWindow(AppName,TEXT(Jiujiushengfa公式表),WS_OVERLAPPEDWINDOW,CW_USEDEFAULT,CW_USEDEFAULT,CW_USEDEFAULT,CW_USEDEFAULT,NULL,NULL,hInstance,NULL); ShowWindow(hwnd,cmd); UpdateWindow(hwnd); while(GetMessage)(&Msg,NULL,0,0)){TranslateMessage(DispatchMessage(}returnmsg)
LRESULTCALLBACKWndProc(HWNDhwnd,UINT消息,WPARAMwparam,LPARAMlparam){HDChdc; wParam;}PAINTSTRUCTps; RECTrectac;
tmAveCharWidth; y = tm。
tmHeight + tm
tm External Leading; ReleaseDC(HWND,HDC)。MessageBox(NULL,TEXT(CreateSuccessed!)
),TEXT(成功),MB_OK)。PlaySound(TEXT(你好。
wav),NULL,SND_FILENAME | SND_ASYNC);返回0; case WM_PAINT:HDC = BeginPaint函数(hWnd,GetClientRect(hWnd,DrawText(HDC,TEXT(HelloWorld!
- )1和矩形,DT_SINGLELINE | DT_CENTER | DT_VCENTER); TextOut(HDC,RECT)。
right2-(strlen(HelloWorld!
)2)* x,平方。
降低2-y2,TEXT(HelloWorld!
,12)。(我= 1;我!
= 10; ++ i){(j = 1; j!
= I + 1。++ j)的{LEN = wsprintf(BUF,TEXT(%DX%d =% - 4 d)中,j,I,I * j)的;的TextOut(HDC,J * LEN * X,I * Y,BUF,LEN);}}调用EndPaint(HWND,return0; caseWM_DESTROY:PostQuitMessage(0); return0;}returnDefWindowProc(HWND,消息,WPARAM,LPARAM);}下一个打印窗口的C语言代码与公式相同的C语言Jiujiushengfa先前窗口接口表程序有其他用户界面库,如GTK,GTK库的用户界面是可移植的,可以与Linux和操作系统一起使用。简单的用户界面如Mac编程示例代码如下#Includegtkgtk窗口包含。
hintmain(intargc,char ** argv){GtkWidget * win; GtkWidget *标签。英蒂,j。GString * str; gtk_init(和argc,Win = gtk_window_new(GTK_WINDOW_TOPLEVEL); gtk_window_set_position(GTK_WINDOW(WIN),GTK_WIN_POS_CENTER); g_signal_connect(G_OBJECT(win)); = 1; I = 9;1,J!
= I + 1。++ j)g_string_append_printf(str,%dx%d =% - 4 d,j,i * j); g_string_append(STR,N)}label = gtk_label_new(STR-STR)。gtk_container_add(GTK_CONTAINER(win),label); gtk_widget_show_all(win); gtk_main(); g_string_free(str,TRUE); return 0;


Time:2019-09-14 08:53:50  编辑:admin
RETURN