当前位置:首页 » 编程语言 » c语言窗口程序

c语言窗口程序

发布时间: 2022-01-18 06:56:29

① 如何用c语言编写一个窗体应用程序

最好不要,稍微麻烦一点的窗体程序你就搞不定,而且资料非常少
比较合算的应该是C#的WPF, VC的MFC,都不是C语言的

② c语言怎么编辑可视窗口程序

C语言是编辑程序

可视窗口程序是就是软件了,C语言介于汇编语言和高级语言之间是不能直接编辑成软件的

学通了C语言,其他语言还在话下吗?

③ 怎么用c语言写窗体程序

步骤:
1、注册窗口类;
2、创建窗体;
3、消息循环;
4、编写窗口消息处理函数。

代码:


#include<windows.h>
#include<tchar.h>
LRESULTCALLBACKWindowProc(HWNDhwnd,UINTmsg,WPARAMwParam,LPARAMlParam);
intWINAPI_tWinMain(HINSTANCEhInstance,HINSTANCEhPrevInstance,LPWSTRszCmdLine,intnCmdShow)
{
WNDCLASSwc;
wc.style=CS_HREDRAW|CS_VREDRAW;
wc.lpfnWndProc=WindowProc;
wc.cbClsExtra=0;
wc.cbWndExtra=0;
wc.hInstance=hInstance;
wc.hIcon=NULL;
wc.hCursor=LoadCursor(NULL,IDC_ARROW);
wc.hbrBackground=(HBRUSH)COLOR_WINDOW;//(HBRUSH)GetStockObject();
wc.lpszMenuName=NULL;
wc.lpszClassName=_T("MyWindowClass");
if(!RegisterClass(&wc))
{
MessageBox(NULL,_T("无法注册窗口类"),_T("错误"),MB_OK);
return0;
}
HWNDnewWindow=CreateWindow(
_T("MyWindowClass"),
_T("我的第一个winapi程序"),
WS_OVERLAPPEDWINDOW,
0,
0,
CW_USEDEFAULT,
CW_USEDEFAULT,
NULL,
NULL,
hInstance,
NULL
);
if(NULL==newWindow)
{
MessageBox(NULL,_T("无法创建窗体"),_T("错误"),MB_OK);
return0;
}
ShowWindow(newWindow,nCmdShow);
UpdateWindow(newWindow);
MSGmsg;
while(GetMessage(&msg,NULL,0,0))
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
}
LRESULTCALLBACKWindowProc(HWNDhwnd,UINTuMsg,WPARAMwParam,LPARAMlParam)
{
switch(uMsg)
{
caseWM_DESTROY:
{
PostQuitMessage(0);
break;
}
default:
returnDefWindowProc(hwnd,uMsg,wParam,lParam);
}
return0;
}

就是一个只有标题栏、关闭按钮、最小化按钮、最大化/还原按钮、显示区域的窗体。

④ 如何用C语言开发窗体应用程序。。

C语言是一门通用计算机编程语言,应用广泛。C语言的设计目标是提供一种能以简易的方式编译、处理低级存储器、产生少量的机器码以及不需要任何运行环境支持便能运行的编程语言。
尽管C语言提供了许多低级处理的功能,但仍然保持着良好跨平台的特性,以一个标准规格写出的C语言程序可在许多电脑平台上进行编译,甚至包含一些嵌入式处理器(单片机或称MCU)以及超级电脑等作业平台。
#include <windows.h>

//Function prototype.
int WINAPI WinMain(HINSTANCE,HINSTANCE ,LPSTR ,int);
LRESULT CALLBACK MainWndProc(HWND ,UINT ,WPARAM,LPARAM);

InitApplication(HINSTANCE);
InitInstance(HINSTANCE,int);

LRESULT CALLBACK MainWndProc(HWND hwnd,UINT nMsg,WPARAM wParam,LPARAM lParam)
{
HDC hdc;
PAINTSTRUCT ps;
RECT rect;

switch(nMsg)
{
case WM_COMMAND:
{
hdc = GetDC((HWND)lParam);
GetClientRect ((HWND)lParam, &rect) ;
DrawText(hdc,"HOHO",-1,&rect,
DT_SINGLELINE | DT_CENTER | DT_VCENTER);
ReleaseDC((HWND)lParam,hdc);
}
break;
case WM_PAINT:
{
hdc = BeginPaint(hwnd,&ps);
GetClientRect (hwnd, &rect) ;
DrawText(hdc,"Hello Word",-1,&rect,
DT_SINGLELINE | DT_CENTER | DT_VCENTER);
EndPaint(hwnd,&ps);
}
break;
//按键
case WM_KEYDOWN:

if(wParam == VK_ESCAPE)
SendMessage(hwnd,WM_CLOSE,0,0);

break;
case WM_CHAR:
switch(wParam)
{
case 'w':
MessageBox(hwnd,"UP","KeyBorad Input",MB_OK);
break;
case 's':
MessageBox(hwnd,"DOWN","KeyBorad Input",MB_OK);
break;
case 'a':
MessageBox(hwnd,"LEFT","KeyBorad Input",MB_OK);
break;
case 'd':
MessageBox(hwnd,"RIGHT","KeyBorad Input",MB_OK);
break;
}
break;

//关闭
case WM_CLOSE:
DestroyWindow(hwnd);
break;
case WM_DESTROY:
PostQuitMessage(0);
break;

default:
return DefWindowProc(hwnd,nMsg,wParam,lParam);
}
return 0;
}

int WINAPI WinMain(HINSTANCE hInstance,HINSTANCE hPreInStance,
LPSTR lpCmdLine,int nCmdShow)
{
MSG msg;

if(!InitApplication(hInstance))
{
MessageBox(NULL,"InitApplication Failed","Error!",MB_ICONEXCLAMATION | MB_OK);
return FALSE;
}
if(!InitInstance(hInstance,nCmdShow)){
MessageBox(NULL,"InitInstance Failed","Error!",MB_ICONEXCLAMATION | MB_OK);
return FALSE;
}

while(GetMessage(&msg,(HWND) NULL,0,0)>0)
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
return msg.wParam;
}

InitApplication(HINSTANCE hInstance)
{
WNDCLASS wc;

wc.style = CS_DBLCLKS;
wc.lpfnWndProc = MainWndProc;
wc.cbClsExtra = 0;
wc.cbWndExtra = 0;
wc.hInstance = hInstance;
wc.hIcon = LoadIcon(NULL,IDI_APPLICATION);
wc.hCursor = LoadCursor(NULL,IDC_ARROW);
wc.hbrBackground = (HBRUSH)(COLOR_WINDOW+1);
wc.lpszMenuName = NULL;
wc.lpszClassName = "MainWClass";
return RegisterClass(&wc);
}

InitInstance(HINSTANCE hInstance,int nCmdShow){
HWND hwnd;
HWND hwndCloseButton;
hwnd = CreateWindow(
"MainWClass",
"Sample",
WS_OVERLAPPEDWINDOW,
CW_USEDEFAULT,
CW_USEDEFAULT,
CW_USEDEFAULT,
CW_USEDEFAULT,
(HWND)NULL,
(HMENU)NULL,
hInstance,
(LPVOID)NULL);

if(!hwnd)
return FALSE;

hwndCloseButton = CreateWindow(
"BUTTON",
"CLOSE",
WS_VISIBLE | WS_CHILD | BS_DEFPUSHBUTTON,
100,
100,
100,
80,
hwnd,
(HMENU)NULL,
hInstance,
(LPVOID)NULL);

if(!hwndCloseButton)
return FALSE;

ShowWindow(hwnd,nCmdShow);
UpdateWindow(hwnd);
return TRUE;
}

⑤ 如何用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);

}

⑥ C语言程序的窗体

可以是可以,但是如果光用C语言的特性来编写Windows窗口程序太费劲,C不适合写窗口程序。给你如下代码,可以在VC中编译成功。

/*------------------------------------------------------------
HELLOWIN.C -- Displays "Hello, Windows 98!" in client area
(c) Charles Petzold, 1998
------------------------------------------------------------*/

#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 ("HelloWin") ;
HWND hwnd ;
MSG msg ;
WNDCLASS wndclass ;

wndclass.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 = szAppName ;

if (!RegisterClass (&wndclass))
{
MessageBox (NULL, TEXT ("This program requires Windows NT!"),
szAppName, MB_ICONERROR) ;
return 0 ;
}

hwnd = CreateWindow (szAppName, // window class name
TEXT ("The Hello Program"), // window caption
WS_OVERLAPPEDWINDOW, // window style
CW_USEDEFAULT, // initial x position
CW_USEDEFAULT, // initial y position
CW_USEDEFAULT, // initial x size
CW_USEDEFAULT, // initial y size
NULL, // parent window handle
NULL, // window menu handle
hInstance, // program instance handle
NULL) ; // creation parameters

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_CREATE:
PlaySound (TEXT ("hellowin.wav"), NULL, SND_FILENAME | SND_ASYNC) ;
return 0 ;

case WM_PAINT:
hdc = BeginPaint (hwnd, &ps) ;

GetClientRect (hwnd, &rect) ;

DrawText (hdc, TEXT ("Hello, Windows 98!"), -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) ;
}

##########################################

这只是在窗口中间显示hello,windows98而已,但是代码却这么长,估计你也看不懂。不管是窗体,还是所有功能事件完全得自己写,太麻烦。研究windows程序运行原理,倒可以学学也无妨。所有windows程序最后编译后都成为这种形式,但是因为写代码的时候完全被面向对象包装了起来,所以都不知道windows程序原来是这么启动的。

⑦ 学c语言如何做出有界面的程序

1、新建一个C项目,点击文件,新建,项目,选择C++Win32控制台应用。

热点内容
一加五安卓8什么时候推送 发布:2024-11-15 11:19:40 浏览:854
暗影骑士擎有哪些配置 发布:2024-11-15 11:13:46 浏览:598
方舟主机专用服务器是什么意思 发布:2024-11-15 11:12:23 浏览:8
创维最早的服务器是什么 发布:2024-11-15 11:11:35 浏览:864
手机配置太低怎么下载原声 发布:2024-11-15 11:03:31 浏览:905
21款奥迪a6配置有哪些 发布:2024-11-15 11:03:20 浏览:120
sql内连接外连接 发布:2024-11-15 11:03:19 浏览:601
学完python基础 发布:2024-11-15 11:01:56 浏览:63
捏泡胶解压 发布:2024-11-15 10:55:07 浏览:803
linux文件最后一行 发布:2024-11-15 10:44:11 浏览:613