Katex

顯示具有 MFC 標籤的文章。 顯示所有文章
顯示具有 MFC 標籤的文章。 顯示所有文章

2012年1月22日 星期日

MFC: Status Bar


                CStatusBar statusbar;

static UINT indicators[] =
{
ID_SEPARATOR,
IDS_UserDefStr1,
IDS_UserDefStr2
};

statusbar.Create(this);
statusbar.SetIndicators(indicators, sizeof(indicators)/sizeof(UINT));

2012年1月21日 星期六

CFrameWnd



Functions

MFC : windows style


  • WS_BORDER   Creates a window that has a border.
  • WS_CAPTION   Creates a window that has a title bar (implies the WS_BORDER style). Cannot be used with the WS_DLGFRAME style.
  • WS_CHILD   Creates a child window. Cannot be used with the WS_POPUP style.
  • WS_CHILDWINDOW   Same as the WS_CHILD style.
  • WS_CLIPCHILDREN   Excludes the area occupied by child windows when you draw within the parent window. Used when you create the parent window.
  • WS_CLIPSIBLINGS   Clips child windows relative to each other; that is, when a particular child window receives a paint message, the WS_CLIPSIBLINGS style clips all other overlapped child windows out of the region of the child window to be updated. (If WS_CLIPSIBLINGS is not given and child windows overlap, when you draw within the client area of a child window, it is possible to draw within the client area of a neighboring child window.) For use with the WS_CHILD style only.
  • WS_DISABLED   Creates a window that is initially disabled.
  • WS_DLGFRAME   Creates a window with a double border but no title.
  • WS_GROUP   Specifies the first control of a group of controls in which the user can move from one control to the next with the arrow keys. All controls defined with the WS_GROUP style FALSE after the first control belong to the same group. The next control with the WS_GROUP style starts the next group (that is, one group ends where the next begins).
  • WS_HSCROLL   Creates a window that has a horizontal scroll bar.
  • WS_ICONIC   Creates a window that is initially minimized. Same as the WS_MINIMIZE style.
  • WS_MAXIMIZE   Creates a window of maximum size.
  • WS_MAXIMIZEBOX   Creates a window that has a Maximize button.
  • WS_MINIMIZE   Creates a window that is initially minimized. For use with the WS_OVERLAPPED style only.
  • WS_MINIMIZEBOX   Creates a window that has a Minimize button.
  • WS_OVERLAPPED   Creates an overlapped window. An overlapped window usually has a caption and a border.
  • WS_OVERLAPPEDWINDOW   Creates an overlapped window with the WS_OVERLAPPED, WS_CAPTION, WS_SYSMENU, WS_THICKFRAME, WS_MINIMIZEBOX, and WS_MAXIMIZEBOX styles.
  • WS_POPUP   Creates a pop-up window. Cannot be used with the WS_CHILD style.
  • WS_POPUPWINDOW   Creates a pop-up window with the WS_BORDER, WS_POPUP, and WS_SYSMENU styles. The WS_CAPTION style must be combined with the WS_POPUPWINDOW style to make the Control menu visible.
  • WS_SIZEBOX   Creates a window that has a sizing border. Same as the WS_THICKFRAME style.
  • WS_SYSMENU   Creates a window that has a Control-menu box in its title bar. Used only for windows with title bars.
  • WS_TABSTOP   Specifies one of any number of controls through which the user can move by using the TAB key. The TAB key moves the user to the next control specified by the WS_TABSTOP style.
  • WS_THICKFRAME   Creates a window with a thick frame that can be used to size the window.
  • WS_TILED   Creates an overlapped window. An overlapped window has a title bar and a border. Same as the WS_OVERLAPPED style.
  • WS_TILEDWINDOW   Creates an overlapped window with the WS_OVERLAPPED, WS_CAPTION, WS_SYSMENU, WS_THICKFRAME, WS_MINIMIZEBOX, and WS_MAXIMIZEBOX styles. Same as theWS_OVERLAPPEDWINDOW style.
  • WS_VISIBLE   Creates a window that is initially visible.
  • WS_VSCROLL   Creates a window that has a vertical scroll bar.

2012年1月11日 星期三

MFC: Document/View










1. Document / View / Frame

CDocument *doc;

CSingleDocTemplate* DocTemplate;
DocTemplate = new CSingleDocTemplate(
IDR_MENU1,
RUNTIME_CLASS(MyDocument),
RUNTIME_CLASS(MyFrame),
RUNTIME_CLASS(MyView));

AddDocTemplate(DocTemplate);

doc = DocTemplate->CreateNewDocument();

m_pMainWnd = DocTemplate->CreateNewFrame(doc, NULL);

DocTemplate->InitialUpdateFrame(
(CFrameWnd*)m_pMainWnd, doc);


2.   動態宣告開啟

class MyFrame : public CFrameWnd
{
public :
DECLARE_DYNCREATE(MyFrame);
}

IMPLEMENT_DYNCREATE(MyFrame, CFrameWnd);

3. 更改視窗名稱
    doc->SetTitle("Hello Document");


2012年1月2日 星期一

[MFC] MSDN - CWnd::MessageBox


CWnd::MessageBox

int MessageBox(
   LPCTSTR lpszText,
   LPCTSTR lpszCaption = NULL,
   UINT nType = MB_OK 
);
Return Value

Type: int
If a message box has a Cancel button, the function returns the IDCANCEL value if either the ESC key is pressed or the Cancel button is selected. If the message box has no Cancel button, pressing ESC has no effect.
If the function fails, the return value is zero. To get extended error information, call GetLastError.
If the function succeeds, the return value is one of the following menu-item values.

Return code/valueDescription
IDABORT
3
The Abort button was selected.
IDCANCEL
2
The Cancel button was selected.
IDCONTINUE
11
The Continue button was selected.
IDIGNORE
5
The Ignore button was selected.
IDNO
7
The No button was selected.
IDOK
1
The OK button was selected.
IDRETRY
4
The Retry button was selected.
IDTRYAGAIN
10
The Try Again button was selected.
IDYES
6
The Yes button was selected.

Parameters

nType

The following message-box styles are available.

  • MB_ABORTRETRYIGNORE   The message box contains three pushbuttons: Abort, Retry, and Ignore.
  • MB_OK   The message box contains one pushbutton: OK.
  • MB_OKCANCEL   The message box contains two pushbuttons: OK and Cancel.
  • MB_RETRYCANCEL   The message box contains two pushbuttons: Retry and Cancel.
  • MB_YESNO   The message box contains two pushbuttons: Yes and No.
  • MB_YESNOCANCEL   The message box contains three pushbuttons: Yes, No, and Cancel.

  • MB_APPLMODAL   The user must respond to the message box before continuing work in the current window. However, the user can move to the windows of other applications and work in those windows. The default is MB_APPLMODAL if neither MB_SYSTEMMODAL nor MB_TASKMODAL is specified.
  • MB_SYSTEMMODAL   All applications are suspended until the user responds to the message box. System-modal message boxes are used to notify the user of serious, potentially damaging errors that require immediate attention and should be used sparingly.
  • MB_TASKMODAL   Similar to MB_APPLMODAL, but not useful within a Microsoft Foundation class application. This flag is reserved for a calling application or library that does not have a window handle available.

  • MB_ICONEXCLAMATION   An exclamation-point icon appears in the message box.
  • MB_ICONINFORMATION   An icon consisting of an "I" in a circle appears in the message box.
  • MB_ICONQUESTION   A question-mark icon appears in the message box.
  • MB_ICONSTOP   A stop-sign icon appears in the message box.

  • MB_DEFBUTTON1   The first button is the default. Note that the first button is always the default unless MB_DEFBUTTON2 or MB_DEFBUTTON3 is specified.
  • MB_DEFBUTTON2   The second button is the default.
  • MB_DEFBUTTON3   The third button is the default.

[MFC] MSDN - CDC Members




MFC - message

class MyFrame : public CFrameWnd
{
...
DECLARE_MESSAGE_MAP()
};

BEGIN_MESSAGE_MAP(MyFrame, CFrameWnd)
...
END_MESSAGE_MAP()




ON_WM_LBUTTONDOWN() : 滑鼠左鍵按下
   afx_msg void OnLButtonDown(UINT nFlags, CPoint point)
{
char szBuffer[100];
wsprintf(szBuffer, "LButton point(%ld, %ld)", point.x, point.y);
              MessageBox(szBuffer);
}

afx_msg void OnLButtonDown(UINT nFlags, CPoint point)
{
SetCapture();
}

ON_WM_MOUSEMOVE() : 滑鼠游標移動
afx_msg void OnMouseMove(UINT nFlags, CPoint point)
{
if ( this == GetCapture() )
{
CClientDC aDC(this);
aDC.SetPixel(point, RGB(225, 0, 0) );
}
}

ON_WM_LBUTTONUP() : 滑鼠左鍵放開
afx_msg void OnLButtonUp(UINT nFlags, CPoint point)
{
ReleaseCapture();
}


2011年12月26日 星期一

MFC - Hello -1



#include <afxwin.h>
#include "resource.h"

class MyFrame : public CFrameWnd
{
private:
 CMenu  *FMenu;

public:
 MyFrame() {
  Create(NULL, "Hello MFC-1");
  FMenu = new CMenu;
  FMenu->LoadMenu(IDR_MENU1);
  SetMenu(FMenu);
 }
};

class HelloMFC : public CWinApp
{
public:
 BOOL InitInstance()
 {
  CFrameWnd *frame = new MyFrame();
  m_pMainWnd = frame;

  frame->ShowWindow(SW_SHOW);

  return true;
 }
};

HelloMFC m_HelloMFC;



====
1. resource.h / IDR_MENU1

建立 resource 


加入新項目


建立資源檔 : 名稱和專案相同


資源檢視 - 選擇 Menu


設計 Menu 項目

====

執行結果



2011年12月19日 星期一

MFC: Hello

Use Visual studio

1. Visual Studio 2010
    Professional

2. 專案屬性
     - 使用 MFC 靜態程式庫


     - 使用多位元組字元集


   - Linker -> System -> subsystem : 選 windows


3. Program : HelloMFC.cpp

#include <afxwin.h>

class HelloMFC : public CWinApp
{
public:
 BOOL InitInstance()
 {
  CFrameWnd *frame = new CFrameWnd();
  m_pMainWnd = frame;

  Frame->Create(NULL, "Hello MFC");
  Frame->ShowWindow(SW_SHOW);

  return true;
 }
};

HelloMFC m_HelloMFC;


4. CWinApp
    - 是由 CWinThread 所衍生

5. InitInstance
   - 是唯一 CWinApp 需要覆寫的程式

6. CFrameWnd
   - CWnd 有以下幾類 :
      * Frame Window : CFrameWnd
      * Control Bars : CControlBar
      * Property Sheets
      * Dialog Boxes
      * Views
      * Controls

7. m_pMainWnd
   - 儲存線程主窗口對象, 若主窗口被關閉, 線程也會終止

8. CFrameWnd::Create

9. CWnd::Show

10. 執行結果


2010年12月18日 星期六

MFC : Microsoft Foundation Classes

MFC 是 Microsoft 提供的 class libraries. 在 1992 年隨著 Microsoft C/C++ 7.0 釋出. 以 C++ 型式封裝 Windows API. 並包含應用程式框架.


產品版本MFC 版本
Microsoft C/C++ 7.0MFC 1.0
Visual C++ 1.0MFC 2.0
Visual C++ 1.5MFC 2.5
Visual C++ 2.0MFC 3.0
Visual C++ 2.1MFC 3.1
Visual C++ 2.2MFC 3.2
Visual C++ 4.0MFC 4.0 (mfc40.dll 包含於 Windows 95)
Visual C++ 4.1MFC 4.1
Visual C++ 4.2MFC 4.2(mfc42.dll 包含於 Windows 98 第一版)
Pocket PC Embedded 3.0MFC 4.2 (mfc42.dll)
Visual C++ 5.0MFC 4.21 (mfc42.dll)
Visual C++ 6.0MFC 6.0 (mfc42.dll)
Visual C++ .NET 2002MFC 7.0 (mfc70.dll)
Visual C++ .NET 2003MFC 7.1 (mfc71.dll)
Visual C++ 20051MFC 8.0 (mfc80.dll)
Visual C++ 20081MFC 9.0.21022 (mfc90.dll)
Visual C++ 2008(包含 Feature Pack)2MFC 9.0.30411 (mfc90.dll)
Visual C++ 20101MFC 10.0.30319.1 (mfc100.dll)


Ref: http://zh.wikipedia.org/wiki/MFC

熱門文章