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

📄 main.cpp

📁 wince 3d tutorial, it has various examples
💻 CPP
字号:
#include "main.h" //We need the defines and prototypes from in.
#include "render.h"

//Some useful global handles
HINSTANCE hInst; //Will hold the current instance of the application.
HWND hWnd; // A handle to the window we will create.
HDC hDC;   // A handle to the device context of the window.


TCHAR szAppName[] = L"OpenGLES"; /*The application name and the window caption*/

//flag that tell us if we are using fog or not
bool useFog = false; 

/*This is the WinMain function. Here we will create the rendering window, initialize OpenGL ES, write the message loop, and, at the end, clean all and release all used resources*/
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPTSTR lpCmdLine,	int nCmdShow)
{
  MSG msg; //This is the message variable for the message loop
  WNDCLASS	wc; /*This structure will hold some init values for our window*/
  hInst = hInstance; // Initialization of our global variable
  bool done = false; 
	  
  /*This block of code is to ensure that the user only can run one
    instance of the application. First we search for a window with the 
    same class name, if found, we will focus it and return*/
  if(hWnd = FindWindow(szAppName, szAppName)) 
  {
    /* Set focus to foremost child window. The "| 0x01" is used to 
       bring any owned windows to the foreground and activate them.*/
    SetForegroundWindow((HWND)((ULONG) hWnd | 0x00000001));
    return 0;
  } 
		
  wc.style          = CS_HREDRAW | CS_VREDRAW; /*Will force a redraw 
  if the window is resized, both horizontally or vertically*/
  wc.lpfnWndProc    = (WNDPROC) WndProc; /*this is a function pointer,
  to tell the OS what function should call when a message needs to be 
  processed*/
  wc.cbClsExtra     = 0;
  wc.cbWndExtra     = 0;
  wc.hInstance      = hInstance;
  wc.hIcon          = LoadIcon(hInstance, NULL);//Load default icon
  wc.hCursor	      = 0; // Default cursor
  wc.hbrBackground  = 0; //We don't care about the background color
  wc.lpszMenuName	  = NULL; //This application does not have a menu
  wc.lpszClassName  = szAppName; /*Important, here we must fill the
   application class name (the class name is not the same than the 
   caption of the window, but many times they are the same)*/

  //Before creating the window, we must register this new window class
  if(!RegisterClass(&wc))
    return false;
	
  hWnd=CreateWindow(szAppName, //Class Name
                    szAppName, //Caption string
                    WS_VISIBLE,//Window style
                    CW_USEDEFAULT,CW_USEDEFAULT,//Starting [x,y] pos.
                    CW_USEDEFAULT, CW_USEDEFAULT, //Width and height
                    NULL, NULL, //Parent window and menu handle
                    hInst, NULL); /*Instance handle. Custom value to 
                    pass in the creation with the WM_CREATE message*/
	                  
  if(!hWnd) return false;
  if(!InitOGLES()) return false; //OpenGL ES Initialization
  
  //Bring the window to front, focus it and refresh it
  SetWindowText(hWnd, L"OpenGLES");
  ShowWindow(hWnd, nCmdShow); 
  UpdateWindow(hWnd);
 
  //Message Loop
  while(!done)
  {
    if(PeekMessage(&msg,NULL,0,0,PM_REMOVE))
    {
      if(msg.message==WM_QUIT)
        done = true;
	    else
      { 
	      TranslateMessage(&msg);
	      DispatchMessage(&msg);
	    }
    }
    else										
	    Render();
  }
  //Clean up all
  Clean();
  DestroyWindow(hWnd);
  UnregisterClass(szAppName, hInst);  
  return 0;
}
//----------------------------------------------------------------------------
LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
{
  switch (message) 
  {		
  case WM_PAINT:	
    ValidateRect(hWnd,NULL); //Needed to avoid new WM_PAINT messages
    return 0; 

  //This code will be executed when the user clicks over the touch screen  
  case WM_LBUTTONDOWN:
    useFog = !useFog;
    if(useFog)
      EnableFog();
    else
      DisableFog();
    return 0;

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

⌨️ 快捷键说明

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