MFC FrameWork函数

    来自于AFX framework

  • AfxFormatString1
  • AfxFormatString2
  • AfxMessageBox
  • AfxFreeLibrary
  • AfxGetApp
  • AfxGetAppName
  • AfxGetInstanceHandle
  • AfxGetMainWnd
  • AfxGetResourceHandle
  • AfxInitRichEdit
  • AfxLoadLibrary
  • AfxMessageBox
  • AfxRegisterWndClass
  • AfxSocketInit
  • AfxSetResourceHandle
  • AfxRegisterClass
  • AfxBeginThread
  • AfxEndThread
  • AfxGetThread
  • AfxWinInit

1.其中 AfxGetApp()能得到

CSimpleApp theApp;

CWinApp* AfxGetApp();
 
 
 
 

2.和win32的WinMain()函数一样,afx提供了这个函数

BOOL AFXAPI AfxWinInit(HINSTANCE hInstance,
		       HINSTANCE hPrevInstance,
                       LPTSTR lpCmdLine,
		       int nCmdShow);

   variables是和WinMain是一样的


3. Win的class都会保存自身的地址,WinApp()会保存为HINSTANCE  m_hInstance;

要得到他:  

HINSTANCE AfxGetInstanceHandle();
 

When you start an application such as Notepad, you are said to have created an instance of the application.

In the same way, when you declare a variable of a class, an instance of the class is created and made available

to the project. The WinMain() function also allows you to create an instance of an application,

referred to as the hInstance argument of the WinMain() function. The instance is created as an HINSTANCE.

The CWinApp class provides a corresponding instance variable called m_hInstance.

This variable can let you get a handle to the instance of your application. Alternatively,

to get a handle to the instance of your application, you can call the AfxGetInstanceHandle() global function.

Its syntax is:

    HINSTANCE AfxGetInstanceHandle();

4. 

Even more, to get a handle to your application, you can call the Win32 API's GetWindowLong()function. Suppose you have opened Notepad to view the source code of an HTML document. This is said that you have an instance of Notepad. Imagine that you want to open a text document using Notepad without closing the first instance of Notepad. To do this, you must open another copy of Notepad. This second copy of Notepad is another instance. In this case, the first instance is referred to as a previous instance. For a Win32 application, the previous instance would be the hPrevInstance argument of the WinMain() function. For a Win32 application, the hPrevInstanceargument always has the NULL value. If you want to find out whether a previous instance of an application already exists, you can call the CWnd::FindWindow() method. Its syntax is:

static CWnd* PASCAL FindWindow(LPCTSTR lpszClassName, LPCTSTR lpszWindowName);


5. If you created the window or if it is a window you know for sure, in which case it could be a WNDCLASS or WNDCLASSEX object, specify it as the lpszClassName argument. If you do not know its name with certainty, set this argument as NULL. The lpszWindowName argument is the possible caption of the window you are looking for. Imagine you position a button on a dialog box and you want the user to launch Notepad with that button and imagine that, if Notepad is already opened, there would be no reason to create another instance of it.

The CWinApp class provides all the basic functionality that an application needs. It is equipped with a method called InitInstance(). Its syntax is:

virtual BOOL InitInstance();

When creating an application, you must override this method in your own class. This method is used to create an application. If it succeeds, it returns TRUE or a non-zero value. If the application could not be created, the method returns FALSE or 0.

Here is an example of implementing it:

class CSimpleApp : public CWinApp
{
    BOOL InitInstance() { return TRUE; }
};


6.   The Command Line

To execute a program, you must communicate its path and possibly some additional parameters to the compiler. This information is called the command line information and it is supplied as a string. You need to keep that in mind although all programs of our lessons will be compiled inside of Visual C++. The command line information is supplied to the compiler as the lpCmdLineargument of the WinMain() function. Internally, Visual C++ creates the path and communicates it to the compiler when you execute the program. If you want to find out what command line was used to execute your program, you can call the Win32's GetCommandLine() function. Its syntax is:

LPTSTR GetCommandLine(VOID);

This function takes no argument but returns the command line of an application as a null-terminated string.





评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值