windowstuff.c

来自「一个炸弹人游戏的源代码(win32 application)」· C语言 代码 · 共 56 行

C
56
字号
//Window handler
long WINAPI WindowMessageHandler (HWND hWnd, UINT wMessage, WPARAM wParam, LPARAM lParam)
{
  //Close window
  if (wMessage == WM_CLOSE) Done = -1;
  #include "bombermessages.c"
  //Other messages
  return DefWindowProc (hWnd, wMessage, wParam, lParam);
}


//Registers a new window class and creates an empty window.
void InitWindow ()
{
  //For initializing the window
  WNDCLASS      wndclass;
  RECT          ClientArea;

  //Register window class, as standard as can be
  wndclass.style = 0;
  wndclass.lpfnWndProc = (WNDPROC)WindowMessageHandler;
  wndclass.cbClsExtra = 0;
  wndclass.cbWndExtra = 0;
  wndclass.hInstance = InstanceHandle;
  wndclass.hIcon = LoadIcon(InstanceHandle, MAKEINTRESOURCE (IDI_MAINICON));
  wndclass.hCursor = LoadCursor(NULL, IDC_ARROW);
  wndclass.hbrBackground = GetStockObject (LTGRAY_BRUSH);
  wndclass.lpszMenuName = NULL;
  wndclass.lpszClassName = (LPSTR)"GAME";
  RegisterClass (&wndclass);

  //Resize window so it can accomodate a 256x256 bitmap
  ClientArea.left = 0;
  ClientArea.top = 0;
  ClientArea.right = 272;
  ClientArea.bottom = 272;
  AdjustWindowRect (&ClientArea, WS_CAPTION | WS_SYSMENU, FALSE);
  ClientArea.bottom -= ClientArea.top;
  ClientArea.right -= ClientArea.left;

  //Create empty window
  WindowHandle = 
  CreateWindow ((LPSTR)"GAME",                //Class name
                (LPSTR)"Bomberman",           //Window name
                WS_CAPTION | WS_SYSMENU,      //Window type
                CW_USEDEFAULT, 0,             //Don't specify location
                ClientArea.right,             //Specify size
                ClientArea.bottom,
                NULL,                         //No parent window
                NULL,                         //No menu
                InstanceHandle,               //It belongs to this program
                NULL);                        //No other data

  //Display the window
  ShowWindow (WindowHandle, SW_SHOWNORMAL);
}

⌨️ 快捷键说明

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