MFC1

/////////////////////////////////////////////1

WINDOWS 也可以接受命令行参数 , project/ setting /debug /program arguments:

F10单步

类是一个抽象的, 不占内存。 只有对象才是实在的。

//////////////////////////////////////////////////////////2

父类先构造,然后子类。  子类先析构,然后父类。

写了带参,无参的就不提供了。

子类向基类传递带参构造,fish():Animal(400,300),a(1){  }   //a(1)是对常量初始化

函数覆盖   父子类之间。 

函数重载  一个类当中

能不能转换,看内存模型。比如 整形4B –> char型 1B 会丢失精度。反之可以。

多态  编译器看到virtual 延迟绑定,运行时才根据传入指针类型决定调用哪个

基类相应函数加 virtual 子类有的用子类,子类没有的调用父类。

纯虚函数  virtual void b() = 0;带纯虚的类,抽象类。不能实例化对象的。除非把纯虚实现。

让派生类继承时给定义 。

指针和引用 。 指针是要空间的存储地址空间。引用本身不需要占内存,是起别名。

引用传参避免值拷贝 ,因为是同一内存。   比指针概念清楚。

改名: F2

///////////////////////////////3MFC

MFC 源代码 C:\Program Files\Microsoft Visual Studio\VC98\MFC\SRC

F5 调试运行

WinMain  : APPMODUL.CPP

全局对象 CTestApp theApp;  构造函数 CTestApp::CTestApp() ;main入口_tWinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance,
    LPTSTR lpCmdLine, int nCmdShow)

对于一个全局变量,加载时就已经分配了内存空间,赋了初值。

CWinApp:APPCORE.CPP

InitInstance 虚函数 ,

继承性原理, this 指向派生类对象,

多态性, 调用子类的方法。

AfxWinMain  afx应用程序框架模型,在 WINMAIN.CPP之中,

//刚才看到了一个有趣的,如何阻止笛膜沾水蒸汽,可以涂点腊,也有用大宝的。。。。

//百度的提问,需要付出金币,然后为了提问,必须先回答别人,这是个好机制好策略啊。

设计注册创建更新。消息循环。

AfxEndDeferRegisterClass 注册窗口类  在WINCORE.CPP

AfxRegisterClass     注册 RegisterClass

子类中有PreCreateWindow  在WINFRM.CPP  调用基类的。。。  这时才注册 。 。 。。 

AfxDeferRegisterClass 是一个宏AFXIMPL,调用AfxEndDeferRegisterClass  

CreateEx   WinFrm.cpp 中调用 。

PreCreateWindow    CREATESTRUCT 为了可以修改窗体属性

1:14:11

int CWinThread::Run() 在     THRDCORE.CPP

BOOL CWinThread::PumpMessage()

俩冒号 :: 表示是全局的函数。  前面有类名,类成员函数。

如果平台SDK函数和自己类中重复,需要此标记。 否则不用也可。

窗口销毁不等于 对象销毁。

createWindow有窗口类型。cRect

ShowWindow(SW_SHOWNORMAL)  WS_VISIBLE

GetParent() 取得父窗口指针CMainFrame, this:  CTestView

///////////////////////////////////////////////////////////////////////////////////////////////////////4 draw

消息类/框架类中 消息捕获

头文件  DECLARE_MESSAGE_MAP()之前。

//{{AFX_MSG(CDrawView)
afx_msg void OnLButtonDown(UINT nFlags, CPoint point);
//}}AFX_MSG

源文件 BEGIN_MESSAGE_MAP(CDrawView, CView) 之后

//{{AFX_MSG_MAP(CDrawView)
ON_WM_LBUTTONDOWN()
//}}AFX_MSG_MAP
消息循环 ,可以用虚函数,也可以消息映射。MFC采用消息映射。对照表。‘

DefWindowProc  在  WINCORE.CPP 。 对消息进行处理。

虚函数,真正的消息处理OnWndMsg , 判断消息各类,查找消息映射,(头文件、源文件

HDC hdc;
hdc = ::GetDC(m_hWnd);

CDC类

CClientDC::CClientDC  

explicit CClientDC( CWnd* pWnd );    可以访问 除工具 栏的非客户区。

CWindowDC::CWindowDC  构造和析构自动的。可以访问整个屏幕区,包括客户和非客户区。

CPen( );

CPen( int nPenStyle, int nWidth, COLORREF crColor );

CPen( int nPenStyle, int nWidth, const LOGBRUSH* pLogBrush, int nStyleCount = 0, const DWORD* lpStyle = NULL );

//位图的画刷

CBrush

CBitmapButton::LoadBitmaps

CBrush *pBrush = CBrush::FromHandle((HBRUSH)(GetStockObject(NULL_BRUSH)));

类的成员函数。 静态的属于类本身。非静态,属于某个对象。非静态可引用静态。 从内存分配考虑。

dc.SetROP2(R2_BLACK);

///////////////////////////////////////////////////////////////////////////////////5  求知的精神,我怎么没有哇

CWnd::CreateSolidCaret    创建插入符

The CreateSolidCaret member function automatically destroys the previous caret shape, if any, regardless of which window owns the caret. Once created, the caret is initially hidden. To show the caret, the ShowCaret member function must be called.

获取文本信息 BOOL GetTextMetrics( LPTEXTMETRIC lpMetrics ) const;

TEXTMETRIC 

创建图形插入符 void CreateCaret(  CBitmap* pBitmap  );  ///////interesting

OnDraw里面可以不停重绘。

CString 

 CString::LoadString

路进程  CDC::BeginPath

CDC::GetTextExtent  获取字符串屏幕上的宽度高度   区别GetTextMetric 字体柄身。。

CSize GetTextExtent(  LPCTSTR lpszString,  int nCount  ) const;  CSize GetTextExtent(  const CString& str  )

BOOL SelectClipPath(  int nMode  ); 剪切区, RGN_DIFF当前路径被 排除 , pDC->SelectClipPath( RGN_DIFF   );

移动一个插入符。SetCaretPos

ACSII

删除

取得背景色 COLORREF GetBkColor( HDC hdc );

设置背景色 COLORREF SetTextColor( _In_  HDC hdc, _In_  COLORREF crColor );

减少字符

光标连动。 SetCaretPos(pt);

创建字体 CFont::CFont

BOOL CreatePointFont( int nPointSize, LPCTSTR lpszFaceName, CDC* pDC = NULL );


CDC::DrawText

virtual int DrawText( LPCTSTR lpszString, int nCount, LPRECT lpRect, UINT nFormat ); int DrawText( const CString& str, LPRECT lpRect, UINT nFormat );

定时器 SetTimer

CWnd:: SetTimer

/////////////////////////////////////////////////////6 菜单

标准消息 除WM_COMMAND之外,所有WM开头 ,从CWnd派生的类都可以接收到这类消息 , 即可以收标准也可接收命令。

命令消息 菜单按钮添加的消息。 WM_COMMAND呈现。

通告消息 单击,选择等。向父窗口。通常WM_COMMAND呈现。从CCmdTarget派生的类均可接收此类消息。

////刚才听了下锋做的东西,水平真高啊。

消息路由 AfxWndProc –> AfxCallWndProc->WindowProc (是Cwnd成员函数)->OnWndMsg (判断是什么类型消息 ) –>( OnCommand or OnNotify ) –>OnCmdMsg .

查找 Frame <–> View <–> Doc

-> app

ID_FILE_OPEN, MF_BYCOMMAND 

标记菜单

CMenu* GetMenu( ) const;

DWORD CheckMenuItem( HMENU hmenu, UINT uIDCheckItem, UINT uCheck );

图形标记菜单  

BOOL SetMenuItemBitmaps( UINT nPosition, UINT nFlags, const CBitmap* pBmpUnchecked, const CBitmap* pBmpChecked );

标记的大小  int GetSystemMetrics( int nIndex); 

使残废 UINT EnableMenuItem( UINT nIDEnableItem, UINT nEnable );

使所有菜单项可用(但不是图标。需要用到这个变量     m_bAutoMenuEnable = FALSE ;在构造函数里初始化。

菜单取消。 SetMenu  BOOL SetMenu( CMenu* pMenu );

命令更新  N_UPDATE_COMMAND_UI     

ON_UPDATE_COMMAND_UI

CCmdUI     “全部清除”菜单项的更新 void CMyClass::OnUpdateToolsMyTool( CCmdUI* pCmdUI ) { if( ToolAvailable() ) pCmdUI->Enable( TRUE ); }

只能用于菜单项,不能用于顶级菜单。

图标和菜单项的对应,使用索引时,工具栏图标 计数位置和菜单计数不同。使用ID号毋庸考虑。

右键弹出菜单。

编写好的组件控件,Project->add to project – >components and …..

显示弹出菜单 BOOL TrackPopupMenu( UINT nFlags, int x, int y, CWnd* pWnd, LPCRECT lpRect = 0 );

1:35

客户区坐标  屏幕坐标  ClientToScreen(&point);

子窗口优先响应机会 。,GetParent());//VIEW类窗口拥有弹出菜单。只有this才能对弹出响应,框架类指针必须设 为 父指针

以上都是静态菜单。

动态的  CMenu::AppendMenu   BOOL AppendMenu( UINT nFlags, UINT_PTR nIDNewItem = 0, LPCTSTR lpszNewItem = NULL );

创建弹出菜单  和 cmenu对象相关联。 所有资源类都有一个句柄,

插入 

动态增加的项  如何命令响应。 资源ID


//命令响应函数添加三个步骤
  1. 头文件  消息原型(DECLARE_MESSAGE_MAP()之前)。 2. 消息映射  ONCOMMAND宏(不加标点)。BEGIN_MESSAGE_MAP() END_MESSAGE_MAP()。 3.函数 实现

菜单栏重绘 BOOL WINAPI DrawMenuBar( _In_  HWND hWnd );

使窗口重绘  CWnd::Invalidate 使整个窗口区无效, 窗口背景擦除

CStringArray

LRESULT OnCommand( [in]  WPARAM wParam, [in]  LPARAM lParam );

The low-order word specifies the identifier of the menu item, control, or accelerator.

取低字节的宏  WORD LOWORD( DWORD dwValue );

源文件单独 参与编译,头文件不参与。#include "Menu2Doc.h" 从源文件移到头文件。

//////////////////////////////////////////////////////////////////////////////////////////////////7 CDialog  

 

C 在MFC是类的标识。

模态对话框 ,创建一个对话框类,CTestDialog dlg; DoModal()  返回值作为EndDialog的参数,来关闭对话框  兼有显示对话框的功能。

非模态  ,  CDialog::Create  , 另外需要显示对话框。 dlg.ShowWindow()

if ( ! m_btn.m_hWnd)

获取窗口文本,GetWindowText(CString&)

CWnd::GetDlgItem  

a to i 函数,  i to a 函数

GetDlgItemText 函数, 、

DoDataExchange   Never call this function directly. It is called by the UpdateData member function. Call UpdateData to initialize a dialog box's controls or retrieve data from a dialog box.

控件变量  成员函数 GetWindowText获取窗口文本。

WM_GETTEXT    SendMessage(WM_SETTEXT,0,(LPARAM)ch3);

SetFocus设置焦点 

    SendDlgItemMessage(IDC_EDIT3,EM_SETSEL,0,-1);
    m_edit3.SetFocus();

孙老师讲茴字有七种写法。

SDK编程

CRect:: 判断矩形区是否构矩形 IsRectEmpty().  四个坐标是否为0  IsRectNull

GetWindowRect获得窗口矩形区域

SetWindowPos

2:05

改变窗口过程 SetWindowLong 窗口过程类型 WNDPROC

OnInitDialog 中。

  函数名,可表代码首地址。

GetNextWindow function 

CWindow::GetWindow

GetFocus()->GetNextWindow()->SetFocus();

    GetFocus()->GetWindow(GW_HWNDNEXT)->SetFocus();

CWnd::GetNextDlgTabItem

GetNextDlgTabItem(GetFocus())->SetFocus(); 查找方式不一样的。Tab Order

////////////////////////////////////////////////////////8 dialog  continue

获取控件指针      CDD* m_pBtn;

ShowWindow(SW_HIDE);
m_pBtn->ShowWindow(SW_SHOW);

属性表单 property sheet,

Prop.clw  

                                                                                                                                                                                              

           CPropertyPage    As with standard dialog boxes, you derive a class from CPropertyPage for each page in your property sheet. To use CPropertyPage-derived objects, first create a CPropertySheet object, and then create an object for each page that goes in the property sheet. Call CPropertySheet::AddPage for each page in the sheet, and then display the property sheet by calling CPropertySheet::DoModal for a modal property sheet, or CPropertySheet::Create for a modeless property sheet.

属性页创建,实例化对象 ,属性表单构造add增加页。显示。

向导SetWizarMode

CPropertyPage::OnSetActive

((CPropertySheet*)GetParent())->SetWizardButtons(PSWIZB_BACK|PSWIZB_NEXT);

OnWizardNext 

UpdateData  true 取回值  false赋于控件

CListBox::AddString    

the difference between  |    and  || ?

OnInitDialog

    ((CComboBox*)GetDlgItem(IDC_COMBO1))->SetCurSel(0);//索引

CPropertySheet::DoModal     

Return Value


IDOK or IDCANCEL if the function was successful; otherwise 0 or -1. If the property sheet has been established as a wizard (see SetWizardMode), DoModal returns either ID_WIZFINISH or IDCANCEL.

快速的数组初始化,memset        memset(m_Like,0,sizeof(m_Like));

    pDC->TextOut(0,3*tm.tmHeight,strTemp);

CFont font ;
font.CreatePointFont(300,"华文行楷");
CFont *poldFont;
poldFont = pDC->SelectObject(&font);

pDC->SelectObject(poldFont);

原文地址:https://www.cnblogs.com/iamgoodman/p/3000519.html