MFC学习之窗口基础
2014-08-04 13:48
330 查看
WinMain函数
1、句柄(HANDLE):{
1. 定义:资源的标识
2. 句柄的作用: 操作系统通过句柄来找到对应的资源,从而对这些资源进行管理和操作。
3句柄的分类:(按资源){
1.图标句柄(HICON) ,
2.光标句柄(HCURSOR) ,
3. 窗口句柄(HWND) ,
4.应用程序实列句柄(HINSTANCE).
}
}
2、Windows应用程序,操作系统,计算机硬件之间的相互关系
Windows程序的入口函数:
窗口应用程序入口:
Int WINAPI WinMain(
HINSTANCE hinstance ; // 应用程序实列句柄
HINSTANCE hPrevInstance ; // 基本都设置为0
LPSTR ipCmdLine ; /commandLLine LPSTRLP(long point 长指针)
int nCmdSbow ; //显示状态
)
3、 窗口的创建:
大致来说,如果要创建一个完整的窗口需要经过下面四个操作步骤:{
(1)、设计一个窗口类;
(2)、 注册窗口类 ;
(3)、创建窗口;
(4)、显示及更新窗口。
}
效果图:
1、句柄(HANDLE):{
1. 定义:资源的标识
2. 句柄的作用: 操作系统通过句柄来找到对应的资源,从而对这些资源进行管理和操作。
3句柄的分类:(按资源){
1.图标句柄(HICON) ,
2.光标句柄(HCURSOR) ,
3. 窗口句柄(HWND) ,
4.应用程序实列句柄(HINSTANCE).
}
}
2、Windows应用程序,操作系统,计算机硬件之间的相互关系
Windows程序的入口函数:
窗口应用程序入口:
Int WINAPI WinMain(
HINSTANCE hinstance ; // 应用程序实列句柄
HINSTANCE hPrevInstance ; // 基本都设置为0
LPSTR ipCmdLine ; /commandLLine LPSTRLP(long point 长指针)
int nCmdSbow ; //显示状态
)
3、 窗口的创建:
大致来说,如果要创建一个完整的窗口需要经过下面四个操作步骤:{
(1)、设计一个窗口类;
(2)、 注册窗口类 ;
(3)、创建窗口;
(4)、显示及更新窗口。
}
#include<stdio.h> #include<string.h> #include<windows.h> /*声明winSunProc*/ LRESULT CALLBACK WinSunProc( HWND hwnd, // handle to window UINT uMsg, // message identifier WPARAM wParam, // first message parameter LPARAM lParam // second message parameter); ); int WINAPI WinMain( HINSTANCE hInstance, // handle to current instance HINSTANCE hPrevInstance, // handle to previous instance LPSTR lpCmdLine, // command line int nCmdShow // show state); ) { WNDCLASS wndclass; /*声明定义什么的*/ wndclass.cbClsExtra = NULL; wndclass.cbWndExtra = NULL; wndclass.hbrBackground = (HBRUSH)GetStockObject(BLACK_BRUSH); wndclass.hCursor = LoadCursor(NULL,IDC_ARROW); wndclass.hIcon = LoadIcon(NULL,IDI_ERROR); wndclass.hInstance = hInstance; wndclass.lpfnWndProc = WinSunProc ; wndclass.lpszClassName = "Gxjun"; wndclass.lpszMenuName =NULL; wndclass.style= CS_HREDRAW|CS_VREDRAW ; RegisterClass(&wndclass); //注册窗口函数 HWND hwnd; hwnd = CreateWindow("Gxjun","龚细军的第一个窗口程序",WS_OVERLAPPEDWINDOW,0,0,400,600,NULL,NULL,hInstance,NULL); /*创建窗口*/ ShowWindow(hwnd,SW_SHOWNORMAL); /*显示窗口*/ UpdateWindow(hwnd); MSG msg; while(GetMessage(&msg,NULL,0,0)) { TranslateMessage(&msg); /*该函数将虚拟键消息转换为字符消息*/ DispatchMessage(&msg); /*该函数分发一个消息给窗口程序。通常消息从GetMessage函数获得。 消息被分发到回调函数(过程函数),作用是消息传递给操作系统, 然后操作系统去调用我们的回调函数,也就是说我们在窗体的过程函 数中处理消息*/ } return 0; } LRESULT CALLBACK WinSunProc( HWND hwnd, // handle to window UINT uMsg, // message identifier WPARAM wParam, // first message parameter LPARAM lParam // second message parameter); ) { switch(uMsg) { case WM_CHAR: char str[26]; sprintf(str,"char is %d",wParam); MessageBox(hwnd,str,"Gxjun",0); break; case WM_LBUTTONDOWN: MessageBox(hwnd,"mouse clicked","Gxjun",0); HDC hdc; /*PAINTSTRUCT ps;*/ hdc=GetDC(hwnd); TextOut(hdc,200,400,"我是胡萝卜头,呼叫北极站",strlen("我是胡萝卜头,呼叫北极站")); ReleaseDC(hwnd,hdc); /*函数释放设备上下文环境(DC)供其他应用程序使用。*/ break; case WM_PAINT: HDC hdc_1; PAINTSTRUCT paints; hdc_1 = BeginPaint(hwnd,&paints); TextOut(hdc_1,0,0,"我是长城好哇",strlen("我是长城好哇")); break; case WM_CLOSE: if(IDYES==MessageBox(hwnd,"哇哈哈,你丫的真的打算关掉吗?","卖萌之家",MB_YESNO)) { DestroyWindow(hwnd); } break; case WM_DESTROY: PostQuitMessage(0); break; default: return DefWindowProc(hwnd,uMsg,wParam, lParam); } return 0; }
效果图:
相关文章推荐
- MFC复习和学习 第一章 MFC基础窗口构建 MFC应用程序启动机制 MFC
- Windows 窗口绘图基础 MFC
- 【学习笔记】零基础C#窗口程序开发入门
- [每日一学]MFC学习笔记——线程中控制窗口内容
- MFC基础,MFC自绘控件学习总结.-- 转
- MFC学习笔记——多窗口之间的通信 .
- VC++学习日志 7-23 MFC基础
- MFC学习第三节:在窗口内点击左键画圆,添加菜单使圆增大。
- 学习笔记之MFC修改默认窗口大小
- MFC学习--对话框及窗口背景色 .
- MFC学习第一节:建立窗口
- DX学习前篇 (Win32窗口基础)(第一章)
- MFC学习笔记之六————更改appwizard生成的窗口外观
- MFC学习笔记之六————更改appwizard生成的窗口外观
- MFC学习--对话框及窗口背景色
- [MFC学习之C++基础] 孙鑫视频中第三讲中提到的小测试程序(关于基类和子类的继承关系)
- MFC学习笔记之三————区分窗口类对象以及窗口&&四种获得DC方式绘图
- MFC学习之路(六)在DoModal()之前态设置对话框窗口标题
- 【学习笔记】零基础C#窗口程序开发入门
- MFC学习第二节:在窗口中输出0-100的十行十列数字