C++必须使用MFC来创建窗口? 5

新手刚学,在看教程中发现视频教程中使用MFC来创建窗口,我想问下C++必须使用MFC来创建窗口吗,C++自身不能创建窗口吗,如果能怎么办才能使用C++不使用MFC创建窗口... 新手刚学,在看教程中发现视频教程中使用MFC来创建窗口,我想问下C++必须使用MFC来创建窗口吗,C++自身不能创建窗口吗,如果能怎么办才能使用C++不使用MFC创建窗口。。
还是因为MFC创建窗口比C++速度快??省事????
展开
 我来答
chichujn
2011-06-08 · TA获得超过663个赞
知道小有建树答主
回答量:1534
采纳率:50%
帮助的人:1076万
展开全部
可以用API创建窗口的。MFC只是做了一定的封装,大大方便使用了而已。如下是DEV-C++里一个sample,用的API。
#include <windows.h>

/* Declare Windows procedure */
LRESULT CALLBACK WindowProcedure (HWND, UINT, WPARAM, LPARAM);

/* Make the class name into a global variable */
char szClassName[ ] = "WindowsApp";

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 Window structure */
wincl.hInstance = hThisInstance;
wincl.lpszClassName = szClassName;
wincl.lpfnWndProc = WindowProcedure; /* This function is called by windows */
wincl.style = CS_DBLCLKS; /* Catch double-clicks */
wincl.cbSize = sizeof (WNDCLASSEX);

/* Use default icon and mouse-pointer */
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; /* No extra bytes after the window class */
wincl.cbWndExtra = 0; /* structure or the window instance */
/* Use Windows's default color as the background of the window */
wincl.hbrBackground = (HBRUSH) COLOR_BACKGROUND;

/* Register the window class, and if it fails quit the program */
if (!RegisterClassEx (&wincl))
return 0;

/* The class is registered, let's create the program*/
hwnd = CreateWindowEx (
0, /* Extended possibilites for variation */
szClassName, /* Classname */
"Windows App", /* Title Text */
WS_OVERLAPPEDWINDOW, /* default window */
CW_USEDEFAULT, /* Windows decides the position */
CW_USEDEFAULT, /* where the window ends up on the screen */
544, /* The programs width */
375, /* and height in pixels */
HWND_DESKTOP, /* The window is a child-window to desktop */
NULL, /* No menu */
hThisInstance, /* Program Instance handler */
NULL /* No Window Creation data */
);

/* 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))
{
/* Translate virtual-key messages into character messages */
TranslateMessage(&messages);
/* Send message to WindowProcedure */
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 WindowProcedure (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;
}
zy020118
2011-06-08
知道答主
回答量:21
采纳率:0%
帮助的人:20.5万
展开全部
C++自身能创建窗口,需要调用Windows API创建窗口
MFC,是微软提供的,用于在C++环境下编写应用程序的一个框架和引擎
所以用MFC创建窗口比C++速度快,省事
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
cnf1980
2011-06-08 · TA获得超过1.5万个赞
知道大有可为答主
回答量:1.2万
采纳率:54%
帮助的人:2473万
展开全部
C++下自定义窗口比较复杂,初学者如果有兴趣也可以学学的。
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
浅夏微凉耶
2011-06-08 · TA获得超过1390个赞
知道小有建树答主
回答量:1865
采纳率:0%
帮助的人:716万
展开全部
可以用API 来创建窗口的。
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
匿名用户
2011-06-08
展开全部
图形界面还是java比较好用,直接拖动就可以实现编程了。C++的话,不了解。
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
收起 更多回答(3)
推荐律师服务: 若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询

为你推荐:

下载百度知道APP,抢鲜体验
使用百度知道APP,立即抢鲜体验。你的手机镜头里或许有别人想知道的答案。
扫描二维码下载
×

类别

我们会通过消息、邮箱等方式尽快将举报结果通知您。

说明

0/200

提交
取消

辅 助

模 式