Friday, November 16, 2012

C++ & MFC Practice


MFC 應用程式

建立應用程式類別

1.繼承CWinApp
2.直接使用CFrameWnd 類別產生視窗


專案設定:

MFC的使用 : 使用MFC靜態程式庫
字元集:使用多位元組字元集
#include

class MyApp: public CWinApp
{
public :
BOOL InitInstance()
{
CFrameWnd *Frame = new CFrameWnd();
m_pMainWnd = Frame;

Frame->Create(NULL,"Hello MFC");
Frame->ShowWindow(SW_SHOW);
return true;
}
};
MyApp a_app; //Build Application

---------------------------------------------------------------------------------------

VC++ Window API

                                WindowAPI
                                   |           |
                       WinMain()      WindowProc
                                                          程式起始                                 訊息


WNDCLASSEX: 定義視窗。
ZeroMemory:設定應用程式位址。
決定視窗所有屬性。
處理視窗訊息。WindlwProc
Ready to initialize DirectX 3D.



#include
#include

LRESULT CALLBACK WindowProc(HWND hWnd,UINT message,WPARAM wParam,LPARAM lParam);


int WINAPI WinMain(HINSTANCE hInstance,HINSTANCE hPrvInstance,LPSTR lpCmdLine,int nCmdShow)
{
HWND hWnd;

WNDCLASSEX wc;

ZeroMemory(&wc,sizeof(WNDCLASSEX));

wc.cbSize = sizeof(WNDCLASSEX);
wc.style = CS_HREDRAW | CS_VREDRAW;
wc.lpfnWndProc = WindowProc;
wc.hInstance = hInstance;
wc.hbrBackground = (HBRUSH)COLOR_WINDOW;
wc.lpszClassName = L"WindowClass1";

wc.cbClsExtra = 0;
wc.cbWndExtra = 0;


RegisterClassEx(&wc);

RECT wr = {0,0,500,400};
AdjustWindowRect(&wr,WS_OVERLAPPEDWINDOW,false);
wc.hCursor = LoadCursor(NULL,IDC_ARROW);
wc.hIcon = LoadIcon(0,IDI_APPLICATION);

hWnd = CreateWindowEx(NULL,
 L"WindowClass1",
 L"Our First Windowed Program",
 WS_OVERLAPPEDWINDOW,
 300,300,
 wr.right - wr.left,
 wr.bottom - wr.top,
 NULL,NULL,
 hInstance,NULL);

ShowWindow(hWnd,nCmdShow);

MSG msg;

while(GetMessage(&msg,NULL,0,0))
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
return msg.wParam;
}

LRESULT CALLBACK WindowProc(HWND hWnd,UINT message,WPARAM wParam,LPARAM lParam)
{
switch (message)
{
case  WM_PAINT:
HDC hDC;
PAINTSTRUCT PaintSt;
RECT aRect;
hDC = BeginPaint(hWnd,&PaintSt);
GetClientRect(hWnd,&aRect);

DrawText(hDC,L"First Window SDK Programing With D3D",
-1,&aRect,
DT_SINGLELINE | DT_CENTER | DT_VCENTER);
EndPaint(hWnd,&PaintSt);
return 0;

case  WM_LBUTTONDOWN:
break;

case WM_LBUTTONUP:
break;

case WM_DESTROY:
{
PostQuitMessage(0);
return 0;
}break;
}
return DefWindowProc(hWnd,message,wParam,lParam);
}

-----------------------------------------------------------------------------------------------------------------------

Design Pattern & Software development


Inversion of Control

創立一個Interface 讓高階模組和低階模組可以共同存取溝通所需要的值。

Test Drive Development
Visual studio 2012 用法:
http://channel9.msdn.com/Events/TechEd/Europe/2012/DEV214







No comments:

Post a Comment