用C语言可以进行有界面的编程吗
1、Windows下用API函数完全可以进行图形界面编程,不过效率太低,不如用VC、VB这种东西直接用鼠标拖放生成来得方便。非图形界面就容易一些了,命令行对话式界面在技术上很容易。
2、例程:
// Window.cpp : Defines the entry point for the application.
#include windows.h
LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM);
int APIENTRY WinMain(HINSTANCE hInstance, //应用程序的实例句柄,
HINSTANCE hPrevInstance,
LPSTR lpCmdLine, //命令行
int nCmdShow) //显示方式
{
MSG msg;
HWND hWnd;
char szTitle[]=”系统信息”; // The title bar text
char szWindowClass[]=”popMsg”; // The title bar text
WNDCLASSEX wcex={0};
wcex.cbSize = sizeof(WNDCLASSEX); //WNDCLASSEX结构体大小
wcex.style = CS_HREDRAW | CS_VREDRAW; //位置改变时重绘
wcex.lpfnWndProc = (WNDPROC)WndProc; //消息处理函数
wcex.hInstance = 0; //当前实例句柄
wcex.hbrBackground = (HBRUSH)COLOR_WINDOWFRAME; //背景色
wcex.lpszClassName = szWindowClass; //参窗口类名
wcex.hIcon =0; //图标
wcex.hCursor =LoadCursor(NULL, IDC_ARROW); //光标
wcex.lpszMenuName =0; //菜单名称
wcex.hIconSm =0; //最小化图标
RegisterClassEx(wcex); //注册窗口类
hWnd = CreateWindow(szWindowClass, szTitle, WS_SYSMENU|WS_VISIBLE, //创建窗口
CW_USEDEFAULT,CW_USEDEFAULT, 400, 300, NULL, NULL, 0, NULL);
if (!hWnd){
return FALSE;
}
ShowWindow(hWnd, nCmdShow);
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)
{
PAINTSTRUCT ps;
HDC hdc;
RECT rect;
switch (message)
{
case WM_PAINT: //重绘消息
hdc = BeginPaint(hWnd, ps);
GetClientRect(hWnd, rect);
MoveToEx(hdc,10,10,0);
SelectObject( hdc,::CreatePen(PS_SOLID,1,RGB(0xFF,0,0)));
LineTo(hdc,100,200);
// DrawText(hdc, szHello, strlen(szHello), rt, DT_CENTER);
EndPaint(hWnd, ps);
break;
case WM_CREATE:
RegisterHotKey(hWnd ,1, 0 ,0x41 );
break;
case WM_HOTKEY:
MessageBox(0,0,0,0);
break;
case WM_TIMER:
break;
case WM_DESTROY: //窗口销毁消息
PostQuitMessage(0);
break;
default:
return DefWindowProc(hWnd, message, wParam, lParam);
}
return 0;
}
C语言能不能写软件界面,有的话具体怎么写
C++可以写。这个是windows窗口的写法:
#include windows.h
LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM); /* Declare Windows procedure */
char szClassName[ ] = “WindowsApp”; /* Class Name */
int WINAPI WinMain(HINSTANCE hThisInstance,
HINSTANCE hPrevInstance,
LPSTR lpszArgument,
int nFunsterStil)
{
HWND hwnd; /* This is the handle for our window */
MSG messages; /* Here messages to the application are saved */
WNDCLASSEX wincl; /* Data structure for the windowclass */
/* The WNDCLASSEX structure */
wincl.hInstance = hThisInstance;
wincl.lpszClassName = szClassName;
wincl.lpfnWndProc = WndProc; /* This function is called by windows */
wincl.style = CS_DBLCLKS; /* Catch double-clicks */
wincl.cbSize = sizeof(WNDCLASSEX);
wincl.hIcon = LoadIcon(NULL, IDI_APPLICATION);
wincl.hIconSm = LoadIcon(NULL, IDI_APPLICATION);
wincl.hCursor = LoadCursor(NULL, IDC_ARROW);
wincl.lpszMenuName = NULL; /* No menu */
wincl.cbClsExtra = 0;
wincl.cbWndExtra = 0;
wincl.hbrBackground = (HBRUSH) GetStockObject(WHITE_BRUSH);
/* Register the window class, if fail quit the program */
if(!RegisterClassEx(wincl)) return 0;
/* The class is registered, create the window*/
hwnd = CreateWindowEx(
0,
szClassName,
“Simple Windows App”,
WS_OVERLAPPEDWINDOW,
CW_USEDEFAULT,
CW_USEDEFAULT,
500,
300,
HWND_DESKTOP,
NULL,
hThisInstance,
NULL
);
/* Make the window visible on the screen */
ShowWindow(hwnd, nFunsterStil);
/* Run the message loop. It will run until GetMessage( ) returns 0 */
while(GetMessage(messages, NULL, 0, 0))
{
TranslateMessage(messages);
DispatchMessage(messages);
}
/* The program return-value is 0 – The value that PostQuitMessage( ) gave */
return messages.wParam;
}
/* This function is called by the Windows function DispatchMessage( ) */
LRESULT CALLBACK WndProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
{
switch (message) /* handle the messages */
{
case WM_DESTROY:
PostQuitMessage(0); /* send a WM_QUIT to the message queue */
break;
default: /* for messages that we don’t deal with */
return DefWindowProc(hwnd, message, wParam, lParam);
}
return 0;
}
c语言能不能写带界面的软件!?
可以的,但是C语言写界面需要用到windows API,这部分不是太难,难的在于消息处理上边,想做界面开发用MFC好些,已经将大多数API封装起来了,用起来也比较方便,你只用处理消息响应函数就行。如果你想深入研究界面的运行的原理你可以使用纯C,如果不是的话还是用MFC
c语言可以用于制作网页吗?
1、c语言是偏底层的语言,用来做界面的话是比较困难的
2、现在的静态网页设计一般使用Html+CSS,是比较基础的东西,而且很容易上手,但也是必须掌握的。
3、现在主流的网站开发就是Java Web和asp.net。
如果你有java基础可以走Java web的方向。可以用JSP+Servlet+Dao模式就能开发网站,当然SSH框架更加深奥。
而asp.net由于是微软自己开发的软件能很好的在windows平台上运行,用的是C#语言其实也和C语言差不多,因为语言是相通的,你学过一门语言后你就会有那种编程的思想。
asp.net是.NET FrameWork的一部分,是一项微软公司的技术,是一种使嵌入网页中的脚本可由因特网服务器执行的服务器端脚本技术,它可以在通过HTTP请求文档时再在Web服务器上动态创建它们。 指 Active Server Pages(动态服务器页面) ,运行于 IIS(Internet Information Server 服务,是Windows开发的Web服务器)之中的程序 。
4、另外,在进行网站开发时为了提高容错能力,脚本语言是必不可少的,所以javascript或
php也是要懂一点点
C语言编写的程序可以实现界面化吗?
可以,但是很麻烦,需要编写很长的代码!你可以学面向对象的程序设计软件,比如VF,VB.