⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 app.cpp

📁 direct3d游戏编程基础源码
💻 CPP
字号:
//-------------------------------------------------------------------------
// File: App.cpp
//
// Desc: Example code showing how to create a minimal Windows skeleton
//
// Last modified: 02. January 2001
//
// Copyright (c) 1999-2001 Wolfgang Engel wolf@direct3d.net
//--------------------------------------------------------------------------
#define STRICT
#include <windows.h>
#include <windowsx.h>
#include <tchar.h>
#include "App.h"
#include "resource.h"

//--------------------------------------------------------------------------
// global this pointer
//--------------------------------------------------------------------------
static CApp* g_pCApp = NULL;

//--------------------------------------------------------------------------
// Name: FAKEApp()
// Desc: Constructor
//--------------------------------------------------------------------------
CApp::CApp()
{
	g_pCApp = this;

	m_bActive = FALSE;

	m_strWindowTitle = _T("FAKE 4");
	m_dwWidth = 640;
	m_dwHeight = 480;
}

//-------------------------------------------------------------------------
// Name: WndProc()
// Desc: static msg handler which passes messages to the application class
//		 in the fake.cpp file	
//-------------------------------------------------------------------------
LRESULT CALLBACK WndProc (HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
{
	return g_pCApp->MsgProc (hWnd, uMsg, wParam, lParam);
}

//-------------------------------------------------------------------------
// Name: Create()
// Desc: static msg handler which passes messages to the application class
//		 in the fake.cpp file	
//-------------------------------------------------------------------------
HRESULT CApp::Create(HINSTANCE hThisInst)
{

	HWND hwnd; 
	
	/* Step 1: Define a window class. */ 
	WNDCLASS wcl; 
	wcl.hInstance = hThisInst; /* handle to this instance */ 
	wcl.lpszClassName = _T("Crusher") ; /* window class name */ 
	wcl.lpfnWndProc = WndProc; /* window function */ 
	wcl.style = 0; /* default style */ 
	wcl.hIcon = LoadIcon(hThisInst, MAKEINTRESOURCE(IDI_ICON1)); /* icon style */ 
	wcl.hCursor = LoadCursor( hThisInst, MAKEINTRESOURCE(IDC_HULLA)) ; /* cursor style */ 
	wcl.lpszMenuName = NULL; /* no menu */ 
	wcl.cbClsExtra = 0; /* no extra */ 
	wcl.cbWndExtra = 0; /* information needed */ 

	/* Make the window background white. */ 
	wcl.hbrBackground = (HBRUSH) GetStockObject(WHITE_BRUSH) ; 

	/* Step 2: Register the window class. */ 
	if(!RegisterClass (&wcl)) 
		return 0; 
	
	DWORD dwWindowStyle = WS_POPUP | WS_CAPTION | WS_VISIBLE | WS_SYSMENU;
	
	RECT rc;
	SetRect(&rc, 0, 0, m_dwWidth, m_dwHeight);
	AdjustWindowRect(&rc, dwWindowStyle, TRUE);

	/* Step 3: Now that a window class has been registered, 
				a window can be created. */ 
	hwnd = CreateWindow(_T("Crusher"), /* name of window class */ 
						m_strWindowTitle, /* title */ 
						dwWindowStyle, /* window style - normal */ 
						CW_USEDEFAULT, /* X coordinate - let Windows decide */ 
						CW_USEDEFAULT, /* y coordinate - let Windows decide */ 
						(rc.right - rc.left), /*  */ 
						(rc.bottom - rc.top), /*  */ 
						HWND_DESKTOP, /* no parent window */ 
						NULL, /* no menu */ 
						hThisInst, /* handle of this instance of the program */ 
						NULL /* no additional arguments */ 
						);

	/* Step 4: Display the window. */ 
//	ShowWindow(hwnd, nWinMode); // obsolete because of the use of WS_VISIBLE

 return S_OK;
}

//------------------------------------------------------------------------
// Name: MsgProc()
// Desc: Message handling function
//------------------------------------------------------------------------
LRESULT CApp::MsgProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
{
	switch (message) 
	{ 
        case WM_CLOSE:
		case WM_DESTROY: 
			PostQuitMessage(WM_QUIT); 
		  break; 
	}
  return DefWindowProc(hWnd, message, wParam, lParam); 
}

//------------------------------------------------------------------------
// Name: Render()
// Desc: Render the app
//------------------------------------------------------------------------
VOID CApp::Render()
{
	// do anything

}

//------------------------------------------------------------------------
// Name: Pause()
// Desc: Sets bActive
//------------------------------------------------------------------------
VOID CApp::Pause(BOOL bPause)
{
	m_bActive = bPause ? 0 : 1;
}

//------------------------------------------------------------------------
// Name: Run()
// Desc: Message Loop and render method
//------------------------------------------------------------------------
WPARAM CApp::Run()
{
	BOOL bGotMsg;
	MSG msg;


	PeekMessage (&msg, NULL, 0U, 0U, PM_REMOVE);

	/* Step 5: Create the message loop. */
	while (WM_QUIT != msg.message)
	{
		if( m_bActive)
			bGotMsg = PeekMessage (&msg, NULL, 0U, 0U, PM_REMOVE);
		else
			bGotMsg = GetMessage (&msg, NULL, 0U, 0U);

		if(bGotMsg)
		{
			TranslateMessage(&msg); /* allow use of keyboard */ 
			DispatchMessage(&msg); /* return control to Windows */ 
		}
		else
		{
			if(m_bActive)
				Render();
		}
	}

	return msg.wParam; 
}	

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -