Thursday, March 11, 2010

DirectX-Note

Include Setting
Go to your project's properties | Configuration Properties | VC++ Directories.
Setting Include Directories :

32 bit Win: C:\Program Files\Microsoft DirectX SDK (June 2010)\Include

64 bit Win: C:\Program Files (x86)\Microsoft DirectX SDK (June 2010)\Include

Your project will know d3dx10.h and d3dx11.h

And Library


32 bit Win: C:\Program Files\Microsoft DirectX SDK (June 2010)\Lib\x86

64 bit Win: C:\Program Files (x86)\Microsoft DirectX SDK (June 2010)\Lib\x64


宣告

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



int WINAPI WinMain(HINSTANCE hInstance,HINSTANCE hPrevInstance,LPSTR lpCmdLine,int nShowCmd)
{
//----------RegisterClass
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.hCursor = LoadCursor(NULL,IDC_ARROW);
wc.hbrBackground = (HBRUSH)COLOR_WINDOW;
wc.lpszClassName = "WindowClass1";

RegisterClassEx(&wc);
//-----------Create Window Application

hWnd = CreateWindowEx(NULL,"WindowClass1","WindowClass1",WS_OVERLAPPEDWINDOW,300,300,1280,720,NULL,NULL,hInstance,NULL);

ShowWindow(hWnd,nShowCmd);

//---------- The Main Loop
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_DESTROY :
{
PostQuitMessage(0);
return 0;
}break;
}

return DefWindowProc(hWnd,message,wParam,lParam);
}


1.RegisterClass
2.Create Window
3.Show Window

WNDCLASSEX wc :This is a struct that contains the information for the window class.

ZeroMemory(&wc, sizeof(WNDCLASSEX)) : ZeroMemory is a function that initializes an entire block of memory to NULL.

wc.cbSize = sizeof(WNDCLASSEX): size up this structure and tell it what it's measurements are.

wc.style = CS_HREDRAW | CS_VREDRAW:There are plenty of values we can insert, but we will almost never use any of them in game programming.

wc.lpfnWndProc = WindowProc:This value tells the window class what function to use when it gets a message from Windows.

wc.hInstance = hInstance:Just put the value Windows handed to us in WinMain().

wc.hCursor = LoadCursor(NULL, IDC_ARROW):This member stores the default mouse image for the window class.
---------------------------------------------------------------------------------------------------
Window Size Versue Client Size

BOOL AdjustWindowRect(LPRECT lpRect,DWORD dwStyle,BOOL bMenu);
RECT wr = {0,0,windowWidth,windowHeight};
LPRECT lpRect: Send &wr.
WORD dwStyle: your windowstyle.
BOOL bMenu: not necessary always FALSE.

part of Code


RECT wr = {0,0,500,400};
AdjustWindowRect(&wr,WS_OVERLAPPEDWINDOW,FALSE);
hWnd = CreateWindowEx(NULL,"WindowClass1","WindowClass1",WS_OVERLAPPEDWINDOW,300,300,wr.right-wr.left,wr.bottom-wr.top,NULL,NULL,hInstance,NULL);


It is adjust your image at right  position while you change your window size.



No comments:

Post a Comment