您的位置:首页 > 其它

Window SDK 入门

2015-06-24 00:50 435 查看
#include<Windows.h>
#include<conio.h>
#include<memory>

#include"GameSpriteDemo.h"
#include"TriangleDemo.h"

#include"D3DTextDemo.h"

/*
* This is the beginning of the main function
*
* Author: ROTBLATT
* Date: 2015-05-31
*
*/

LRESULT CALLBACK WndProc(HWND hwnd, UINT message,
WPARAM wParam, LPARAM lParam);

int WINAPI wWinMain(HINSTANCE hInstance, HINSTANCE prevInstance,
LPWSTR cmdLine, int cmdShow)
{
UNREFERENCED_PARAMETER(prevInstance);
UNREFERENCED_PARAMETER(cmdLine);

WNDCLASSEX wndClass = { 0 };
//ZeroMemory(&wndClass, sizeof(wndClass));
wndClass.cbSize = sizeof(WNDCLASSEX);
wndClass.style = CS_HREDRAW | CS_VREDRAW;
wndClass.lpfnWndProc = WndProc;
wndClass.hInstance = hInstance;
wndClass.hCursor = LoadCursor(NULL, IDC_ARROW);
wndClass.hbrBackground = (HBRUSH)(COLOR_WINDOW + 1);
wndClass.lpszMenuName = NULL;
wndClass.lpszClassName = "DX11BookWindowClass";

if (!RegisterClassEx(&wndClass))
return -1;

RECT rc = { 0, 0, 1024, 768 };
AdjustWindowRect(&rc, WS_OVERLAPPEDWINDOW, FALSE);

HWND hwnd = CreateWindow("DX11BookWindowClass",
"DirectX 11 Demo",
WS_OVERLAPPEDWINDOW | WS_VSCROLL,
CW_USEDEFAULT,
CW_USEDEFAULT,
rc.right - rc.left,
rc.bottom - rc.top,
NULL, NULL, hInstance, NULL);

if (!hwnd)
return -1;

ShowWindow(hwnd, cmdShow);

//GameSpriteDemo demo;
//TriangleDemo demo;
D3DTextDemo demo;
bool result = demo.Initialize(hInstance, hwnd);

if (result == false)
return -1;

MSG msg = { 0 };

while (msg.message != WM_QUIT)
{
if (PeekMessage(&msg, 0, 0, 0, PM_REMOVE))
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
//Update and Draw
demo.Update(0.0f);
demo.Render();
}
demo.Shutdown();

return static_cast<int>(msg.wParam);
}

LRESULT CALLBACK WndProc(HWND hwnd, UINT message,
WPARAM wParam, LPARAM lParam)
{
PAINTSTRUCT paintStruct;
HDC hDC;

switch (message)
{
case WM_PAINT:
//_cprintf("");
hDC = BeginPaint(hwnd, &paintStruct);
EndPaint(hwnd, &paintStruct);
break;
case WM_SIZE:
//MessageBox(NULL, "Windows Changing", "Prompt", MB_OK);
//RECT rect;
//GetClientRect(hwnd, &rect);
//ValidateRect(hwnd,&rect);

break;

case WM_LBUTTONDOWN:
MessageBox(hwnd, "LBT Clicked", "PROMPT", MB_OK);
break;

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

return 0;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: