c换窗口程序怎么写

1.C语言有什么用,如何C用写窗口程序楼主您好~~
您看看这个 呵呵
其实 我在一年前也和您一样想过这个问题 后来学了MFC才明白 其实黑框程序是在console application工程里运行的那种控制台程序程序 。如果需要编写界面,您应该学MFC啦 装一个VC6.0对照孙鑫老师的视频教程慢慢学就会拉 ~~~画图啊 编写界面啊都很方便的 您试试
2.怎么用c语言写窗体程序步骤:
1、注册窗口类;
2、创建窗体;
3、消息循环;
4、编写窗口消息处理函数 。
代码:
#include <windows.h>
#include<tchar.h>
LRESULT CALLBACK WindowProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam);
int WINAPI _tWinMain (HINSTANCE hInstance, HINSTANCE hPrevInstance, LPWSTR szCmdLine, int nCmdShow)
{
WNDCLASS wc;
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);
return 0 ;
}
HWND newWindow = CreateWindow(
_T("MyWindowClass"),
_T("我的第一个winapi程序"),
WS_OVERLAPPEDWINDOW,
0,
0,
CW_USEDEFAULT,
CW_USEDEFAULT,
NULL,
NULL,
【c换窗口程序怎么写】hInstance,
NULL
);
if (NULL == newWindow)
{
MessageBox (NULL, _T("无法创建窗体"),_T("错误"),MB_OK);
return 0;
}
ShowWindow(newWindow, nCmdShow);
UpdateWindow(newWindow);
MSG msg;
while(GetMessage(&msg, NULL, 0, 0))
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
}
LRESULT CALLBACK WindowProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
{
switch (uMsg)
{
case WM_DESTROY:
{
PostQuitMessage(0);
break;
}
default :
return DefWindowProc(hwnd, uMsg, wParam, lParam);
}
return 0;
}
就是一个只有标题栏、关闭按钮、最小化按钮、最大化/还原按钮、显示区域的窗体 。
3.C语言编写的DOS程序,怎样转换为windows窗口程序#include 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)) { //在Windows 98中,大多数Unicode函数无法执行,MessageBoxW是个例外 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函数检索一个窗口的客户区坐标rect GetClientRect (hwnd, &rect) ; char buf[80]; sprintf(buf,"char 数据类型长度:%d\nstring 数据类型长度:%d\n",sizeof((char)'a'),sizeof("a")); DrawText (hdc, TEXT (buf), -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);} 。