因为网站的事情忙碌了一段时间,然后继续打算研究怎么读取~~~结果~~那些子模块还是没有读取成功…………
回个头来研究一下MFC~~~
窗体的创建过程如下:
1、设计窗体类:WNDCLASS
2、注册这个类:RegisterClass(&wndcls);
3、通过这个类创建窗体句柄:
eg: hwnd=CreateWindow( "sunxin2006", //所使用的窗体类
"http://www.sunxin.org", //窗体标题
WS_OVERLAPPEDWINDOW, //样式
0, //x
0, //y
600, //宽
400, //高
NULL, //父窗体句柄
NULL, //菜单句柄
hInstance, //包含窗体的实例句柄
NULL //附加参数
);
4、显示窗体:ShowWindow
5、刷新窗体:UpdateWindow
6、最后循环一下消息
7、回调函数:一般也就是用来处理消息函数的部分…………
#include
<
windows.h
>
#include
<
iostream
>
//
定义回调函数
LRESULT CALLBACK WinSunProc(
HWND hwnd,
UINT uMsg,
WPARAM wParam,
LPARAM lParam
);
//
主函数
int
WINAPI WinMain(
HINSTANCE hInstance,
HINSTANCE hPrevInstance,
LPSTR lpCmdLine,
int
nCmdShow
)
...
{
//设计一个窗口类
WNDCLASS wndcls;
wndcls.cbClsExtra = 0;
wndcls.cbWndExtra = 0;
wndcls.hbrBackground = (HBRUSH)GetStockObject(BLACK_BRUSH);
wndcls.hCursor = LoadCursor(NULL,IDC_CROSS);
wndcls.hIcon = LoadIcon(NULL,IDI_ERROR);
wndcls.hInstance = hInstance;
wndcls.lpfnWndProc = WinSunProc;
wndcls.lpszClassName = "mywindows";
wndcls.lpszMenuName = NULL;
wndcls.style = CS_HREDRAW|CS_VREDRAW;
RegisterClass(&wndcls);
//创建窗口,定义一个变量用来保存成功创建窗口后返回的句柄
HWND hwnd;
hwnd = CreateWindow("mywindows","我的窗口",WS_OVERLAPPEDWINDOW,0,0,600,400,NULL,NULL,hInstance,NULL);
//显示及刷新窗口
ShowWindow(hwnd,SW_SHOWNORMAL);
UpdateWindow(hwnd);
MSG msg;
while(GetMessage(&msg,NULL,0,0))
...{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
return msg.wParam;
}
LRESULT CALLBACK WinSunProc(
HWND hwnd,
UINT uMsg,
WPARAM wParam,
LPARAM lParam
)
...
{
switch(uMsg)
...{
case WM_CHAR:
char szChar[20];
sprintf(szChar,"Char Code is %C",wParam);
MessageBox(hwnd,szChar,"Char",0);
break;
case WM_CLOSE:
if(IDYES == MessageBox(hwnd,"是否关闭窗口?","结束",MB_YESNO))
...{
DestroyWindow(hwnd);
}
case WM_DESTROY:
PostQuitMessage(0);
break;
default:
return DefWindowProc(hwnd,uMsg,wParam,lParam);
}
return 0;
}