zoukankan      html  css  js  c++  java
  • MFC–2

    4.11//////// 9 修改应用程序的外观                                                                                            

    修改CreateStruct 结构体

    BOOL CMainFrame::PreCreateWindow(CREATESTRUCT& cs)

    // TODO: Modify the Window class or styles here by modifying
    //  the CREATESTRUCT cs

    //    cs.style&=~FWS_ADDTOTITLE;

    //    cs.style=WS_OVERLAPPEDWINDOW;
        cs.style=cs.style&~FWS_ADDTOTITLE;  

    Microsoft TechNet

    创建之后改变外观 OnCreate      

    SetWindowLong(m_hWnd,GWL_STYLE,WS_OVERLAPPEDWINDOW);

    SetWindowLong(m_hWnd,GWL_STYLE,GetWindowLong(m_hWnd,GWL_STYLE) & ~WS_MAXIMIZEBOX);

    图标光标背景  设计窗口类时,

    获取当前应用程序的句柄 AfxGetInstanceHandle( );

        wndcls.lpszClassName = "liujiahao";       cs.lpszClass = "liujiahao";     any connections between these two?

    28:12

    AfxRegisterWndClass   Allows you to register your own window classes.

    LPCTSTR AFXAPI AfxRegisterWndClass( UINT nClassStyle, HCURSOR hCursor = 0, HBRUSH hbrBackground = 0, HICON hIcon = 0 );  

        cs.lpszClass = AfxRegisterWndClass(CS_HREDRAW | CS_VREDRAW,0,0,LoadIcon(NULL,IDI_WARNING));//不需要重新设计一个窗口类了。

    SetClassLong  

    QQ截图20130411084606

    SetClassLong(m_hWnd,GCL_HICON,(LONG)LoadIcon(NULL,IDI_ERROR));

        //修改背景 光标 在VIEW类 OnCreate

    SetClassLong(m_hWnd,GCL_HBRBACKGROUND,(long)GetStockObject(BLACK_BRUSH));
    SetClassLong(m_hWnd,GCL_HCURSOR,(LONG)LoadCursor(NULL,IDC_HELP));

    动画的图标效果 定时器 和 SetClassLong 可在窗口创建之后改变图标

    MAKEINTRESOURCE

    CWinApp data Members :  m_hInstance 表示程序当前实例。

    AfxGetInstanceHandle(),

    调用在另个源文件中定义的全局变量,extern 声明,

    全局函数AfxGetApp这个函式所传回的指标可以用於存取应用程式的资讯

    CToolBar                                             

    Create a toolbar resource.

    1. Construct the CToolBar object.
    2. Call the Create (or CreateEx) function to create the Windows toolbar and attach it to the CToolBar object.
    3. Call LoadToolBar to load the toolbar resource.

    Otherwise, follow these steps:

    1. Construct the CToolBar object.
    2. Call the Create (or CreateEx) function to create the Windows CE toolbar and attach it to the CToolBar object.
    3. Call LoadBitmap to load the bitmap that contains the toolbar button images.
    4. Call SetButtons to set the button style and associate each button with an image in the bitmap.

      EnableDocking      让工具栏可以停靠,通过Style 设定。BOOL EnableDocking( DWORD dwDockStyle );

    CMDIChildWndEx::EnableDocking  

    m_wndToolBar.EnableDocking(CBRS_ALIGN_ANY); //工具栏本身可以  停靠
    EnableDocking(CBRS_ALIGN_ANY);//CFrameWnd::EnableDocking 让框架窗口可以被 停靠

        DockControlBar(&m_wndToolBar);

    CFrameWnd::RecalcLayout();  Called by the framework when the standard control bars are toggled on or off or when the frame window is resized.

    CFrameWnd::ShowControlBar   很方便。比上面那东西    ShowControlBar(&m_newToolBar,!m_newToolBar.IsWindowVisible(),false); 

    CMainFrame::OnUpdateViewNewtool(CCmdUI* pCmdUI) //附选标记

    状态栏                                                    

    static UINT indicators[] =
    {
        ID_SEPARATOR,           // status line indicator
        ID_INDICATOR_CAPS,
        ID_INDICATOR_NUM,
        ID_INDICATOR_SCRL,
    };

              sizeof(indicators)/sizeof(UINT)))  //数组元素数目

    显示系统时间  CTime::GetCurrentTime

    CStatusBar::SetPaneText    类的成员函数要用对象调用。

    窗格宽度

    CMFCStatusBar::SetPaneInfo

    void SetPaneInfo( int nIndex, UINT nID, UINT nStyle, int cxWidth );

        m_wndStatusBar.SetPaneInfo(1,IDS_TIMER,SBPS_NORMAL,sz.cx);

    创建进度栏                                        

      CProgressCtrl::Create

    virtual BOOL Create( DWORD dwStyle, const RECT& rect, CWnd* pParentWnd, UINT nID );

        m_progress.Create(WS_CHILD | WS_VISIBLE| PBS_VERTICAL , CRect(100,100,120,200),this,661 );
    m_progress.SetPos(50);

    如何避免和系统消息冲突  WM_USER 宏

    SendMessage(UM_PROGRESS);   PostMessage(UM_PROGRESS);

    尺寸不会变(不会动):

    利用重绘时 OnPaint 设置矩形区域 rect 放进度栏在 矩形区 . 取消消息发送?

    CFrameWnd::SetMessageText 直接在状态栏上放置文本

    状态条上显示坐标:

    持久的窗口对象 临时窗口对象

    启动画面

    工程 /增加到工程 /组件控件 /VC++  /Splash screen 这个我没有。

    4.12//////////////////////10 图像绘制 设置 颜色 字体 位 图                                                                                  

    inner peace

    CDC::SetPixel    

    CPen pen(PS_SOLID,1,RGB(255,0,0));
    dc.SelectObject(&pen);
    CBrush *pBrush = CBrush::FromHandle((HBRUSH)GetStockObject(NULL_BRUSH)); 透明的填充
    dc.SelectObject(pBrush);

        dlg.DoModal();

    view类的对象, 会一直在。 对话框对象,却是随着关闭

    线型定义

    /* Pen Styles */
    #define PS_SOLID            0
    #define PS_DASH             1       /* -------  */
    #define PS_DOT              2       /* .......  */
    #define PS_DASHDOT          3       /* _._._._  */
    #define PS_DASHDOTDOT       4       /* _.._.._  */

    创建颜色对话框              

    CColorDialog Members

    ChooseColor 

    typedef struct tagCHOOSECOLOR

    { DWORD lStructSize; HWND hwndOwner; HINSTANCE hInstance; COLORREF rgbResult; COLORREF *lpCustColors; DWORD Flags; LPARAM lCustData; LPCCHOOKPROC lpfnHook; LPCTSTR lpTemplateName;

    } CHOOSECOLOR, *LPCHOOSECOLOR;

    如果要设置颜色 初始的位置 , ::m_cc 设置标记

    CTRL + TAB 窗口间的切换

        dlg.m_cc.Flags |= CC_RGBINIT |CC_FULLOPEN;//或操作缺省标记

    CFontDialog 字体对话框

    CFontDialog::CFontDialog

    m_cf

     
    释放先前的字体资源 CGdiObject::DeleteObject
    view类对象 与 view类窗口关系 , view类对象  有个数据成员保存了窗口句柄 。  一个类对象 和windows资源, 通过数据成员来连系。可以切断。

    if(m_font.m_hObject) 
        m_font.DeleteObject();

    CGdiObject 对象是个类的对象  GdiObject 是种资源对象
     
     
    GetDlgItem(IDC_SAMPLE)获取主框 窗口指针  , GetDlgItem(IDC_SAMPLE)->GetWindowRect(&rect);调用矩形区域大小 , 直接调用则变成对话框的矩形区大小 了。
     
    当控件和成员变量关联时, 要想及时变化 。

    UpdateData();

    过程之中进行数据交换。
     

    CWnd::OnCtlColor

    当将绘制时,框架调用该成员函数的子控件。

    afx_msg HBRUSH OnCtlColor(
       CDC* pDC,
       CWnd* pWnd,
       UINT nCtlColor 
    );

    参数


    pDC 包含指针到子窗口中显示上下文。 是瞬态的。
    pWnd包含指向该控件将请求颜色。 是瞬态的。
    nCtlColor包含下列值之一,指定控件的类型:
    • CTLCOLOR_BTN 按钮控件

    • CTLCOLOR_DLG 对话框

    • CTLCOLOR_EDIT 编辑控件

    • CTLCOLOR_LISTBOX 列表框控件

    • CTLCOLOR_MSGBOX 消息框

    • CTLCOLOR_SCROLLBAR 滚动条控件

    • CTLCOLOR_STATIC 静态控件


    •                     


    HBRUSH CSettingDlg::OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor)

    warning C4715: 'CSettingDlg::OnCtlColor' : not all control paths return a value

    文字背景色 设置透明的。  SetBkMode     OPAQUE /TRANSPARENT

    CButton::DrawItem

    An owner-drawn button has the BS_OWNERDRAW style set. Override this member function to implement drawing for an owner-drawn CButton object. The application should restore all graphics device interface (GDI) objects selected for the display context supplied in lpDrawItemStruct before the member function terminates.   

    简而言之,自绘制控件, 要改变它背景色和文字, 要编写派生类, 从CBUTTON而来。 进行按钮绘制。

    // Draw the button text using the text color red.

    COLORREF crOldColor = ::SetTextColor(lpDrawItemStruct->hDC, RGB(255,0,0)); //返回先前的颜色,

    ::DrawText(lpDrawItemStruct->hDC, strText, strText.GetLength(), &lpDrawItemStruct->rcItem, DT_SINGLELINE|DT_VCENTER|DT_CENTER);

    ::SetTextColor(lpDrawItemStruct->hDC, crOldColor);

    先建个BUTTON类, 将对话框按钮上的 按钮 控件 和 这个类的对象 关联起来。

    OK按钮文字颜色  BS_OWNERDRAW

    背景色

    贺西格的马头琴, 好可爱啊。

    拿来主义。

    在窗口中贴图

    1. 创建位图。

    CBitmap bitmap; bitmap.LoadBitmap(IDB_BITMAP1);

    2.  创建兼容DC  。

    CDC dcCompatible; dcCompatible.CreateCompatibleDC(pDC);

    3.  位图选到兼容DC。

    dcCompatible.Sel;ectObject(&bitmap);

    4.  兼容DC中的位图贴到当前DC中。

    pDC->BitBlt(rect.left, rect.top,rect.width(),rect.height(),&dcCompatible,0,0,SRCCOPY);

    CBitmap bitmap;
    bitmap.LoadBitmap(IDB_BITMAP1); //1

    CDC dcCompatible;
    dcCompatible.CreateCompatibleDC(pDC);//2

    dcCompatible.SelectObject(&bitmap);//3

    CRect rect;
    GetClientRect(&rect);
    pDC->BitBlt(0,0,rect.Width(),rect.Height(),&dcCompatible,0,0,SRCCOPY);//4    bitBlt 按1:1的比例,故无法拉伸

        pDC->StretchBlt(0,0,rect.Width(),rect.Height(),&dcCompatible,0,0,bmp.bmWidth,bmp.bmHeight,SRCCOPY);

    将代码放在OnDraw里会有些闪动。 因为擦除重绘。

    作业 CDialogBar 类(不是对话框的类,非模态对话框,和对话框类非常相似) :创建, 上面放一些标准控件, DialogBar本身的背景色,编辑框背景色文字色, 列表框背景显示一图片。

       ///////////////4.13///////////////////////////////////////////////////////////////图形保存和重绘

    Base Class  for CGraphicView , default is CView, other can choose CScrolView,CEditView……now still View,,,,,

    窗口变化 时, 图画被擦除了。。

    用结构体保存不同类型的对象  , 就是类啊。 图形 的 三要素,

    CStrArray

    CPtrArray   

    CObArray

    梨花院落溶溶月 柳絮池塘淡淡风——晏殊      

    1. CptrArray m_ptrArray , CGraph graph(…)  因为是在OnLButton是局部对象,地址是对象所在内存的地址。m_ptrArray.Add(&graph) 实际上保存了对象地址。当对象发生析构内存回收后,不存在了。 虽然保存了对象的地址,但对象已经消失了。

    2. //solution: CPtrArray m_ptrArray; CGraph *pGraph; 因为指针类型的变量也是在OnLbuttonup局部的。pGraph = new Graph(…) ;为指针类型变量分配空间构造个对象,new都是在堆中分配。将对象地址赋给变量,变量保存了CGraph对象在堆中内存的地址  .   m_ptrArray.Add(pGraph);这个变量的值就是内存的地址,这个内存的地址就是new 构造的对象在堆中地址。虽然LButtonUp析构回收了变量pGraph,但仍然可以通过保存的内存地址索引到堆里的地址对象。

      堆中分配的内存,如果不显示delete 则生命周期和应用程序是一致的,

    CGraph *pGraph = new CGraph(m_nDrawType ,m_ptOrigin,point);
    m_ptrArray.Add(pGraph);

    VIEWCORE.CPP   OnPaint();

    // standard paint routine
    CPaintDC dc(this);
    OnPrepareDC(&dc);
    OnDraw(&dc);

          CPaintDC::CPaintDC  是一个设备上下文类派生自CDC类, 通过CWnd:: BeginPaint得到DC句柄 , 通过CWnd::EndPaint析构。这两个方法封装到了构造方法和析构里。

    CPaintDC对象只能用于响应WM_PAINT消息响应中.  BeginPaint, EndPaint不能在其它地方使。

    OnPrepareDC 虚函数, ,OnPrint OnDraw调用之前,都要调用我。用于屏幕显示时,调用蕨类 ,什么也不做。在派生类中被覆盖 用于调整设备上下文的属性。

    OnDraw根据多态, 子类有的用子类。

    有OnPaint

    使窗口有滚动能力。CScrollView

    CScrollView::SetScrollSizes  运用坐标空间和转换来完成 对图形输出进行缩放、旋转、平移、斜切和反射。

    应用程序用世界坐标系,

    Win32把世界坐标系空间和页面空间 为空间。 物理设备空间指的是 应用程序窗口的客户区; 也或指打印机的一页张。

    页面空间/窗口/窗口原点   --转换因子--  设备空间/视口/视口原点

    几乎所有的GDI 函数中使用的坐标都是逻辑单位。Windows必须将逻辑单位转换为设备单位(像素)。 这种转换是映射方式、窗口和视口的原点为以及窗口和视口的范围所控制的。 所有的消息、非GDI函数和一些GDI函数GetDeviceCaps使用设备坐标,以像素为单位。 永远使用设备坐标。

    通常视口和客户区相同。

    CScrollView::SetScrollSizes  窗口创建之后调用,

    OnInitialUpdate() {  //OnDraw之前调用。 第一个调用的函数。

    VIEWSCRL.CPP  中, void CScrollView::OnPrepareDC(CDC* pDC, CPrintInfo* pInfo)

        断点 pDC->SetViewportOrg(ptVpOrg);

    关于图形错位。GDI 函数使用逻辑坐标,图形显示要使用设备坐标,

    刚开始画没有使用OnPrepareDC调整, 只有重绘时才调整, 从而改变视口原点,作图的函数都是逻辑坐标,会自动转设备坐标,SOLUTION ?

    绘制图形后,保存坐标点前。调用 OnPrepareDC函数,调整显示上下文的属性,

    n首先我们在绘制图形之后,在保存坐标点之前,调用OnPrepareDC函数,调整显示上下文的属性,将视口的原点设置为(0,-150),这样的话,窗口的原点,也就是逻辑坐标(0,0)将被映射为设备坐标(0,-150),然后我们调用DPtoLP函数将设备坐标(680,390)转换为逻辑坐标,根据设备坐标转换为逻辑坐标的公式:

    xWindow = xViewport-xViewOrg+xWinOrg,

    yWindow = yViewport-yViewOrg+yWinOrg,得到逻辑点的x坐标为680-0+0=680,y坐标为390-(-150)+0=540,将逻辑坐标(680,540)保存起来,在窗口重绘时,会先调用OnPrepareDC函数,调整显示上下文的属性,将视口的原点设置为了(0,-150),然后GDI函数用逻辑坐标点(680,540)绘制图形,被Windows转换为设备坐标点(680,390),和原先显示图形时的设备点是一样的,当然图形就还在原先的地方显示出来。

    转换  受映射模式  窗口和视口原点影响 ,

    保存图形和重绘图形方式。

    播放;

    CMetaFileDC 从CDC派生而来,

    打开和保存 CopyMetaFile

    要想绘制时看到效果 , 两次调用,当前DC调用一次,兼容DC调用一次。


    /////////////////////////////////////////////////////////////////////4.14//////////////////////////////////////文件操作

    指向常量的指针 和 指针常量

    const char*   pStr = ch; 指向对象是常量 。 *pStr = ‘W’; 不可以修改指向。 pStr= “wnaglgd”。可以修改指向地址。

    char*  const pStr = ch; 必须定义同时初始化。指针值不可改,指向可修改。

    fopen

    fwrite

    size_t  unsigned integer.

    c语言使用缓冲文件系统,缓冲区装满才送磁盘。

    fseek ,  文件指针,     //移动文件指针、

    fread

    多写一个字节,就是多写一个零。 自动作为结束符。

    memset  用指定的字符,设定。

    ftell得到文件指针当前位置

    char *pBuf;  //
    fseek(pFile,0,SEEK_END);
    int len =  ftell(pFile);
    pBuf = new char[len+1];
    //移动了文件指针,再弄回来,fseek
    rewind(pFile);

    fread(pBuf,1,len,pFile);

    文本方式和二进制方式,

    写入文件ofstream    #include <fstream.h>

    读取文件 ifsream

    Win32API函数

    打开文件 CreateFile  功能很强大,

    1:12今天周末啊

    HANDLE WINAPI CreateFile(

    _In_      LPCTSTR lpFileName,

    _In_      DWORD dwDesiredAccess,

    _In_      DWORD dwShareMode,

    _In_opt_  LPSECURITY_ATTRIBUTES lpSecurityAttributes, //确定返回句柄是否能被子进程继承  创建文件访问权限   服务器端软件才有意义,否则NULL缺省安全。

    _In_      DWORD dwCreationDisposition,//如何创建

    _In_      DWORD dwFlagsAndAttributes,

    _In_opt_  HANDLE hTemplateFile );

    typedef struct _SECURITY_ATTRIBUTES {

    DWORD  nLength;

    LPVOID lpSecurityDescriptor;

    BOOL   bInheritHandle;

    } SECURITY_ATTRIBUTES, *PSECURITY_ATTRIBUTES, *LPSECURITY_ATTRIBUTES;

    BOOL WINAPI WriteFile(

    _In_         HANDLE hFile,

    _In_         LPCVOID lpBuffer,

    _In_         DWORD nNumberOfBytesToWrite,

    _Out_opt_    LPDWORD lpNumberOfBytesWritten,实际写入字节数

    _Inout_opt_  LPOVERLAPPED lpOverlapped );  

    HANDLE hFile;
    hFile = CreateFile("5.txt",GENERIC_WRITE,0,NULL,CREATE_NEW,FILE_ATTRIBUTE_NORMAL,NULL);
    DWORD dwWrites;
    WriteFile(hFile,"dsafdasfasdfasdfsafasdf",strlen("dsafdasfasdfasdfsafasdf"),&dwWrites,NULL);
    CloseHandle(hFile);

    HANDLE hFile;
    hFile = CreateFile("5.txt",GENERIC_READ,0,NULL,OPEN_EXISTING,FILE_ATTRIBUTE_NORMAL,NULL);
    char ch[100];
    DWORD dwReads;
    ReadFile(hFile,ch,100,&dwReads,NULL);
    ch[dwReads]= 0;
    CloseHandle(hFile);
    MessageBox(ch);

    CFile 文件编程还是挺方便的。

          • CFile::modeCreate   Directs the constructor to create a new file. If the file exists already, it is truncated to 0 length.
          • CFile::modeNoTruncate   Combine this value with modeCreate. If the file being created already exists, it is not truncated to 0 length. Thus the file is guaranteed to open, either as a newly created file or as an existing file. This might be useful, for example, when opening a settings file that may or may not exist already. This option applies to CStdioFile as well.
          • CFile::modeRead   Opens the file for reading only.
          • CFile::modeReadWrite   Opens the file for reading and writing.
          • CFile::modeWrite   Opens the file for writing only.
          • CFile::modeNoInherit   Prevents the file from being inherited by child processes.
          • CFile::shareDenyNone   Opens the file without denying other processes read or write access to the file. Create fails if the file has been opened in compatibility mode by any other process.
          • CFile::shareDenyRead   Opens the file and denies other processes read access to the file. Create fails if the file has been opened in compatibility mode or for read access by any other process.
          • CFile::shareDenyWrite   Opens the file and denies other processes write access to the file. Create fails if the file has been opened in compatibility mode or for write access by any other process.
          • CFile::shareExclusive   Opens the file with exclusive mode, denying other processes both read and write access to the file. Construction fails if the file has been opened in any other mode for read or write access, even by the current process.
          • CFile::shareCompat   This flag is not available in 32 bit MFC. This flag maps to CFile::shareExclusive when used in CFile::Open.
          • CFile::typeText   Sets text mode with special processing for carriage return–linefeed pairs (used in derived classes only).
          • CFile::typeBinary   Sets binary mode (used in derived classes only).

    CFile file("6.txt",CFile::modeCreate | CFile::modeWrite );
    file.Write("1234567890",strlen("1234567890"));
    file.Close();

    CFile file("6.txt",CFile::modeRead);
    char *pBuf;
    DWORD dwFileLen;
    dwFileLen = file.GetLength();
    pBuf = new char[dwFileLen+1];
    pBuf[dwFileLen] = 0;

    file.Read(pBuf,dwFileLen);
    file.Close();
    MessageBox(pBuf);

    CFileDialog

    typedef struct tagOFN {

    DWORD         lStructSize;

    HWND          hwndOwner;

    HINSTANCE     hInstance;

    LPCTSTR       lpstrFilter;

    LPTSTR        lpstrCustomFilter;

    DWORD         nMaxCustFilter;

    DWORD         nFilterIndex;

    LPTSTR        lpstrFile;

    DWORD         nMaxFile;

    LPTSTR        lpstrFileTitle;

    DWORD         nMaxFileTitle;

    LPCTSTR       lpstrInitialDir;

    LPCTSTR       lpstrTitle;

    DWORD         Flags;

    WORD          nFileOffset;

    WORD          nFileExtension;

    LPCTSTR       lpstrDefExt;

    LPARAM        lCustData;

    LPOFNHOOKPROC lpfnHook;

    LPCTSTR       lpTemplateName;

    #if (_WIN32_WINNT >= 0x0500)

    void          *pvReserved;

    DWORD         dwReserved; DWORD         FlagsEx;

    #endif

    } OPENFILENAME, *LPOPENFILENAME;


    CFileDialog fileDlg(FALSE);
    fileDlg.m_ofn.lpstrTitle= " 保存文件  ";
    fileDlg.m_ofn.lpstrFilter="Text Files(*.txt)\0*.txt\0All Files(*.*)\0*.*\0\0";//只是显示\0过滤功能
    fileDlg.m_ofn.lpstrDefExt="txt";
    if(IDOK ==     fileDlg.DoModal())
    {
        CFile file(fileDlg.GetFileName(),CFile::modeCreate | CFile::modeWrite );
        file.Write( "dsafdasfasdfasdfsafasdf",strlen("dsafdasfasdfasdfsafasdf") );
        file.Close();
    }

    CFileDialog fileDlg(TRUE);
    fileDlg.m_ofn.lpstrTitle= " 打开文件  ";
    fileDlg.m_ofn.lpstrFilter="Text Files(*.txt)\0*.txt\0All Files(*.*)\0*.*\0\0";//只是显示\0过滤功能
     
    if(IDOK ==     fileDlg.DoModal())
    {
        CFile file(fileDlg.GetFileName(),CFile::modeRead);
        char *pBuf;
    DWORD dwFileLen;
    dwFileLen = file.GetLength();
    pBuf = new char[dwFileLen+1];
    pBuf[dwFileLen] = 0;

    file.Read(pBuf,dwFileLen);
    file.Close();
    MessageBox(pBuf);
     

    WriteProfileString 

    CWinApp::WriteProfileString

    调用该成员函数将指定字符串与应用程序的注册表或.INI文件的指定部分。

    BOOL WriteProfileString(
       LPCTSTR lpszSection,
       LPCTSTR lpszEntry,
       LPCTSTR lpszValue 
    );

    参数

    lpszSection

    指向指定包含项的节的一个Null终止的字符串。 如果节不存在,则创建。 该节的名称是用例独立;该字符串可以是大写和小写字母的任意组合。

    lpszEntry

    指向包含项该值将写入的一个Null终止的字符串。 如果项不存在于指定的部分,则创建。 如果此参数是 NULL,lpszSection 指定的部分中删除。

    lpszValue

    指向该字符串将编写。 如果此参数是 NULL,lpszEntry 参数指定的项被删除。

    GetProfileString 

    BOOL CFileApp::InitInstance()……

    CString str;
    ::GetProfileString("dkfasjldfkasdlf","admin","lisa",str.GetBuffer(100),100);
    AfxMessageBox(str);

    ::WriteProfileString("dkfjaklsdfkjadslfdjsfkla","admin","liu");

    regedit  HKEY_CURRENT_USER / SOFTWARE/

    从注册表读取信息

    GetProfileString

    对注册表编程

    RegCreateKey

    WHAT A NICE DAY TODAY!

    LONG RegCreateKey( HKEY hKey, // 要打开键的句柄 LPCTSTR lpSubKey, // 要打开子键的名字的地址 PHKEY phkResult // 已打开句柄的缓存区的地址 );

    
    
    参数
    hKey
    当前打开键的句柄或下列已确定保留句柄值:

    HKEY_CLASSES_root
    HKEY_CURRENT_CONFIG
    HKEY_CURRENT_USER
    HKEY_LOCAL_MACHINE
    HKEY_USERS
    windows NT: HKEY_PERFORMANCE_DATA
    Windows 95和
    windows 98: HKEY_DYN_DATA

    被RegCreateKey打开或新建的是被hKey识别的键的子键。

    lpSubKey
    指向包含了要打开或新建键的名字的以空字符结束的字符串。这个键必须是能被hKey参数识别的子键。

    如果hKey是已确定保留句柄值之一,lpSubKey可以为NULL。在这种情形下,函数phkResult返回与被传递相同的句柄。

    phkResult
    指向接收打开或新建键的变量。当你不再需要返回句柄时,调用RegCloseKey函数关闭它
    返回值

    如果调用成功,返回ERROR_SUCCESS。

    如果调用失败,返回一个非零错误码(定义在WINERROR.H)。你可以使用带有FORMAT_MESSAGE_FROM_SYSTEM标记的FormatMessage函数获得普通错误描述信息。

    注意

    一个应用程序可以使用RegCreateKey函数一次新建单独键。如,一个应用程序可以在共一时间新建一个四级子键(包括给定键前面的三级)象以下的lpSubKey参数字符串:

    subkey1subkey2subkey3subkey4

    这个能被hKey参数识别的键必须被带有KEY_CREATE_SUB_KEY存取权限打开(KEY_WRITE存取权限包括KEY_CREATE_SUB_KEY存取权限)。

    如果lpSubKey参数是一个空字符串的地址,函数打开并传递能被hKey参数识别的键。

    快速信息

    Windows NT: 需要3.1或更高版本。
    Windows: 需要Windows 95或更高版本。
    Windows CE: 不支持。
    文件头: winreg.h
    输入库: advapi32.lib.
    Unicode: 在Windows NT中作为Unicode和ANSI
    执行

    参见

    RegSetValue 指定注册表项的 缺省的  没有名字的 数据。值的 名称  类型 值本身。

    RegQueryValue  查看注册表

    RegSetValueEx

    RegOpenKey

    HKEY hKey;
    RegOpenKey(HKEY_LOCAL_MACHINE,"Software\\LIUJIAHAO\\admin",&hKey);
    DWORD dwType;
    DWORD dwValue;
    DWORD dwAge;
    RegQueryValueEx(hKey,"age",0,&dwType,(LPBYTE)&dwAge,&dwValue);
    CString str;
    str.Format("age=%d",dwAge);
    MessageBox(dwAge);

    4.14 Lesson 13                                                                                                                                                                   

    文件读写

    CArchive 没有基类

    当应用程序关闭后, 下次开始,利用存储的对象持久,再重新构建。将对象保存在磁盘上,让对象数据持久过程,就是串行化,一种类型的二进制流,一个archive与IO有关,带缓冲的读取数据,有效率的非冗余处理二进制对象数据。 必须创建CFILE对象, 必须确保一致。

    BOOL CGraphic3Doc::OnNewDocument()

    程序启动时就要被 调用

    另个改名字的 String table : Graphic3\n\nGraphi\n\n\nGraphic3.Document\nGraphi Document

    CSingleDocTemplate* pDocTemplate;
    pDocTemplate = new CSingleDocTemplate(
        IDR_MAINFRAME,
        RUNTIME_CLASS(CGraphic3Doc),
        RUNTIME_CLASS(CMainFrame),       // main SDI frame window
        RUNTIME_CLASS(CGraphic3View));

    AddDocTemplate(pDocTemplate);

    //将资源ID传进


    GetDocString   文档模板函数获取各子串

    IDR_MAINFRAME七个子串的含义:(1)主框架窗口标题(2)缺省文档名称(3)文档类型名称(4)

    APPDLG.CPP

    void CWinApp::OnFileNew()
    {
        if (m_pDocManager != NULL)
            m_pDocManager->OnFileNew();
    }

        CDocManager* m_pDocManager;

    DOCMGR. CPP

    void CDocManager::OnFileNew()

    DOCSINGLE.CPP

    CDocument* CSingleDocTemplate::OpenDocumentFile(LPCTSTR lpszPathName,    BOOL bMakeVisible)

    没有调用基类中的,(文档模板类中,是一个虚函数

    virtual CDocument* OpenDocumentFile(
        LPCTSTR lpszPathName, BOOL bMakeVisible = TRUE) = 0;
                    // open named file
                    // if lpszPathName == NULL => create new file with this type

    一个文档产生:文档、 框架 、 视类 对象

    1. CWinApp::OnFileNeW() 菜单点击命令消息响应. 2.CDocManager:: OnFileNew()文档管理类    3.利用文档模板指针(单文档模板指针) pTemplate->OpenDocumentFile(NULL);

    4. 单文档模板类中 CDocument* SingleDocumentFile  5.开始创建文档类对象   6.框架类对象  7. 同时,视类对象 ,同时视类窗口  8. 文档指针,实际用子类指针调用

    保存、加载数据

    void CGraphic3Doc::Serialize(CArchive& ar)

    52.37

    又跟上次一样,觉得耳朵有点蒙了,“余学而忘食,乐以忘忧,不知老之将至云尔。”  书没读出来人就死了有个屁用。

    void CGraphic3Doc::Serialize(CArchive& ar)

    mfc打开文件也是用CFileDlg

    APPUI.CPP  OpenDocumentFile

    文档对象始终只有一个,单文档。  多文档对象是不同的。

    线索 cwinapp 管理文档,文档管理器管理文档模板,  文档模板管理框架类0视类文档类三位一体, 

    Serialize保存 一个可串行的类 通常有一个串行化成员函数,

    五个步骤:

    1:让你的类从CObject派生  。

    2:覆盖Serialize函数。

    3:在头文件中使用DECLARE_SERIAL宏,     DECLARE_SERIAL(CGraph)

    4:定义一个不带参数的构造函数

    5:实现文件中使用IMPLEMENT_SERIAL宏

    菜单 资源还可以直接复制过来, , , so easy但我觉得这在java开发中算是常用大法啊

    集合类 CObArray   加入的是CObject指针

    文档类得到视类指针  GetFirstViewPosition 得到和文档相关的视类对象, 对视类对象只能和一个文档类相关。 获得第一个视类对象在视类对象列表中的位置,

    1.43 OMG利用文档类保存一个可串行化对象,实际上利用一个对象本身的可串行化类确定的,哪些数据,

    CObArray                                 

    view类访问文档类对象指针  , , GetDocument,  MFC 文档框架 视类结构, 

    Deletecontents 文档对象是被重复使用的,单文档。 释放分配的内存。

    DOC类上增加虚函数,释放堆上分配的内存,        delete m_obArray.GetAt(i); 删除指针指向堆内存, 指针值仍然是存在的。内存泄漏  

    m_obArray.RemoveAll(); OTHER THAN    m_obArray.RemoveAt(i); (因为计数器的原因,仍然可能会泄漏

    the socalled smart maybe like …….  

    while (count - - )  非零即为真, 初始3 、  可供操作的计数器为: 2 , 1 , 0

    /////////////////////////////////////////////////////////4.15 网络编程14                                                                                                                

    Server:create socket , bind ,  listen , accept ,  send/recv,  wait another  client, close….

    client: create socket, connect ,  send/recv, close.

    UDP :

    server: socket , bind , recvfrom , close;

    client: socket , sendto, close .

    WSAStartup 这里有个使用的例子。

    alt + f8 格式化代码

    socket

    htonl  htons 

    bind

    accept

    link:   ws2_32.lib  client端也需要设置这个lib

    UDP 1.27

    ws2_32.lib

    recvfrom

    sendto

    一时脑抽,简单讲是这样的, 杯里没水,想倒杯水。抬头看到一大盒“特浓”型 的雀巢pia’pia向我招手,伸手出去然后不知怎么滴,杯里就满满的了,红色的咖啡油脂上,泛亮了一缕白烟,告诉我这一切 虽然只是电花火石的一瞬间,也已经是过去时了。此时 我还没有想起 失眠,当然 也没有  为每天的难以入睡而感到忧虑万分,随手又抄起一袋来提高浓度。随着这两袋特浓的迅速溶解,我的思绪也化开了:我了个去啊, 喝杯小绿茶都能失眠的人,这叫我怎么活呀。

    interesting

  • 相关阅读:
    jQuery插件编写步骤详解
    原生JavaScript实现JSON合并(递归深度合并)
    js原型链继承及调用父类方法
    codefind.pl
    如何为属性是disabled的表单绑定js事件
    平假名、片假名转换
    #和##在宏替换中的作用
    Perl实用中文处理步骤(修改版)
    Perl Unicode全攻略
    nio DirectByteBuffer如何回收堆外内存
  • 原文地址:https://www.cnblogs.com/iamgoodman/p/3013292.html
Copyright © 2011-2022 走看看