Visual C MFC 1 HDC h DC PAINTSTRUCT
- Slides: 125
Visual C++ MFC 编程基础. 1
文本输出例 HDC h. DC; // 输出设备句柄 PAINTSTRUCT ps; // 重画信息 结构 switch( msg ) { …… case WM_PAINT: // 重画消息入口 h. DC = Begin. Paint(hwnd, &ps); // 获得 设备 Text. Out(h. DC, 10, “Hello”, 5); // 文本 输出 End. Paint(h. Wnd, &ps); // 释放 37
图形输出例 int x = LOWORD( l. Param ); // 获得鼠标位置 int y = HIWORD( l. Param ); HDC h. DC = Get. DC( h. Wnd ); // 获取设备 句柄 switch( msg ) { …… case WM_LBUTTONDOWN: // 鼠标按下 Move. To(h. DC, x, y); break; // 设 置当前点 case WM_LBUTTONUP: // 鼠标释放 Line. To(h. DC, x, y); break; // 画 39 线至指定点
常用容器类(1/2) F 数组类: – 如:CWord. Array、CPtr. Array、COb. Array. . . CWord. Array ax; for( int i=0; i < ax. Get. Count(); i++ ) WORD w = ax[ i ]; F 链表集合类: – 如:COb. List、CPtr. List、CString. List. . . CString. List sx; POSITION pos = sx. Get. Head. Position( ); while( pos ) { CString s = sx. Get. Next( pos ); . . . } 52
常用容器类(2/2) F 映射集合类: – 如:CMap. Word. To. Ptr、CMap. String. To. Ob. . . CMap. Word. To. Ptr wpx; POSITION pos = wpx. Get. Start. Position( ); while( pos ) { WORD w; void *p; wpx. Get. Next( w, p, pos ); . . . } 53
最简单的 MFC 应用程序 #include <afxwin. . h> class CHello. App // 应用程序派生类 : public CWin. App { public: virtual BOOL Init. Instance( ); // 实例初始化 }; class CHello. Wnd // 主窗口派生类 : public CFrame. Wnd { public: CHello. Wnd( ) ; // 构造主窗口 }; 56
最简单的 MFC 应用程序(续) CHello. App; // 应用程序 BOOL CHello. App: : Init. Instance() { m_p. Main. Wnd = new CHello. Wnd( ); // 主窗口 m_p. Main. Wnd->Show. Window( m_n. Cmd. Show ); m_p. Main. Wnd->Update. Window( ); // 显示 return TRUE; } CHello. Wnd: : CHello. Wnd( ) { Create( NULL, “Hello World!” ); } // 创建主窗口结构 57
66
CClient. DC 的应用 void CMain. Wnd: : On. LButton. Down( UINT flg, CPoint pt ) CClient. DC dc( this ); { // 建立设备描述对象 CRect rct; Get. Client. Rect( rct ); // 取得窗口矩 形 dc. Ellipse( rct ); // 画椭圆 CFrame. Wnd: : On. LButton. Down( cfg, pt ); } 68
CPaint. DC 的应用 void CMain. Wnd: : On. Paint(UINT flg, CPoint pt ) { // 处理 WM_PAINT 消息 CClient. DC dc( this ); CRect rct; Get. Client. Rect( rct ); dc. Ellipse( rct ); CFrame. Wnd: : On. LButton. Down( cfg, pt ); } // 当窗口重新显示时, 自动产生此消息 69
鼠标消息处理 CWnd 的鼠标消息响应函数 afx_msg void On. LButton. Down( UINT flg, CPoint pt ); afx_msg void On. Mouse. Move( UINT flg, CPoint pt ); …… – flg 虚拟键标志;pt 鼠标的屏幕坐标 F 鼠标的消息入口 ON_WM_LBUTTONDOWN( ) ON_WM_MOUSEMOVE( ) 71 F
应用例:鼠标画线 F On. LButton. Down( UINT flg, CPoint pt ) p. Drag = new CClient. DC( this ); // 构造用户区设备对象 p. Drag->Move. To( pt. x, pt. y ); // 设输出位置(设备属性) F On. Mouse. Move( UINT flg, CPoint pt ) p. Drag->Line. To( pt. x, pt. y ); // 画线到点 pt、并改变输出位置 F On. LButton. Up( UINT flg, CPoint pt ) delete p. Drag; // 释放设备对象 72
应用例:光标状态的切换 F 系统光标的获得 h. Cursor = : : Afx. Get. App( )->Load. Standard. Cursor( IDC_WAIT ); // Afx. Get. App( ) 获得 CMy. App 指针 F On. Key. Down( UINT ch, UINT rep, UINT flg ) h. Cursor = : : Set. Cursor( h. Cursor ); // 改变光标,并保存原光标 F On. Key. Up( UINT ch, UINT rep, UINT flg ) h. Cursor = : : Set. Cursor( h. Cursor ); // 恢复光标,并保存原光标 75
图形输出函数 F 当前输出位置 – Move. To / Get. Current. Position F 图形输出函数 – 线输出: Line. To, Poly. Line, Arc – 线输出并添色: Rectangle, Ellipse, Round. Rect, Chord, Pie, Polygon 85
应用例:位图输出 void CMy. DC: : Draw. Bitmap( CBitmap *bmp, CPoint pt ) { CDC mem. DC; mem. DC. Create. Compatible. DC( this ); // 内存设备 mem. DC. Select. Object( bmp ); // 选入 mem. DC. Set. Map. Mode( Get. Map. Mode( ) ); BITMAP bm; // 获取尺寸 bmp->Get. Object( sizeof(BITMAP), (LPSTR)&bm ); CPoint org( 0, 0 ), sz( bm. Width, bm. Height ); mem. DC. DPto. LP( &org ); DPto. LP( &sz ); 91 Bit. Blt( pt. x, pt. y, sz. x, sz. y, &mem. DC, org. x, org. y,
5. 1 资源编辑 资源种类 对话框模板 菜单模板 图标 光标 位图 加速键表 字符串表 具条模板 DIALOG MENU ICON CURSOR BITMAP ACCELERATORS STRINGTABLE TOOLBAR 98
对话框的资源描述. RC IDD_MYDIALOG DISCARDABLE 0, 0, 230, 104 STYLE DS_MODALFRAME|WS_POPUP|WS_CAPTION|WS_SYS MENU CAPTION “My Dialog” FONT 10, “System” BEGIN DEFPUSHBUTTON “OK”, IDOK, 173, 7, 50, 14 PUSHBUTTON “Cancel”, IDCANCEL, 173, 24, 50, 14 CTEXT “This is a dialog”, IDC_STATIC, 130, 56, 87, 17 CONTROL 103, IDC_STATIC, ”Static”, SS_BITMAP, 7, 7, 120, 90 END 102
数据传输的实现 void CComputer. Dlg: : Do. Data. Exchange( CData. Exchange *p. DX ) { CDialog: : Do. Data. Exchange( p. DX ); DDX_Text( p. DX, IDC_CPUEDIT, m_CPU ); // CPU 编辑框 《=》 成员变量 DDV_Max. Chars( p. DX, m_CPU, 30 ); // 字符串长度限制 DDX_Text( p. DX, IDC_FREQEDIT, m_Freq. Edit ); // 主频编辑框 《=》 成员变量 DDV_Min. Max. UInt( p. DX, m_Main. Freq, 2, 450 ); // 无符号整数的上下限 。。。 } 112
数据传输的控制 (Dialog类) Do. Modal On. OK 程序中直接调用 On. Init. Dialog 自动调用 Update. Data Do. Data. Exchage 113
主窗口的实现 F 消息映射 ON_WM_CREATE( ) // 创建消息 ON_COMMAND( ID_FILEEXIT, On. File. Exit ); // 菜单 项 ON_COMMAND( ID_FILEINFO, On. File. Info ); F 菜单响应函数 void CMain. Wnd: : On. File. Info( ) { – CComputer. Dlg dlg; – dlg. Do. Model( ); – CClient. DC dc( this ); – Show. Message( &dc ); } // 启动对话框 // 显示数据 114
生成的程序框架 F CDemo. App the. App; – 继承 CWin. App, 提供消息循环和程序入口 F CMain. Frame – 继承 CMDIFrame. Wnd, 提供多文档主窗口 F CChild. Frame – 继承 CMDIChild. Wnd, 提供多文档子窗口 F CDemo. Document – 继承 CDocument 文档类 F CDemo. View – 继承 CView 视窗类 119
CDemo. App: : Init. Instance CMulti. Doc. Template* p. Doc. Template; p. Doc. Template = new CMulti. Doc. Template( 文档模板 IDR_AX 3 TYPE, 模板描 述 RUNTIME_CLASS(CAX 3 Doc), 文档类 RUNTIME_CLASS(CChild. Frame), 窗口类 RUNTIME_CLASS(CAX 3 View)); 视窗类 Add. Doc. Template(p. Doc. Template); 登记 CMain. Frame* p. Main. Frame = new CMain. Frame; 主窗口 if (!p. Main. Frame->Load. Frame(IDR_MAINFRAME)) 120
- Mfc hdc
- Paintstruct
- Zanele mathe
- Rich froehlich hdc
- Hdcservice
- Mfc
- Hora santa por las familias mfc
- Guia del matrimonio promotor mfc primer nivel
- Windows foundation classes
- Taller de metodologia mfc
- Mfc critical section
- Mfc internals
- Mfc app
- Sacerdote asistente del mfc en méxico 2020
- Mfc internals
- Mfc feature pack
- Mfc cmas
- C++ mfc 예제
- Mfc vs wpf
- Decalogo del dialogo en equipo mfc
- 6 exigencias basicas del mfc
- Brother 5750dw driver
- Oracion del matrimonio promotor mfc
- Exigencias basicas del mfc
- Jelaskan definisi pemrograman visual
- Rima visual
- Visual pathways
- Aplikasi audio visual
- Visual studio 2017 android emulator
- A sensorimotor account of vision and visual consciousness
- Whats visual imagery
- Cpt = cpt + 1
- Opc systems
- Rvr aviation term
- Compaq visual fortran
- Visual basic express
- Allegory examples
- Visual studio code
- Hemodynamics
- Visual apparatus
- Visual analyser
- Epanadiplosis retorica visual
- Visual search
- Grade 8 creative arts atp
- Retrica significado
- Visual segment surface
- Circle time visual schedule
- Para visual display
- Sadq h10
- An example of auditory imagery
- Visual methods in qualitative research
- Visual cliff experiment
- Integer en visual basic
- How to disassemble an engine step by step
- Rubrica de organizador visual
- Managing risk with the ipde process
- Kinesthetic learner
- Visual basic 3 letter prefixes
- Visual spatial relations
- Visual chart 6
- Visual geometry group
- Visual basic for aplication
- Excel 2007 vba
- Visual basic debugging tools
- Visual descent point
- Seni multimedia
- Visual studio 2005 team
- Penyajian visual dengan benda-benda dua dan tiga dimensi
- Visual basic control structures
- What is visual pollution definition
- Purdue writing lab
- Visual differential geometry
- Visual fox pro
- Emerging media definition
- Estructura de control java
- Gaya pembelajaran model kolb
- Visual search
- What is visual structure
- Cultura visual
- Visual spatial intelligence famous person
- Visual webgui
- Visual understanding environment
- What does harmonious mean
- Agnosia
- Comunicação visual
- Treisman's feature integration theory
- "defense advanced gps receiver"
- Oskar fischinger
- Vcaa visual communication design
- Art vocabulary elements and principles
- Karya harmoni
- Principles of visual aids
- Ritmo
- Upside-down brilliance: the visual-spatial learner
- Robert herrick visual house
- Visual studio 2005 professional
- Visual merchandising synonym
- Visual studio 2017 download
- Signo qu
- Visual profox
- Types of verbal support
- Mensagem visual
- Starburst graphic organizer
- Store layout, design and visual merchandising ppt
- Object oriented programming visual basic
- Describe the three step writing process
- Visual information fidelity
- Introduction to visual basic.net
- Xiaojun languages
- Victorian curriculum art
- Assonanc
- Metaphor in a thousand splendid suns
- Algorithms for visual design
- Visual input
- Electronegativity visual representation
- Consciousness outside the brain
- There is no word for goodbye imagery
- Textura visual mecanica
- Mnozenje matrica
- Visual aid benefits
- Bottom down processing
- Teaching with visual symbols
- Eclipse visual editor
- Download prolog
- Fotorreceptores
- Visual plumes