c窗体设计
① 用C语言编写设计一个Windows应用程序窗口界面。
您好!
小弟建议您用 Visual C# 2008 软件
这不是问题,这是标准模块
属于秒杀问题 根本不需要任何演算法(内建)!
② c语言程序设计窗体
|建立窗口很简单,只需呼叫CreateWindow函数即可。
HELLOWIN.C
/*------------------------------------------------------------------------
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 ;
WNDCLASwndclass ;
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.lpszMenuNam = 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) ;
}
③ C语言窗口界面如何美化
首先修改背景字体颜色 :
颜色属性由两十六进制数字指定 -- 第背景第二个则是前景,
每个数字内可以容为以下任何值之一
0 = 黑色 8 = 灰色
1 = 蓝色 9 = 淡蓝色
2 = 绿色 A = 淡绿色
3 = 浅绿色 B = 淡浅绿色
4 = 红色 C = 淡红色
5 = 紫色 D = 淡紫色
6 = 黄色 E = 淡黄色
7 = 白色 F = 亮白色
④ 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语言开发窗体应用程序。。
生产窗体可以使用CreateWindowEx函数。
函数功能:该函数创建一个具有扩展风格的层叠式窗口、弹出式窗口或子窗口,其他与CreateWindow函数相同。
函数原型:
CreateWindowEx函数创建一个层叠的,自动弹出的(pop-up)或是一个子窗口通过扩展格式。另外这个函数的作用与CreateWindow函数的作用相同。要获得更多的关于创建窗口的信息和关于CreateWindowEx函数参数的详细描述。参见CreateWindow
HWND CreateWindowEx(
DWOR DdwExStyle, //窗口的扩展风格
LPCTSTR lpClassName, //指向注册类名的指针
LPCTSTR lpWindowName, //指向窗口名称的指针
DWORD dwStyle, //窗口风格
int x, //窗口的水平位置
int y, //窗口的垂直位置
int nWidth, //窗口的宽度
int nHeight, //窗口的高度
HWND hWndParent, //父窗口的句柄
HMENU hMenu, //菜单的句柄或是子窗口的标识符
HINSTANCE hInstance, //应用程序实例的句柄
LPVOID lpParam //指向窗口的创建数据
);例程:
include<windows.h>
#include<stdio.h>
LRESULTCALLBACKWinDouProc(
HWNDhwnd,//handletowindow
UINTuMsg,//messageidentifier
WPARAMwParam,//firstmessageparameter
LPARAMlParam//secondmessageparameter
);
classCWnd
{
public:
CWnd()
{
m_hWnd=NULL;
}
BOOLCreateEx(
DWORDdwExStyle,//extendedwindowstyle
LPCTSTRlpClassName,//pointertoregisteredclassname
LPCTSTRlpWindowName,//pointertowindowname
DWORDdwStyle,//windowstyle
intx,//horizontalpositionofwindow
inty,//verticalpositionofwindow
intnWidth,//windowwidth
intnHeight,//windowheight
HWNDhWndParent,//handletoparentorownerwindow
HMENUhMenu,//handletomenuorchild-windowidentifier
HANDLEhInstance,//handletoapplicationinstance
LPVOIDlpParam//pointertowindow-creationdata
);
BOOLShowWindow(intnCmdShow);
BOOLUpdateWindow();
public:
HWNDm_hWnd;
};
BOOLCWnd::CreateEx(
DWORDdwExStyle,//extendedwindowstyle
LPCTSTRlpClassName,//pointertoregisteredclassname
LPCTSTRlpWindowName,//pointertowindowname
DWORDdwStyle,//windowstyle
intx,//horizontalpositionofwindow
inty,//verticalpositionofwindow
intnWidth,//windowwidth
intnHeight,//windowheight
HWNDhWndParent,//handletoparentorownerwindow
HMENUhMenu,//handletomenuorchild-windowidentifier
HANDLEhInstance,//handletoapplicationinstance
LPVOIDlpParam//pointertowindow-creationdata
)
{
m_hWnd=::CreateWindowEx(dwExStyle,lpClassName,lpWindowName,dwStyle,x,y,nWidth,nHeight,hWndParent,hMenu,(HINSTANCE)hInstance,lpParam);
if(m_hWnd!=NULL)
returnTRUE;
else
returnFALSE;
}
BOOLCWnd::ShowWindow(intnCmdShow)
{
return::ShowWindow(m_hWnd,nCmdShow);
}
BOOLCWnd::UpdateWindow()
{
return::UpdateWindow(m_hWnd);
}
intWINAPIWinMain(
HINSTANCEhInstance,//handletocurrentinstance
HINSTANCEhPrevInstance,//handletopreviousinstance
LPSTRlpCmdLine,//pointertocommandline
intnCmdShow//showstateofwindow
)
{
WNDCLASSwndclass;//先设计窗口类
wndclass.cbClsExtra=0;
wndclass.cbWndExtra=0;
wndclass.hbrBackground=(HBRUSH)GetStockObject(DKGRAY_BRUSH);
wndclass.hCursor=LoadCursor(NULL,IDC_HELP);
wndclass.hIcon=LoadIcon(NULL,IDI_WARNING);
wndclass.hInstance=hInstance;
wndclass.lpfnWndProc=WinDouProc;
wndclass.lpszClassName="Magic_Maggie";
wndclass.lpszMenuName=0;
wndclass.style=CS_VREDRAW|CS_HREDRAW;
//某一个变量原油几个变量去掉一个特征,可以用取反(~)后再进行与(&)
//例如:style上去掉CS_NOCLOSE,可以style&~CS_NOCLOSE;
RegisterClass(&wndclass);///注意先建立再注册昂
CWndwnd;
wnd.CreateEx(NULL,"Magic_Maggie","DouDou",WS_OVERLAPPEDWINDOW,0,0,800,600,NULL,NULL,hInstance,NULL);
wnd.ShowWindow(SW_SHOWNORMAL);
wnd.UpdateWindow();
MSGmsg;//消息循环
while(GetMessage(&msg,NULL,0,0))
{
TranslateMessage(&msg);
DispatchMessage(&msg);//触发WinDouProc
}
return0;
}
LRESULTCALLBACKWinDouProc(
HWNDhwnd,//handletowindow
UINTuMsg,//messageidentifier
WPARAMwParam,//firstmessageparameter
LPARAMlParam//secondmessageparameter
)
{
switch(uMsg)
{
caseWM_LBUTTONDOWN:
MessageBox(hwnd,"您按下了鼠标左键昂","豆豆的程序",MB_OK);
HDChdc;
hdc=GetDC(hwnd);
//.text.
TextOut(hdc,0,0,"感谢您对豆豆程序的支持昂",strlen("感谢您对豆豆程序的支持昂"));
ReleaseDC(hwnd,hdc);
break;
caseWM_CHAR:
charszChar[20];
sprintf(szChar,"Charis%d",wParam);
MessageBox(hwnd,szChar,"豆豆的程序",MB_OK);
break;
caseWM_PAINT:
PAINTSTRUCTps;
HDChDc;
hDc=BeginPaint(hwnd,&ps);
TextOut(hDc,0,0,"这个是重绘滴哦",strlen("这个是重绘滴哦"));
EndPaint(hwnd,&ps);
break;
caseWM_CLOSE://这个case与下边的destroy这个case不要弄错了,否则窗口不出现,但任务管理器中运行
if(IDYES==MessageBox(hwnd,"您真的要退出么?","豆豆的程序",MB_YESNO))
{
DestroyWindow(hwnd);
}
break;
caseWM_DESTROY:
PostQuitMessage(0);
//////////////////////////////////////////?????????????????????
break;
default:
returnDefWindowProc(hwnd,uMsg,wParam,lParam);//别忘记了return
}
return0;
}
⑥ C#窗体设计
c#高级编程第四版来,如果有基础的话看源这本书,可以说深入浅出,窗体设计+控件介绍+实例一共就40页左右,花两天时间看完就入门了.
不要想去找什么视频教程,又不清晰又拖沓,反而没什么效率,还是自己边看书边操作更直接!
⑦ 怎样用c语言设计立体窗口
立体窗口?你还想搞3D窗口吗?如果只是想写普通的窗口程序,可以用相关的API
⑧ C语言怎么设计窗口呀
楼主
首先这不是c与c#区别
你学c#的时候之所以有这些控件,能进行界面编辑是因为你内建的是winform程序容,在编辑的时候实际上也是有代码控制的。如果你c#建的是控制台程序的话就会与c语言一样了,但是你在应用中加入 using System.Windows.Forms;那么就可以调用winform程序的控件了。
一般的话你是为了学习一种语言的话建议学习控制台应用程序。如果用界面的话对你语言学习没有什么好处,反而会让你分心。当你真真学习做一个项目的时候可以用winform来了。反正当你学习到一定程度你就会明白其中的关系了。
对于c语言的话我本人只用过控制台,通过代码来创建窗口,也是可以产生你所需要的效果的。
你要明白现在你要学的是一门语言,你要懂得语法等知识,而不是费心去拉几个控件,所以好好的学好基础吧。c#的话也在控制台上来联系。你要学的不是开发工具,所以不要把精力浪费在这里,而且还把自己搞得乱七八糟的。
至于楼上的,vc是c++的编译工具,只不过可以运行c语言程序而已,楼主用的工具比vc好的多,vc老了,楼主的才是新版,不用理会
⑨ C,C++设计出窗口程序的方法
主流当来然是MFC(Microsoft Foundation Classes),win32 Application 中的自API 函数 Create也可以绘制出一个窗口 再用ShowWindow显示窗口 UpdateWindow更新窗口
⑩ 怎么设计C语言立体窗口
所谓立体窗口实际上就是你自己画出阴影,可以先下面画出深色背景,然后在上面用正常背景色画,类似这样的效果。