HWND CreateMyWindow(LPSTR strWindowName, int width, int height, DWORD dwStyle, bool bFullScreen, HINSTANCE hInstance) { HWND hWnd; WNDCLASS wndclass; memset(&wndclass, 0, sizeof(WNDCLASS)); // Init the size of the class wndclass.style = CS_HREDRAW | CS_VREDRAW; // Regular drawing capabilities wndclass.lpfnWndProc = WinProc; // Pass our function pointer as the window procedure wndclass.hInstance = hInstance; // Assign our hInstance wndclass.hIcon = LoadIcon(NULL, IDI_APPLICATION); // General icon wndclass.hCursor = LoadCursor(NULL, IDC_ARROW); // An arrow for the cursor wndclass.hbrBackground = (HBRUSH) (COLOR_WINDOW+1); // A white window wndclass.lpszClassName = "GameTutorials"; // Assign the class name RegisterClass(&wndclass); // Register the class if(bFullScreen && !dwStyle) // Check if we wanted full screen mode { // Set the window properties for full screen mode dwStyle = WS_POPUP | WS_CLIPSIBLINGS | WS_CLIPCHILDREN; ChangeToFullScreen(); // Go to full screen ShowCursor(FALSE); // Hide the cursor } else if(!dwStyle) // Assign styles to the window depending on the choice dwStyle = WS_OVERLAPPEDWINDOW | WS_CLIPSIBLINGS | WS_CLIPCHILDREN; g_hInstance = hInstance; // Assign our global hInstance to the window's hInstance RECT rWindow; rWindow.left = 0; // Set Left Value To 0 rWindow.right = width; // Set Right Value To Requested Width rWindow.top = 0; // Set Top Value To 0 rWindow.bottom = height; // Set Bottom Value To Requested Height AdjustWindowRect( &rWindow, dwStyle, false); // Adjust Window To True Requested Size // Create the window hWnd = CreateWindow("GameTutorials", strWindowName, dwStyle, 0, 0, rWindow.right - rWindow.left, rWindow.bottom - rWindow.top, NULL, NULL, hInstance, NULL); if(!hWnd) return NULL; // If we could get a handle, return NULL ShowWindow(hWnd, SW_SHOWNORMAL); // Show the window UpdateWindow(hWnd); // Draw the window SetFocus(hWnd); // Sets Keyboard Focus To The Window return hWnd; }
void GameWindow::CreateGameWindow(LPSTR title) { m_sClass = title; WNDCLASS hwnd_class; memset(&hwnd_class, 0, sizeof(WNDCLASS)); hwnd_class.style = CS_HREDRAW | CS_VREDRAW; hwnd_class.lpfnWndProc = WinProc; hwnd_class.hInstance = m_hinstance; hwnd_class.hIcon = LoadIcon(NULL, IDI_APPLICATION); hwnd_class.hCursor = LoadCursor(NULL, IDC_ARROW); hwnd_class.hbrBackground = (HBRUSH) (COLOR_WINDOW + 1); hwnd_class.lpszClassName = m_sClass; RegisterClass(&hwnd_class); DWORD style; if (m_bFullScreen) { style = WS_POPUP | WS_CLIPSIBLINGS | WS_CLIPCHILDREN; ChangeToFullScreen(); ShowCursor(FALSE); } else { style = WS_OVERLAPPEDWINDOW | WS_CLIPSIBLINGS | WS_CLIPCHILDREN; ShowCursor(FALSE); } RECT boundaries; boundaries.left = 0; boundaries.right = SCREEN_WIDTH; boundaries.top = 0; boundaries.bottom = SCREEN_HEIGHT; AdjustWindowRect(&boundaries, style, false); m_hwnd = CreateWindow(m_sClass, m_sClass, style, 0, 0, SCREEN_WIDTH, SCREEN_HEIGHT, NULL, NULL, m_hinstance, NULL); if (m_hwnd) { ShowWindow(m_hwnd, SW_SHOWNORMAL); UpdateWindow(m_hwnd); SetFocus(m_hwnd); } }
// Change to Full-Screen BOOL chg_screen_mode(int mode) { HANDLE hProcess; if (mode == SCRN_FULL) { if (!CreateDirectDraw(hwndApp)) return FALSE; // Change to fullscreen fullmode = ChangeToFullScreen(); if (fullmode<0) { MessageBox(hwndApp, "Display Mode Change Error!", "Error", MB_ICONERROR); return FALSE; } // 全画面であれば、プロセスの優先度をあげる hProcess = GetCurrentProcess(); if (hProcess) { SetPriorityClass(hProcess, HIGH_PRIORITY_CLASS); } // mouse_cursor(FALSE); /* clear mouse cursor */ } else { // Window EndDirectDraw(); mouse_cursor(TRUE); /* mouse cursor on */ } mz_refresh_screen(REFSC_ALL); return TRUE; }
// Here is our "main()" equivalent in windows, WinMain(). int WINAPI WinMain (HINSTANCE hInstance, HINSTANCE hPrevInstance, PSTR szCmdLine, int iCmdShow) { HWND hwnd; // Create a variable that holds a handle to our window. MSG msg; // Create a variable to hold the message information WNDCLASSEX wndclass; // This variable will hold all the information about the window (The name, icon, cursor, color, menu bar...) DWORD dwStyle; wndclass.cbSize = sizeof (wndclass); // Here we set the size of the wndclass. wndclass.style = CS_HREDRAW | CS_VREDRAW; // The style we want is Verticle-Redraw and Horizontal-Redraw wndclass.lpfnWndProc = WndProc; // Here is where we assing our CALLBACK function. (The function to handle the messages) wndclass.cbClsExtra = 0; // We want zero extra bytes wndclass.cbWndExtra = 0; // Init this useless thing to 0 wndclass.hInstance = hInstance; // We assign our hInstance to our window. wndclass.hIcon = LoadIcon (NULL, IDI_WINLOGO); // Load a logo for our window wndclass.hCursor = LoadCursor (NULL, IDC_ARROW); // Load a arrow cursor for our window. // Set the background color for the window wndclass.hbrBackground = (HBRUSH) GetStockObject (BLACK_BRUSH); wndclass.lpszMenuName = NULL; // We pass NULL because we don't want a menu. wndclass.lpszClassName = "Full Screen App"; // Create a name that we identify this window class with. wndclass.hIconSm = LoadIcon (NULL, IDI_WINLOGO); // Create an icon for the top left of the window. RegisterClassEx (&wndclass); // We need to register the wndclass. if(MessageBox(NULL, "Click Yes to go to full screen (Recommended)", "Options", MB_YESNO | MB_ICONQUESTION) == IDNO) { dwStyle = WS_OVERLAPPEDWINDOW; // If we don't want full screen, open a simple window } else // If we chose YES { bFullScreen = TRUE; // Set our boolean to TRUE, we wanted fullscreen // This is the style that we need our window to have in order to be windowless fullscreen dwStyle = WS_POPUP | WS_CLIPSIBLINGS | WS_CLIPCHILDREN; ChangeToFullScreen(SCREEN_WIDTH, SCREEN_HEIGHT); // This changes our screen to full screen with our desired resolution } // Here we create the window returning our handle to the window. hwnd = CreateWindow ("Full Screen App", // window class name "Full Screen App", // window's Title dwStyle, // window style 0, // initial x position 0, // initial y position SCREEN_WIDTH, // initial x size - Our resolution width SCREEN_HEIGHT, // initial y size - Our resolution height NULL, // Pass NULL for the parent window NULL, // Pass NULL for a menu hInstance, // Pass in our hInstance NULL); // Pass NULL to the wndProc, we don't want to pass it any variables address's. ShowWindow (hwnd, iCmdShow); // Show the window UpdateWindow (hwnd); // Update our window and paint it to the screen // Start our main loop while (GetMessage (&msg, NULL, 0, 0)) // Create our message loop, Get the message, then translate it and handle it. { TranslateMessage (&msg); // Translate the message recieved from the user DispatchMessage (&msg); // Handle the message recieved from the user } UnregisterClass("Full Screen App",hInstance); // We need to unregister the wndclass. return msg.wParam ; // Quit the program }