Advertisement
Caiwan

Untitled

Jun 16th, 2011
141
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.95 KB | None | 0 0
  1. FWcore::window::window(int _width, int _height, int _bpp, bool _fullscr){   // window creator class constructor
  2.     // todo: make allow to create more window, with custom callback proc (for develop)
  3.     width       = _width;
  4.     height      = _height;
  5.     fullscreen  =_fullscr;
  6.     bpp         =_bpp;
  7.    
  8.     for (int i=0; i<256; i++) keys[i]=false;    // reset keys
  9.  
  10.     WNDCLASS wc = {
  11.         CS_VREDRAW |CS_HREDRAW | CS_OWNDC,
  12.         mainloopCallbackProc,   // <- custoimize
  13.         0, 0,
  14.         GetModuleHandle(0),
  15.         static_cast<HICON>( LoadImage(GetModuleHandle( 0 ),
  16.             MAKEINTRESOURCE(IDI_ICON1),
  17.             IMAGE_ICON, 32, 32,
  18.             LR_DEFAULTSIZE)),
  19.         0,  0,  0,
  20.         "WINCLASS" };   // <- customize
  21.  
  22.     if( !RegisterClass(&wc) ){
  23.         MessageBox (HWND_DESKTOP, "Cannot register window class.", "Error", MB_OK | MB_ICONEXCLAMATION);
  24.         exit(1);
  25.     }
  26.  
  27.     DWORD windowframe = NULL;
  28.     if( fullscreen ) {
  29.         DEVMODE screenSettings;
  30.         ZeroMemory( &screenSettings, sizeof( screenSettings ) );
  31.         screenSettings.dmSize       = sizeof( screenSettings );
  32.         screenSettings.dmPelsWidth  = width;
  33.         screenSettings.dmPelsHeight = height;
  34.         screenSettings.dmBitsPerPel = bpp;
  35.         screenSettings.dmFields     = DM_BITSPERPEL | DM_PELSWIDTH | DM_PELSHEIGHT;
  36.  
  37.         long reso = ChangeDisplaySettings( &screenSettings, CDS_FULLSCREEN );
  38.         if( reso != DISP_CHANGE_SUCCESSFUL ) {
  39.             MessageBox( 0, "Could not initialize fullscreen window.", "Fatal error", MB_OK );
  40.             exit(1); // elvileg jónak kell elennie mindig.
  41.         }
  42.         windowframe = NULL;
  43.         ShowCursor( false );
  44.     } else {
  45.         windowframe = WS_OVERLAPPED | WS_CAPTION | WS_SYSMENU ;
  46.     }
  47.     hWnd = CreateWindowEx( NULL, "WINCLASS", MAIN_WINDOW_TITLE,
  48.         WS_POPUP | WS_VISIBLE | WS_CLIPSIBLINGS | WS_CLIPCHILDREN | windowframe,
  49.         0, 0, width, height, NULL, NULL, GetModuleHandle( 0 ), NULL );
  50.  
  51.     if( hWnd == NULL ){
  52.         MessageBox (HWND_DESKTOP, "cannot create window", "Error", MB_OK | MB_ICONEXCLAMATION);
  53.         exit(1);
  54.     }
  55.    
  56.     hDc = GetDC(hWnd);
  57.  
  58.     ShowWindow( hWnd, SW_SHOWDEFAULT );
  59.     UpdateWindow( hWnd );
  60. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement