Example #1
0
/**
 * Hiden Window function running in the thread.
 * @param lpParam  thread parameter
 * @return 1
 */
DWORD WINAPI windowThreadFunction(LPVOID lpParam) 
{
	WNDCLASSEX wndclassex;

	wndclassex.cbSize=sizeof(WNDCLASSEX);
	wndclassex.style=CS_NOCLOSE;
	wndclassex.lpfnWndProc=windowCallback;
	wndclassex.cbClsExtra=0;
	wndclassex.cbWndExtra=0;
	wndclassex.hInstance=hinstance;
	wndclassex.hIcon=NULL;
	wndclassex.hCursor=LoadCursor(0,(LPCWSTR)IDC_ARROW);
	wndclassex.hbrBackground=(HBRUSH)GetStockObject(WHITE_BRUSH);
	wndclassex.lpszMenuName=NULL;
	wndclassex.lpszClassName=L"Mouse 3D Window";
	wndclassex.hIconSm=LoadIcon(0,(LPCWSTR)IDI_APPLICATION);

	if(RegisterClassEx(&wndclassex)==0)
	{
		EnterCriticalSection(&StartSection);
		startResult=false;
		resultReady=true;
		LeaveCriticalSection(&StartSection);

		return 1;
	}

	WindowHandle=NULL;

	/* Creates hidden window which will be getting messages*/
	WindowHandle=CreateWindowEx(0,L"Mouse 3D Window",L"3D Mouse Window",WS_OVERLAPPEDWINDOW,100,100,100,100,0,0,hinstance,0);

	if(WindowHandle==0)
	{
		EnterCriticalSection(&StartSection);
		startResult=false;
		resultReady=true;
		LeaveCriticalSection(&StartSection);

		UnregisterClass(L"Mouse 3D Window",hinstance);
		return 1;
	}

	if(registerRawInput(WindowHandle)==false)
	{
		EnterCriticalSection(&StartSection);
		startResult=false;
		resultReady=true;
		LeaveCriticalSection(&StartSection);

		SendMessage(WindowHandle,WM_CLOSE,0,0);
	}
	else
	{
		EnterCriticalSection(&StartSection);
		startResult=true;
		resultReady=true;
		LeaveCriticalSection(&StartSection);
	}

	MSG msg;
	for(;;)
	{

		if(0!=GetMessage(&msg,NULL,0,0))
		{
			TranslateMessage(&msg);
			DispatchMessage(&msg);
		}
		if(msg.message==WM_QUIT)
		{
			break;
		}
	}

	if(UnregisterClass(L"Mouse 3D Window",hinstance)==0)
	{
		//error		
	}

	return 1;
}
Example #2
0
// WinMain
int WINAPI WinMain(HINSTANCE hinstance, HINSTANCE hprev, PSTR cmdline, int ishow)
{
    HWND hwnd = NULL;
    MSG msg = {0};
    WNDCLASSEX wndclassex = {0};

    // Init fields we care about
    wndclassex.cbSize = sizeof(WNDCLASSEX); // Always set to size of WNDCLASSEX
    wndclassex.style = CS_HREDRAW | CS_VREDRAW;
    wndclassex.lpfnWndProc = WinProc;
    wndclassex.hInstance = hinstance;
    wndclassex.lpszClassName = kClassName;
    wndclassex.hCursor = (HCURSOR)LoadImage(NULL, MAKEINTRESOURCE(IDC_ARROW),
                                            IMAGE_CURSOR, 0, 0, LR_SHARED);

    RegisterClassEx(&wndclassex); // Register the WNDCLASSEX

    RECT rect = { 0, 0, kWinWid, kWinHgt }; // Desired window client rect

    DWORD winStyleEx = WS_EX_CLIENTEDGE;
    DWORD winStyle = WS_OVERLAPPED | WS_CAPTION | WS_SYSMENU | WS_THICKFRAME |
                     WS_CLIPCHILDREN | WS_CLIPSIBLINGS;

    // Adjust window rect so it gives us our desired client rect when we
    // create the window
    AdjustWindowRectEx(&rect, winStyle, false, winStyleEx);

    // Create the window
    hwnd = CreateWindowEx(winStyleEx, // Window extended style
                          kClassName,
                          "www.GameTutorials.com -- Ray and AABB Collision",
                          winStyle, // Window style
                          CW_USEDEFAULT,
                          CW_USEDEFAULT,
                          rect.right - rect.left, // Window width
                          rect.bottom - rect.top, // Window height
                          NULL,
                          NULL,
                          hinstance,
                          NULL);

    // Init our global 3D object
    if(g3D->init(hwnd) == false)
        return EXIT_FAILURE; // There's been an error, lets get out of this joint

    // Get the client rect and make sure our client is the size we want
    GetClientRect(hwnd, &rect);
    assert(rect.right == kWinWid && rect.bottom == kWinHgt);

    // We set up our projection matrix once because it will never change
    g3D->setProjMatrix(DEG2RAD(60), (float)rect.right / (float)rect.bottom, 1.0f, 8192.0f);

    // We set our view matrix once because it will never change
    g3D->setViewMatrix(CPos(0,1.5f,-3.0f), CPos(0,0,0));

    ShowWindow(hwnd, ishow);
    UpdateWindow(hwnd);

    // While the app is running
    while(1)
    {
        // If the OS has messages for us, handle them
        if(PeekMessage(&msg,NULL,0,0,PM_REMOVE))
        {
            if(msg.message == WM_QUIT)
                break;

            TranslateMessage(&msg);
            DispatchMessage(&msg);
        }
        else if(LockFrameRate()) // If it is time to draw, do so
        {
            g3D->begin(); // Begin drawing
            g3D->clear(); // Clear the screen

            // Draw our plane in GREEN if our ray intersects with it
            if(gAABB.intersect(gRay))
                gAABB.render(D3DCOLOR_ARGB(255,25,225,25));
            else // Otherwise draw it in RED
                gAABB.render(D3DCOLOR_ARGB(255,225,25,25));

            // Draw our ray
            gRay.render(D3DCOLOR_ARGB(255,225,225,0));

            g3D->end(); // Finish drawing
        }
        else
            Sleep(1); // Give the OS a little bit of time to process other things

    } // end of while(1)

    g3D->deinit(); // Free up CD3DObj
    UnregisterClass(kClassName,hinstance); // Free up WNDCLASSEX
    return EXIT_SUCCESS; // Application was a success
}
Example #3
0
void ShutDown()
{
	Renderer::Shutdown();
	delete renderset;
	UnregisterClass(L"DirectXApplication", application);
}
Example #4
0
// Our Win32 main
int WINAPI WinMain(HINSTANCE hinstance, HINSTANCE hprev, PSTR cmdline, int ishow)
{
    HWND hwnd = NULL; // Handle to our window
    MSG msg = {0};
    WNDCLASSEX wndclassex = {0};

    // Init fields we care about
    wndclassex.cbSize = sizeof(WNDCLASSEX); // Always set to size of WNDCLASSEX
    wndclassex.style = CS_HREDRAW | CS_VREDRAW;
    wndclassex.lpfnWndProc = WinProc;
    wndclassex.hInstance = hinstance;
    wndclassex.lpszClassName = kClassName;
    wndclassex.hCursor = (HCURSOR)LoadImage(NULL, MAKEINTRESOURCE(IDC_ARROW),
                                            IMAGE_CURSOR, 0, 0, LR_SHARED);

    RegisterClassEx(&wndclassex); // Register the WNDCLASSEX

    RECT rect = { 0, 0, kWinWid, kWinHgt }; // Desired window client rect

    DWORD winStyleEx = WS_EX_CLIENTEDGE;
    DWORD winStyle = WS_OVERLAPPED | WS_CAPTION | WS_SYSMENU | WS_THICKFRAME;

    // Adjust window rect so it gives us our desired client rect when we
    // create the window
    AdjustWindowRectEx(&rect, winStyle, false, winStyleEx);

    // Create the window
    hwnd = CreateWindowEx(winStyleEx,
                          kClassName,
                          "www.GameTutorials.com -- Render Targets",
                          winStyle,
                          CW_USEDEFAULT,
                          CW_USEDEFAULT,
                          rect.right - rect.left,
                          rect.bottom - rect.top,
                          NULL,
                          NULL,
                          hinstance,
                          NULL);

    // Get the client rect and make sure our client is the size we want
    GetClientRect(hwnd, &rect);
    assert(rect.right == kWinWid && rect.bottom == kWinHgt);



    // Init our global 3D object
    if(g3D->init(hwnd) == false)
        return EXIT_FAILURE; // There's been an error, lets get out of this joint

    if(!gBlurTexture1.createRenderTexture(256, 256, D3DFMT_A8R8G8B8))
        return false; // Couldn't create a off screen texture to render to

    if(!gBlurTexture2.createRenderTexture(256, 256, D3DFMT_A8R8G8B8))
        return false; // Couldn't create a off screen texture to render to

    if(!gDiffTex.load("texture.jpg"))
        return false;

    if(!gRenderTarget.init(256, 256, D3DFMT_A8R8G8B8, D3DFMT_D24S8))
        return false; // Couldn't create a render texture... Does your video card support this?

    Make3x3GuassianDistribution();

    // Set up our projection matrix once because it will not change
    g3D->setProjMatrix(DEG2RAD(60), 1.0f, 2048.0f);

    // We set up our view matrix once because it will never change
    g3D->setViewMatrix(kEyePos, CPos(0.0f, 0.0f, 0.0f));

    g3D->mShader->SetFloatArray("gEyePos", &kEyePos.x, 3); // Set the camera's eye position
    g3D->mShader->SetFloatArray("gBlurWeights", gBlurWeights, 9); // Gaussian blur weights

    // Show and update the window
    ShowWindow(hwnd, ishow);
    UpdateWindow(hwnd);

    while(1) // While the app is alive
    {
        if(PeekMessage(&msg,NULL,0,0,PM_REMOVE)) // If the OS has a message for us
        {
            if(msg.message == WM_QUIT)
                break;

            TranslateMessage(&msg);
            DispatchMessage(&msg);
        }
        else if(LockFrameRate()) // Else, if it's time to draw
        {
            // Render the off screen texture (created directly above) to another
            // off screen texture using a Gaussian blur
            if(gToggle)
                Combined();
            else
                RenderSobelFilter();

            // Render the two textures to the screen
            RenderScene();
        }
        else
            Sleep(1); // Otherwise, give the OS some time to process other programs

    } // end of while(1)

    g3D->deinit(); // Free up the D3D object
    UnregisterClass(kClassName,hinstance); // Free up WNDCLASSEX
    return EXIT_SUCCESS; // Application was a success
}
Example #5
0
INT WINAPI wWinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPWSTR szCmdLine, int iCmdShow)
{
	WNDCLASSEX winClass ;

	winClass.lpszClassName = "Teapot";
	winClass.cbSize        = sizeof(WNDCLASSEX);
	winClass.style         = CS_HREDRAW | CS_VREDRAW;
	winClass.lpfnWndProc   = MsgProc;
	winClass.hInstance     = hInstance;
	winClass.hIcon	       = NULL ;
	winClass.hIconSm	   = NULL ;
	winClass.hCursor       = LoadCursor(NULL, IDC_ARROW) ; // to avoid busy cursor
	winClass.hbrBackground = NULL ;
	winClass.lpszMenuName  = NULL ;
	winClass.cbClsExtra    = 0;
	winClass.cbWndExtra    = 0;

	RegisterClassEx (&winClass) ;  

	HWND hWnd = CreateWindowEx(NULL,  
		winClass.lpszClassName,		// window class name
		"Teapot",					// window caption
		WS_OVERLAPPEDWINDOW, 		// window style
		32,							// initial x position
		32,							// initial y position
		600,						// initial window width
		600,						// initial window height
		NULL,						// parent window handle
		NULL,						// window menu handle
		hInstance,					// program instance handle
		NULL) ;						// creation parameters

	// Create window failed
	if(hWnd == NULL)
	{
		MessageBoxA(hWnd, "Create Window failed!", "Error", 0) ;
		return -1 ;
	}

	// Initialize Direct3D
	if( SUCCEEDED(InitD3D(hWnd)))
	{ 
		InitVertexBuffer() ;

		// Show the window
		ShowWindow( hWnd, SW_SHOWDEFAULT );
		UpdateWindow( hWnd );

		// Enter the message loop
		MSG    msg ; 
		ZeroMemory( &msg, sizeof(msg) );
		PeekMessage( &msg, NULL, 0U, 0U, PM_NOREMOVE );

		// Get last time
		static DWORD lastTime = timeGetTime();

		while (msg.message != WM_QUIT)  
		{
			if( PeekMessage(&msg, NULL, 0U, 0U, PM_REMOVE) != 0)
			{
				TranslateMessage (&msg) ;
				DispatchMessage (&msg) ;
			}
			else // Render the game if there is no message to process
			{
				// Get current time
				DWORD currTime  = timeGetTime();

				// Calculate time elapsed
				float timeDelta = (currTime - lastTime)*0.001f;

				// Render
				Render() ;

				// Update last time to current time for next loop
				lastTime = currTime;
			}
		}
	}

	UnregisterClass(winClass.lpszClassName, hInstance) ;
	return 0;
}
//*************************************************************************************************************
int main(int argc, char* argv[])
{
	ReadResolutionFile();

	LARGE_INTEGER qwTicksPerSec = { 0, 0 };
	LARGE_INTEGER qwTime;
	LONGLONG tickspersec;
	double last, current;
	double delta, accum = 0;

	WNDCLASSEX wc =
	{
		sizeof(WNDCLASSEX),
		CS_OWNDC,
		(WNDPROC)WndProc,
		0L,
		0L,
		GetModuleHandle(NULL),
		NULL,
		LoadCursor(0, IDC_ARROW),
		NULL, NULL, "TestClass", NULL
	};

	RegisterClassEx(&wc);
	SystemParametersInfo(SPI_GETWORKAREA, 0, &workarea, 0);

	RECT rect = { 0, 0, screenwidth, screenheight };
	DWORD style = WS_CLIPCHILDREN|WS_CLIPSIBLINGS;

	// windowed mode
	style |= WS_SYSMENU|WS_BORDER|WS_CAPTION;
	Adjust(rect, screenwidth, screenheight, style, 0);

	hwnd = CreateWindowA("TestClass", TITLE, style,
		rect.left, rect.top, rect.right - rect.left, rect.bottom - rect.top,
		NULL, NULL, wc.hInstance, NULL);

	if( !hwnd )
	{
		MYERROR("Could not create window");
		goto _end;
	}

	if( FAILED(InitDirect3D(hwnd)) )
	{
		MYERROR("Failed to initialize Direct3D");
		goto _end;
	}
	
	if( FAILED(InitScene()) )
	{
		MYERROR("Failed to initialize scene");
		goto _end;
	}

	ShowWindow(hwnd, SW_SHOWDEFAULT);
	UpdateWindow(hwnd);

	MSG msg;
	ZeroMemory(&msg, sizeof(msg));

	POINT p;
	GetCursorPos(&p);
	ScreenToClient(hwnd, &p);

	// timer
	QueryPerformanceFrequency(&qwTicksPerSec);
	tickspersec = qwTicksPerSec.QuadPart;

	QueryPerformanceCounter(&qwTime);
	last = (qwTime.QuadPart % tickspersec) / (double)tickspersec;

	while( msg.message != WM_QUIT )
	{
		QueryPerformanceCounter(&qwTime);

		current = (qwTime.QuadPart % tickspersec) / (double)tickspersec;

		if (current < last)
			delta = ((1.0 + current) - last);
		else
			delta = (current - last);

		last = current;
		accum += delta;

		mousedx = mousedy = 0;

		while( accum > 0.0333f )
		{
			accum -= 0.0333f;

			while( PeekMessage(&msg, NULL, 0U, 0U, PM_REMOVE) )
			{
				TranslateMessage(&msg);
				DispatchMessage(&msg);
			}

			Update(0.0333f);
		}

		if( msg.message != WM_QUIT )
			Render((float)accum / 0.0333f, (float)delta);
	}

_end:
	UninitScene();

	if( device )
	{
		ULONG rc = device->Release();

		if( rc > 0 )
			MYERROR("You forgot to release something");
	}

	if( direct3d )
		direct3d->Release();

	UnregisterClass("TestClass", wc.hInstance);
	_CrtDumpMemoryLeaks();

#ifdef _DEBUG
	system("pause");
#endif

	return 0;
}
Example #7
0
File: Main.cpp Project: m1h4/Pong
INT WINAPI WinMain(HINSTANCE hInstance,HINSTANCE hPrevInstance,LPSTR cmdLine,INT cmdShow)
{
    if(!lstrcmpA(cmdLine,"/server"))
        return WinServer(hInstance);

    TCHAR application[512];
    LoadString(GetModuleHandle(NULL),IDS_APPLICATION,application,sizeof(application)/sizeof(TCHAR));

    WNDCLASSEX wcex;
    ZeroMemory(&wcex,sizeof(wcex));
    wcex.cbSize			= sizeof(WNDCLASSEX);
    wcex.style			= CS_CLASSDC|CS_DBLCLKS;
    wcex.lpfnWndProc	= WinProcedure;
    wcex.hInstance		= GetModuleHandle(NULL);
    wcex.hIcon			= LoadIcon(GetModuleHandle(NULL),MAKEINTRESOURCE(IDI_MAIN));
    wcex.hIconSm		= LoadIcon(GetModuleHandle(NULL),MAKEINTRESOURCE(IDI_MAIN));
    wcex.hCursor		= LoadCursor(NULL,IDC_ARROW);
    wcex.lpszClassName	= application;

    if(!RegisterClassEx(&wcex))
    {
        TRACE(L"Error: Failed to register window class.\n");
        return 1;
    }

    HACCEL hAccelerators = LoadAccelerators(GetModuleHandle(NULL),MAKEINTRESOURCE(IDA_MAIN));
    if(!hAccelerators)
    {
        TRACE(L"Error: Failed to load accelerators.\n");
        return 1;
    }

    //HMENU hMenu = LoadMenu(GetModuleHandle(NULL),MAKEINTRESOURCE(IDM_MAIN));
    //if(!hMenu)
    //{
    //	TRACE(L"Error: Failed to load menu.\n");
    //	return 1;
    //}

    HWND hWnd = CreateWindowEx(NULL,application,application,WS_OVERLAPPEDWINDOW|WS_VISIBLE|WS_CLIPCHILDREN,CW_USEDEFAULT,CW_USEDEFAULT,MAIN_WINDOW_WIDTH,MAIN_WINDOW_HEIGHT,GetDesktopWindow(),/*hMenu*/ NULL,GetModuleHandle(NULL),NULL);
    if(!hWnd)
    {
        TRACE(L"Error: Failed to create window.\n");
        return 1;
    }

    MSG msg;
    ZeroMemory(&msg,sizeof(msg));

    while(GetMessage(&msg,NULL,NULL,NULL))
    {
        if(!TranslateAccelerator(hWnd,hAccelerators,&msg))
        {
            TranslateMessage(&msg);
            DispatchMessage(&msg);
        }
    }

    DestroyWindow(hWnd);
    UnregisterClass(application,GetModuleHandle(NULL));

    return (INT)msg.wParam;
}
// エントリポイント
int WINAPI _tWinMain( HINSTANCE hInst, HINSTANCE, LPTSTR, int )
{
	LARGE_INTEGER			nNowTime, nLastTime;		// 現在とひとつ前の時刻
	LARGE_INTEGER			nTimeFreq;					// 時間単位

    // 画面サイズ
    g_nClientWidth  = VIEW_WIDTH;						// 幅
    g_nClientHeight = VIEW_HEIGHT;						// 高さ

	// Register the window class
    WNDCLASSEX wc = { sizeof( WNDCLASSEX ), CS_CLASSDC, MsgProc, 0L, 0L,
                      GetModuleHandle( NULL ), NULL, NULL, NULL, NULL,
                      _T( "D3D Sample" ), NULL };
    RegisterClassEx( &wc );

	RECT rcRect;
	SetRect( &rcRect, 0, 0, g_nClientWidth, g_nClientHeight );
	AdjustWindowRect( &rcRect, WS_OVERLAPPEDWINDOW, FALSE );
    g_hWnd = CreateWindow( _T( "D3D Sample" ), _T( "3DCheckHit_3_2" ),
						   WS_OVERLAPPEDWINDOW, 100, 20, rcRect.right - rcRect.left, rcRect.bottom - rcRect.top,
						   GetDesktopWindow(), NULL, wc.hInstance, NULL );

    // Initialize Direct3D
    if( SUCCEEDED( InitD3D() ) && SUCCEEDED( MakeShaders() ) )
    {
        // Create the shaders
        if( SUCCEEDED( InitDrawModes() ) )
        {
			if ( SUCCEEDED( InitGeometry() ) ) {					// ジオメトリ作成
				
				InitPlayer();										// プレイヤーの初期化
				// Show the window
				ShowWindow( g_hWnd, SW_SHOWDEFAULT );
				UpdateWindow( g_hWnd );
				
				QueryPerformanceFrequency( &nTimeFreq );			// 時間単位
				QueryPerformanceCounter( &nLastTime );				// 1フレーム前時刻初期化

				// Enter the message loop
				MSG msg;
				ZeroMemory( &msg, sizeof( msg ) );
				while( msg.message != WM_QUIT )
				{
					MovePlayer();
					Render();
					do {
						if( PeekMessage( &msg, NULL, 0U, 0U, PM_REMOVE ) )
						{
							TranslateMessage( &msg );
							DispatchMessage( &msg );
						}
						QueryPerformanceCounter( &nNowTime );
					} while( ( ( nNowTime.QuadPart - nLastTime.QuadPart ) < ( nTimeFreq.QuadPart / 90 ) ) &&
							 ( msg.message != WM_QUIT ) );
					while( ( ( nNowTime.QuadPart - nLastTime.QuadPart ) < ( nTimeFreq.QuadPart / 60 ) ) &&
						   ( msg.message != WM_QUIT ) )
					{
						QueryPerformanceCounter( &nNowTime );
					}
					nLastTime = nNowTime;
					g_pSwapChain->Present( 0, 0 );					// 表示
				}
			}
        }
    }

    // Clean up everything and exit the app
    Cleanup();
    UnregisterClass( _T( "D3D Sample" ), wc.hInstance );
    return 0;
}
Example #9
0
void GFXGLDevice::enumerateAdapters( Vector<GFXAdapter*> &adapterList )
{
//   GL_ERROR_CHECK();
   WNDCLASS windowclass;
   dMemset( &windowclass, 0, sizeof( WNDCLASS ) );

   windowclass.lpszClassName = L"GFX-OpenGL";
   windowclass.style         = CS_OWNDC;
   windowclass.lpfnWndProc   = DefWindowProc;
   windowclass.hInstance     = winState.appInstance;

   if( !RegisterClass( &windowclass ) )
      AssertFatal( false, "Failed to register the window class for the GL test window." );

   // Now create a window
   HWND hwnd = CreateWindow( L"GFX-OpenGL", L"", WS_POPUP, 0, 0, 640, 480, 
                             NULL, NULL, winState.appInstance, NULL );
   AssertFatal( hwnd != NULL, "Failed to create the window for the GL test window." );

   // Create a device context
   HDC tempDC = GetDC( hwnd );
   AssertFatal( tempDC != NULL, "Failed to create device context" );

   // Create pixel format descriptor...
   PIXELFORMATDESCRIPTOR pfd;
   CreatePixelFormat( &pfd, 32, 0, 0, false );
   if( !SetPixelFormat( tempDC, ChoosePixelFormat( tempDC, &pfd ), &pfd ) )
      AssertFatal( false, "I don't know who's responcible for this, but I want caught..." );

   // Create a rendering context!
   HGLRC tempGLRC = wglCreateContext( tempDC );
   if( !wglMakeCurrent( tempDC, tempGLRC ) )
      AssertFatal( false, "I want them caught and killed." );

   // Add the GL renderer
   loadGLCore();
   loadGLExtensions(tempDC);

   GFXAdapter *toAdd = new GFXAdapter;
   toAdd->mIndex = 0;

   const char* renderer = (const char*) glGetString( GL_RENDERER );
   AssertFatal( renderer != NULL, "GL_RENDERER returned NULL!" );

   if (renderer)
   {
      dStrcpy(toAdd->mName, renderer);
      dStrncat(toAdd->mName, " OpenGL", GFXAdapter::MaxAdapterNameLen);
   }
   else
      dStrcpy(toAdd->mName, "OpenGL");

   toAdd->mType = OpenGL;
   toAdd->mShaderModel = 0.f;
   toAdd->mCreateDeviceInstanceDelegate = mCreateDeviceInstance;

   // Enumerate all available resolutions:
   DEVMODE devMode;
   U32 modeNum = 0;
   U32 stillGoing = true;
   while ( stillGoing )
   {
      dMemset( &devMode, 0, sizeof( devMode ) );
      devMode.dmSize = sizeof( devMode );

      stillGoing = EnumDisplaySettings( NULL, modeNum++, &devMode );

      if (( devMode.dmPelsWidth >= 480) && (devMode.dmPelsHeight >= 360 )
         && ( devMode.dmBitsPerPel == 16 || devMode.dmBitsPerPel == 32 )) 
      {
         GFXVideoMode vmAdd;

         vmAdd.bitDepth     = devMode.dmBitsPerPel;
         vmAdd.fullScreen   = true;
         vmAdd.refreshRate  = devMode.dmDisplayFrequency;
         vmAdd.resolution.x = devMode.dmPelsWidth;
         vmAdd.resolution.y = devMode.dmPelsHeight;

         // Only add this resolution if it is not already in the list:
         bool alreadyInList = false;
         for (Vector<GFXVideoMode>::iterator i = toAdd->mAvailableModes.begin(); i != toAdd->mAvailableModes.end(); i++)
         {
            if (vmAdd == *i)
            {
               alreadyInList = true;
               break;
            }
         }

         if(alreadyInList)
            continue;

         toAdd->mAvailableModes.push_back( vmAdd );
      }
   }

   // Add to the list of available adapters.
   adapterList.push_back(toAdd);

   // Cleanup our window
   wglMakeCurrent(NULL, NULL);
   wglDeleteContext(tempGLRC);
   ReleaseDC(hwnd, tempDC);
   DestroyWindow(hwnd);
   UnregisterClass(L"GFX-OpenGL", winState.appInstance);
}
Example #10
0
void destroyWinClass(HINSTANCE hInstance)
{
	//注销窗口类
	UnregisterClass("ClassName", hInstance);
}
Example #11
0
void uninitOSWindow()
{
    procs->clear(true);
    si->hashdelete(procs);
    UnregisterClass("MT3OSWindow",instance);
}
Example #12
0
void endPlugin(HINSTANCE h_instance)
{
    DestroyWindow(hPluginWnd);
    SendMessage(GetBBWnd(), BB_UNREGISTERMESSAGE, (WPARAM)hPluginWnd, (LPARAM)bb_messages);
    UnregisterClass(pluginInfo(APPNAME), h_instance);
}
Example #13
0
////////////////////////////////////////////////////////////////////////////////////////////////////
// Application entry point
int APIENTRY _tWinMain ( HINSTANCE hInstance ,
                         HINSTANCE hPrevInstance ,
                         LPTSTR    lpCmdLine ,
                         int       nCmdShow )
{
    UNREFERENCED_PARAMETER ( hPrevInstance ) ;
    UNREFERENCED_PARAMETER ( lpCmdLine ) ;
    UNREFERENCED_PARAMETER ( nCmdShow ) ;

    g_hInst = hInstance ;

    // Ensure that only one copy of our application is running.
    HANDLE mutex = CreateMutex ( NULL , FALSE , INSTANCE_MUTEX ) ;
    DWORD dwRetVal = WaitForSingleObject ( mutex , 0 ) ;
    if ( dwRetVal == WAIT_TIMEOUT )
    {
        ShowCustomError ( IDS_CAPTION_ERROR , IDS_ERROR_ALREADY_RUNNING ) ;
        return 1 ;
    }

    // Create a fake window to listen to events.
    WNDCLASSEX wclx =  { 0 } ;
    wclx.cbSize         = sizeof( wclx ) ;
    wclx.lpfnWndProc    = &WindowProc ;
    wclx.hInstance      = hInstance ;
    wclx.lpszClassName  = WINDOWCLASS_NAME ;
    RegisterClassEx ( &wclx ) ;
    g_hWnd = CreateWindow ( WINDOWCLASS_NAME ,
                            0 ,
                            0 ,
                            0 ,
                            0 ,
                            0 ,
                            0 ,
                            HWND_MESSAGE ,
                            0 ,
                            g_hInst ,
                            0 ) ;

    // Initialize array of handlers. Note to app extenders: register your hotkey handlers here.
    g_pHandlers [ 0 ] = new CLayoutSwitcher   ( ) ;
    g_pHandlers [ 1 ] = new CShellExecutor    ( ) ;
    g_pHandlers [ 2 ] = new CClipboardHistory ( ) ;
    g_pHandlers [ 3 ] = new CDummyTextGenerator ( ) ;
    g_pHandlers [ 4 ] = new CZOrderChanger ( ) ;

    for ( BYTE index = 0 ; index < NUM_LIVEKEYS_HANDLERS ; index++ )
    {
        BOOL bInitialized = g_pHandlers [ index ]->Initialize ( 
            index , g_hWnd , g_hInst , RegisterHandlerHotkey ) ;
        if ( !bInitialized )
        {
            ShowCustomError ( IDS_CAPTION_ERROR , IDS_ERROR_HANDLER_NOT_INITIALIZED ) ;
            delete g_pHandlers [ index ] ;
            g_pHandlers [ index ] = NULL ;
        }
    }

    // Set hook on all keyboard events in order to implement hotkeys functionality.
    g_hHook = SetWindowsHookEx ( WH_KEYBOARD_LL , 
                                 LowLevelHookProc , 
                                 GetModuleHandle ( NULL ) , 
                                 0 ) ;
    if ( NULL == g_hHook )
    {
        ShowCustomError ( IDS_CAPTION_ERROR , IDS_ERROR_HOOK_FAILED ) ;
        return 1 ;
    }

    // And finally start message handling loop.
    MSG msg ;
    while ( GetMessage ( &msg , NULL , 0 , 0 ) )
    {
        TranslateMessage ( &msg ) ;
        DispatchMessage ( &msg ) ;
    }

    // Some cleanup here
    for ( BYTE index = 0 ; index < NUM_LIVEKEYS_HANDLERS ; index++ )
        if ( NULL != g_pHandlers [ index ] )
        {
            g_pHandlers [ index ]->ShutDown ( UnregisterHandlerHotkey ) ;
            delete g_pHandlers [ index ] ;
        }

    UnregisterClass ( WINDOWCLASS_NAME , hInstance ) ;
    DestroyWindow ( g_hWnd ) ;
    UnhookWindowsHookEx ( g_hHook ) ;
 
    return 0 ;
}
Example #14
0
void GLimp_Shutdown( void )
{
	//Knightmare- added Vic's hardware gamma ramp
	if ( !r_ignorehwgamma->value )
	{
		if( qwglSetDeviceGammaRamp3DFX )
		{
			WORD newramp[3*256];
			int j;

			for( j = 0; j < 256; j++ )
			{
				newramp[j+0] = original_ramp[0][j];
				newramp[j+256] = original_ramp[1][j];
				newramp[j+512] = original_ramp[2][j];
			}

			qwglSetDeviceGammaRamp3DFX ( glw_state.hDC, newramp );
		}
		else
		{
			SetDeviceGammaRamp (glw_state.hDC, original_ramp);
		}
	}
	//end Knightmare

	if ( qwglMakeCurrent && !qwglMakeCurrent( NULL, NULL ) )
		VID_Printf( PRINT_ALL, "ref_gl::R_Shutdown() - wglMakeCurrent failed\n");
	if ( glw_state.hGLRC )
	{
		if (  qwglDeleteContext && !qwglDeleteContext( glw_state.hGLRC ) )
			VID_Printf( PRINT_ALL, "ref_gl::R_Shutdown() - wglDeleteContext failed\n");
		glw_state.hGLRC = NULL;
	}
	if (glw_state.hDC)
	{
		if ( !ReleaseDC( glw_state.hWnd, glw_state.hDC ) )
			VID_Printf( PRINT_ALL, "ref_gl::R_Shutdown() - ReleaseDC failed\n" );
		glw_state.hDC   = NULL;
	}
	if (glw_state.hWnd)
	{	//Knightmare- remove leftover button on taskbar
		ShowWindow (glw_state.hWnd, SW_HIDE);
		//end Knightmare
		DestroyWindow (	glw_state.hWnd );
		glw_state.hWnd = NULL;
	}

	if ( glw_state.log_fp )
	{
		fclose( glw_state.log_fp );
		glw_state.log_fp = 0;
	}

	UnregisterClass (WINDOW_CLASS_NAME, glw_state.hInstance);

	if ( gl_state.fullscreen )
	{
		ChangeDisplaySettings( 0, 0 );
		gl_state.fullscreen = false;
	}
}
Example #15
0
INT WINAPI wWinMain( HINSTANCE hInst, HINSTANCE, LPWSTR, INT ) // 프로그램 진입점
{
	WNDCLASSEX wc =                                                           // 윈도우 클래스 정의,등록
	{
		sizeof( WNDCLASSEX ), CS_CLASSDC, MsgProc, 0L, 0L,
		GetModuleHandle( NULL ), NULL, NULL, NULL, NULL,
		"ProG", NULL
	};
	RegisterClassEx( &wc );

	HWND hWnd = CreateWindow( "ProG", "ProG",  // 윈도우 생성
		WS_BORDER | WS_SYSMENU, 0, 0, 1680, 1030,     ////   좌표 변수 처리
		NULL, NULL, wc.hInstance, NULL );

	CDevice::GetInstance()->Init(hWnd, 1680, 1030);

	if( SUCCEEDED( InitD3D( hWnd ) ) ) // Direct3D초기화
	{
		ShowWindow( hWnd, SW_SHOWDEFAULT ); // 윈도우 출력
		UpdateWindow( hWnd );

		MSG msg;
		while(true) // 메시지 루프
		{
			if(PeekMessage(&msg, NULL,NULL, NULL, PM_REMOVE))
			{
				TranslateMessage( &msg );
				DispatchMessage( &msg );
			}
			else
			{
				first_time = GetTickCount();
				if(g_Load.Logo_Start == true)
				{
					Loading();
					if(g_Load.Out_Exit() == true)
					{
						PostQuitMessage( 0 );
					}

				}
				if(g_Load.Logo_Start == false)
				{
				Update(); 
				Destroy();
				Active();
				Collision();
				Create();
				Stage1();
				EL();
				World_Time = World_Time + tick;
				
				}
				Render();
				tick = (float)(GetTickCount() - first_time)/(float)1000;
			}
			if(msg.message == WM_QUIT)
			{
				break;
			}

		}
	}

	Cleanup();

	UnregisterClass( "ProG", wc.hInstance );  // 등록된 클래스 소거

	return 0;
}
Example #16
0
/*-------------------------------------------
	アプリケーションの終了処理
--------------------------------------------*/
bool CleanupApp(void)
{
	// ウインドウ クラスの登録解除
	UnregisterClass(g_szWndClass, g_hInstance);
	return true;
}
Example #17
0
// Program Entry (WinMain)
int WINAPI WinMain (HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow)
{
	Application			application;									// Application Structure
	GL_Window			window;											// Window Structure
	Keys				keys;											// Key Structure
	BOOL				isMessagePumpActive;							// Message Pump Active?
	MSG					msg;											// Window Message Structure
	DWORD				tickCount;										// Used For The Tick Counter

	// Fill Out Application Data
	application.className = "OpenGL";									// Application Class Name
	application.hInstance = hInstance;									// Application Instance

	// Fill Out Window
	ZeroMemory (&window, sizeof (GL_Window));							// Make Sure Memory Is Zeroed
	window.keys					= &keys;								// Window Key Structure
	window.init.application		= &application;							// Window Application
	window.init.title			= "NeHe's Cel-Shading Tutorial";		// Window Title
	window.init.width			= 640;									// Window Width
	window.init.height			= 480;									// Window Height
	window.init.bitsPerPixel	= 16;									// Bits Per Pixel
	window.init.isFullScreen	= TRUE;									// Fullscreen? (Set To TRUE)

	ZeroMemory (&keys, sizeof (Keys));									// Zero keys Structure

	// Ask The User If They Want To Start In FullScreen Mode?
	if (MessageBox (HWND_DESKTOP, "Would You Like To Run In Fullscreen Mode?", "Start FullScreen?", MB_YESNO | MB_ICONQUESTION) == IDNO)
	{
		window.init.isFullScreen = FALSE;								// If Not, Run In Windowed Mode
	}

	// Register A Class For Our Window To Use
	if (RegisterWindowClass (&application) == FALSE)					// Did Registering A Class Fail?
	{
		// Failure
		MessageBox (HWND_DESKTOP, "Error Registering Window Class!", "Error", MB_OK | MB_ICONEXCLAMATION);
		return -1;														// Terminate Application
	}

	g_isProgramLooping = TRUE;											// Program Looping Is Set To TRUE
	g_createFullScreen = window.init.isFullScreen;						// g_createFullScreen Is Set To User Default
	while (g_isProgramLooping)											// Loop Until WM_QUIT Is Received
	{
		// Create A Window
		window.init.isFullScreen = g_createFullScreen;					// Set Init Param Of Window Creation To Fullscreen?
		if (CreateWindowGL (&window) == TRUE)							// Was Window Creation Successful?
		{
			// At This Point We Should Have A Window That Is Setup To Render OpenGL
			if (Initialize (&window, &keys) == FALSE)					// Call User Intialization
			{
				// Failure
				TerminateApplication (&window);							// Close Window, This Will Handle The Shutdown
			}
			else														// Otherwise (Start The Message Pump)
			{	// Initialize was a success
				isMessagePumpActive = TRUE;								// Set isMessagePumpActive To TRUE
				while (isMessagePumpActive == TRUE)						// While The Message Pump Is Active
				{
					// Success Creating Window.  Check For Window Messages
					if (PeekMessage (&msg, window.hWnd, 0, 0, PM_REMOVE) != 0)
					{
						// Check For WM_QUIT Message
						if (msg.message != WM_QUIT)						// Is The Message A WM_QUIT Message?
						{
							DispatchMessage (&msg);						// If Not, Dispatch The Message
						}
						else											// Otherwise (If Message Is WM_QUIT)
						{
							isMessagePumpActive = FALSE;				// Terminate The Message Pump
						}
					}
					else												// If There Are No Messages
					{
						if (window.isVisible == FALSE)					// If Window Is Not Visible
						{
							WaitMessage ();								// Application Is Minimized Wait For A Message
						}
						else											// If Window Is Visible
						{
							// Process Application Loop
							tickCount = GetTickCount ();				// Get The Tick Count
							Update (tickCount - window.lastTickCount);	// Update The Counter
							window.lastTickCount = tickCount;			// Set Last Count To Current Count
							Draw ();									// Draw Our Scene

							SwapBuffers (window.hDC);					// Swap Buffers (Double Buffering)
						}
					}
				}														// Loop While isMessagePumpActive == TRUE
			}															// If (Initialize (...

			// Application Is Finished
			Deinitialize ();											// User Defined DeInitialization

			DestroyWindowGL (&window);									// Destroy The Active Window
		}
		else															// If Window Creation Failed
		{
			// Error Creating Window
			MessageBox (HWND_DESKTOP, "Error Creating OpenGL Window", "Error", MB_OK | MB_ICONEXCLAMATION);
			g_isProgramLooping = FALSE;									// Terminate The Loop
		}
	}																	// While (isProgramLooping)

	UnregisterClass (application.className, application.hInstance);		// UnRegister Window Class
	return 0;
}																		// End Of WinMain()
Example #18
0
 CSimpleWndHelper::~CSimpleWndHelper()
 {
     if(m_hHeap) HeapDestroy(m_hHeap);
     DeleteCriticalSection(&m_cs);
     if(m_atom) UnregisterClass((LPCTSTR)m_atom,m_hInst);
 }
// Registers a window class for the splash and splash owner windows.
void CSplashScreen::UnregisterWindowClass() {
	UnregisterClass(m_strSplashClass.c_str(), m_hInstance);
}
void DeinitWindow()
{
	UnregisterClass(windowClass.lpszClassName, windowClass.hInstance);
}
Example #21
0
static void cleanup(void) {
    msg_spy_cleanup();
    if (hwnd)
        DestroyWindow(hwnd);
    UnregisterClass(wndcls, GetModuleHandle(0));
}
Example #22
0
bool CWGLManager::initialize(const SIrrlichtCreationParameters& params, const SExposedVideoData& videodata)
{
	// store params, videoData is set later as it would be overwritten else
	Params=params;

	// Create a window to test antialiasing support
	const fschar_t* ClassName = __TEXT("CWGLManager");
	HINSTANCE lhInstance = GetModuleHandle(0);

	// Register Class
	WNDCLASSEX wcex;
	wcex.cbSize        = sizeof(WNDCLASSEX);
	wcex.style         = CS_HREDRAW | CS_VREDRAW;
	wcex.lpfnWndProc   = (WNDPROC)DefWindowProc;
	wcex.cbClsExtra    = 0;
	wcex.cbWndExtra    = 0;
	wcex.hInstance     = lhInstance;
	wcex.hIcon         = NULL;
	wcex.hCursor       = LoadCursor(NULL, IDC_ARROW);
	wcex.hbrBackground  = (HBRUSH)(COLOR_WINDOW+1);
	wcex.lpszMenuName  = 0;
	wcex.lpszClassName = ClassName;
	wcex.hIconSm       = 0;
	wcex.hIcon         = 0;
	RegisterClassEx(&wcex);

	RECT clientSize;
	clientSize.top = 0;
	clientSize.left = 0;
	clientSize.right = Params.WindowSize.Width;
	clientSize.bottom = Params.WindowSize.Height;

	DWORD style = WS_POPUP;
	if (!Params.Fullscreen)
		style = WS_SYSMENU | WS_BORDER | WS_CAPTION | WS_CLIPCHILDREN | WS_CLIPSIBLINGS;

	AdjustWindowRect(&clientSize, style, FALSE);

	const s32 realWidth = clientSize.right - clientSize.left;
	const s32 realHeight = clientSize.bottom - clientSize.top;

	const s32 windowLeft = (GetSystemMetrics(SM_CXSCREEN) - realWidth) / 2;
	const s32 windowTop = (GetSystemMetrics(SM_CYSCREEN) - realHeight) / 2;

	HWND temporary_wnd=CreateWindow(ClassName, __TEXT(""), style, windowLeft,
			windowTop, realWidth, realHeight, NULL, NULL, lhInstance, NULL);

	if (!temporary_wnd)
	{
		os::Printer::log("Cannot create a temporary window.", ELL_ERROR);
		UnregisterClass(ClassName, lhInstance);
		return false;
	}

	HDC HDc = GetDC(temporary_wnd);

	// Set up pixel format descriptor with desired parameters
	PIXELFORMATDESCRIPTOR tmp_pfd = {
		sizeof(PIXELFORMATDESCRIPTOR),             // Size Of This Pixel Format Descriptor
		1,                                         // Version Number
		PFD_DRAW_TO_WINDOW |                       // Format Must Support Window
		PFD_SUPPORT_OPENGL |                       // Format Must Support OpenGL
		(Params.Doublebuffer?PFD_DOUBLEBUFFER:0) | // Must Support Double Buffering
		(Params.Stereobuffer?PFD_STEREO:0),        // Must Support Stereo Buffer
		PFD_TYPE_RGBA,                             // Request An RGBA Format
		Params.Bits,                               // Select Our Color Depth
		0, 0, 0, 0, 0, 0,                          // Color Bits Ignored
		0,                                         // No Alpha Buffer
		0,                                         // Shift Bit Ignored
		0,                                         // No Accumulation Buffer
		0, 0, 0, 0,	                               // Accumulation Bits Ignored
		Params.ZBufferBits,                        // Z-Buffer (Depth Buffer)
		BYTE(Params.Stencilbuffer ? 1 : 0),        // Stencil Buffer Depth
		0,                                         // No Auxiliary Buffer
		PFD_MAIN_PLANE,                            // Main Drawing Layer
		0,                                         // Reserved
		0, 0, 0                                    // Layer Masks Ignored
	};
	pfd=tmp_pfd;

	for (u32 i=0; i<6; ++i)
	{
		if (i == 1)
		{
			if (Params.Stencilbuffer)
			{
				os::Printer::log("Cannot create a GL device with stencil buffer, disabling stencil shadows.", ELL_WARNING);
				Params.Stencilbuffer = false;
				pfd.cStencilBits = 0;
			}
			else
				continue;
		}
		else
		if (i == 2)
		{
			pfd.cDepthBits = 24;
		}
		else
		if (i == 3)
		{
			if (Params.Bits!=16)
				pfd.cDepthBits = 16;
			else
				continue;
		}
		else
		if (i == 4)
		{
			// try single buffer
			if (Params.Doublebuffer)
				pfd.dwFlags &= ~PFD_DOUBLEBUFFER;
			else
				continue;
		}
		else
		if (i == 5)
		{
			os::Printer::log("Cannot create a GL device context", "No suitable format for temporary window.", ELL_ERROR);
			ReleaseDC(temporary_wnd, HDc);
			DestroyWindow(temporary_wnd);
			UnregisterClass(ClassName, lhInstance);
			return false;
		}

		// choose pixelformat
		PixelFormat = ChoosePixelFormat(HDc, &pfd);
		if (PixelFormat)
			break;
	}

	SetPixelFormat(HDc, PixelFormat, &pfd);
	os::Printer::log("Temporary context");
	HGLRC hrc=wglCreateContext(HDc);
	if (!hrc)
	{
		os::Printer::log("Cannot create a temporary GL rendering context.", ELL_ERROR);
		ReleaseDC(temporary_wnd, HDc);
		DestroyWindow(temporary_wnd);
		UnregisterClass(ClassName, lhInstance);
		return false;
	}

	CurrentContext.OpenGLWin32.HDc = HDc;
	CurrentContext.OpenGLWin32.HRc = hrc;
	CurrentContext.OpenGLWin32.HWnd = temporary_wnd;

	if (!activateContext(CurrentContext))
	{
		os::Printer::log("Cannot activate a temporary GL rendering context.", ELL_ERROR);
		wglDeleteContext(hrc);
		ReleaseDC(temporary_wnd, HDc);
		DestroyWindow(temporary_wnd);
		UnregisterClass(ClassName, lhInstance);
		return false;
	}

	core::stringc wglExtensions;
#ifdef WGL_ARB_extensions_string
	PFNWGLGETEXTENSIONSSTRINGARBPROC irrGetExtensionsString = (PFNWGLGETEXTENSIONSSTRINGARBPROC)wglGetProcAddress("wglGetExtensionsStringARB");
	if (irrGetExtensionsString)
		wglExtensions = irrGetExtensionsString(HDc);
#elif defined(WGL_EXT_extensions_string)
	PFNWGLGETEXTENSIONSSTRINGEXTPROC irrGetExtensionsString = (PFNWGLGETEXTENSIONSSTRINGEXTPROC)wglGetProcAddress("wglGetExtensionsStringEXT");
	if (irrGetExtensionsString)
		wglExtensions = irrGetExtensionsString(HDc);
#endif
	const bool pixel_format_supported = (wglExtensions.find("WGL_ARB_pixel_format") != -1);
	const bool multi_sample_supported = ((wglExtensions.find("WGL_ARB_multisample") != -1) ||
		(wglExtensions.find("WGL_EXT_multisample") != -1) || (wglExtensions.find("WGL_3DFX_multisample") != -1) );
#ifdef _DEBUG
	os::Printer::log("WGL_extensions", wglExtensions);
#endif

#ifdef WGL_ARB_pixel_format
	PFNWGLCHOOSEPIXELFORMATARBPROC wglChoosePixelFormat_ARB = (PFNWGLCHOOSEPIXELFORMATARBPROC)wglGetProcAddress("wglChoosePixelFormatARB");
	if (pixel_format_supported && wglChoosePixelFormat_ARB)
	{
		// This value determines the number of samples used for antialiasing
		// My experience is that 8 does not show a big
		// improvement over 4, but 4 shows a big improvement
		// over 2.

		if (Params.AntiAlias > 32)
			Params.AntiAlias = 32;

		f32 fAttributes[] = {0.0, 0.0};
		s32 iAttributes[] =
		{
			WGL_DRAW_TO_WINDOW_ARB,1,
			WGL_SUPPORT_OPENGL_ARB,1,
			WGL_ACCELERATION_ARB,WGL_FULL_ACCELERATION_ARB,
			WGL_COLOR_BITS_ARB,(Params.Bits==32) ? 24 : 15,
			WGL_ALPHA_BITS_ARB,(Params.Bits==32) ? 8 : 1,
			WGL_DEPTH_BITS_ARB,Params.ZBufferBits, // 10,11
			WGL_STENCIL_BITS_ARB,Params.Stencilbuffer ? 1 : 0,
			WGL_DOUBLE_BUFFER_ARB,Params.Doublebuffer ? 1 : 0,
			WGL_STEREO_ARB,Params.Stereobuffer ? 1 : 0,
			WGL_PIXEL_TYPE_ARB, WGL_TYPE_RGBA_ARB,
#ifdef WGL_ARB_multisample
			WGL_SAMPLES_ARB,Params.AntiAlias, // 20,21
			WGL_SAMPLE_BUFFERS_ARB, 1,
#elif defined(WGL_EXT_multisample)
			WGL_SAMPLES_EXT,AntiAlias, // 20,21
			WGL_SAMPLE_BUFFERS_EXT, 1,
#elif defined(WGL_3DFX_multisample)
			WGL_SAMPLES_3DFX,AntiAlias, // 20,21
			WGL_SAMPLE_BUFFERS_3DFX, 1,
#endif
#ifdef WGL_ARB_framebuffer_sRGB
			WGL_FRAMEBUFFER_SRGB_CAPABLE_ARB, Params.HandleSRGB ? 1:0,
#elif defined(WGL_EXT_framebuffer_sRGB)
			WGL_FRAMEBUFFER_SRGB_CAPABLE_EXT, Params.HandleSRGB ? 1:0,
#endif
//			WGL_DEPTH_FLOAT_EXT, 1,
			0,0,0,0
		};
		int iAttrSize = sizeof(iAttributes)/sizeof(int);
		const bool framebuffer_srgb_supported = ((wglExtensions.find("WGL_ARB_framebuffer_sRGB") != -1) ||
			(wglExtensions.find("WGL_EXT_framebuffer_sRGB") != -1));
		if (!framebuffer_srgb_supported)
		{
			memmove(&iAttributes[24],&iAttributes[26],sizeof(int)*(iAttrSize-26));
			iAttrSize -= 2;
		}
		if (!multi_sample_supported)
		{
			memmove(&iAttributes[20],&iAttributes[24],sizeof(int)*(iAttrSize-24));
			iAttrSize -= 4;
		}

		s32 rv=0;
		// Try to get an acceptable pixel format
		do
		{
			int pixelFormat=0;
			UINT numFormats=0;
			const BOOL valid = wglChoosePixelFormat_ARB(HDc,iAttributes,fAttributes,1,&pixelFormat,&numFormats);

			if (valid && numFormats)
				rv = pixelFormat;
			else
				iAttributes[21] -= 1;
		}
		while(rv==0 && iAttributes[21]>1);
		if (rv)
		{
			PixelFormat=rv;
			Params.AntiAlias=iAttributes[21];
		}
	}
	else
#endif
		Params.AntiAlias=0;

	// this only terminates the temporary HRc
	destroyContext();
	destroySurface();
	terminate();
	DestroyWindow(temporary_wnd);
	UnregisterClass(ClassName, lhInstance);

	// now get new window
	CurrentContext.OpenGLWin32.HWnd=videodata.OpenGLWin32.HWnd;
	// get hdc
	if (!(CurrentContext.OpenGLWin32.HDc=GetDC((HWND)videodata.OpenGLWin32.HWnd)))
	{
		os::Printer::log("Cannot create a GL device context.", ELL_ERROR);
		return false;
	}
	if (!PrimaryContext.OpenGLWin32.HWnd)
	{
		PrimaryContext.OpenGLWin32.HWnd=CurrentContext.OpenGLWin32.HWnd;
		PrimaryContext.OpenGLWin32.HDc=CurrentContext.OpenGLWin32.HDc;
	}

	return true;
}
Example #23
0
		~InputBox()
		{
			UnregisterClass(CIB_CLASS_NAME, hThisInstance);
		}
Example #24
0
Eina_Bool
engine_direct3d_args(const char *engine, int width, int height)
{
   WNDCLASS                   wc;
   RECT                       rect;
   HDC                        dc;
   MSG                        msg;
   Evas_Engine_Info_Direct3D *einfo;
   DWORD                      style;
   int                        depth;
   int                        i;

   instance = GetModuleHandle(NULL);
   if (!instance) return EINA_FALSE;

   wc.style = 0;
   wc.lpfnWndProc = MainWndProc;
   wc.cbClsExtra = 0;
   wc.cbWndExtra = 0;
   wc.hInstance = instance;
   wc.hIcon = LoadIcon (NULL, IDI_APPLICATION);
   wc.hCursor = LoadCursor (NULL, IDC_ARROW);
   wc.hbrBackground = GetSysColorBrush(COLOR_BTNFACE);
   wc.lpszMenuName =  NULL;
   wc.lpszClassName = "Evas_Direct3D_Test";

   if(!RegisterClass(&wc))
     goto free_library;

   rect.left = 0;
   rect.top = 0;
   rect.right = width;
   rect.bottom = height;
   AdjustWindowRect (&rect, WS_OVERLAPPEDWINDOW | WS_SIZEBOX, FALSE);

   window = CreateWindowEx(0,
                           "Evas_Direct3D_Test",
                           "Evas_Direct3D_Test",
                           WS_OVERLAPPEDWINDOW | WS_SIZEBOX,
                           CW_USEDEFAULT, CW_USEDEFAULT,
                           rect.right - rect.left, rect.bottom - rect.top,
                           NULL, NULL, instance, NULL);
   if (!window)
     goto unregister_class;

   /* make the window non resizable */
   style = GetWindowLong(window, GWL_STYLE);
   style &= ~WS_THICKFRAME;
   if (!SetWindowLong(window, GWL_STYLE, style))
     goto unregister_class;

   dc = GetDC(NULL);
   if (!dc)
     goto destroy_window;

   depth = GetDeviceCaps(dc, BITSPIXEL);
   ReleaseDC(NULL, dc);

   evas_output_method_set(evas, evas_render_method_lookup("direct3d"));
   einfo = (Evas_Engine_Info_Direct3D *)evas_engine_info_get(evas);
   if (!einfo)
     {
        fprintf(stderr, "Evas does not support the Direct3D Engine\n");
        goto destroy_window;
     }

   einfo->info.window = window;
   einfo->info.depth = depth;
   einfo->info.rotation = 0;
   if (!evas_engine_info_set(evas, (Evas_Engine_Info *)einfo))
     {
	printf("Evas can not setup the informations of the Direct3D Engine\n");
        goto destroy_window;
     }

   /* the second parameter is ignored, as it's the first call of ShowWindow */
   ShowWindow(window, SW_SHOWDEFAULT);
   UpdateWindow(window);

   return EINA_TRUE;

 destroy_window:
   DestroyWindow(window);
 unregister_class:
   UnregisterClass("Evas_Direct3D_Test", instance);
 free_library:
   FreeLibrary(instance);

   return EINA_FALSE;
}
Example #25
0
static void winCanvasReleaseMethod(Iclass* ic)
{
  (void)ic;
  if (iupwinClassExist("IupCanvas"))
    UnregisterClass("IupCanvas", iupwin_hinstance);
}
Example #26
0
INT WINAPI WinMain(HINSTANCE hInst, HINSTANCE hPrevInst, LPSTR lpCmdLine, int nShowCmd)
{
	WNDCLASSEX wc =
	{
		sizeof(WNDCLASSEX),
		CS_CLASSDC,
		(WNDPROC)WndProc,
		0L, 0L,
		hInst,
		NULL,
		NULL,
		CreateSolidBrush(RGB(240, 240, 240)),
		NULL,
		"TestClass",
		NULL
	};

	RegisterClassEx(&wc);
	
	int w = GetSystemMetrics(0);
	int h = GetSystemMetrics(1);

	DWORD style = WS_CLIPCHILDREN|WS_CLIPSIBLINGS|WS_SYSMENU|WS_BORDER|WS_CAPTION;

	hwnd = CreateWindowA("TestClass", "Winapi2", style,
		(w - 450) / 2, (h - 200) / 2, 450, 200,
		NULL, NULL, wc.hInstance, NULL);
	
	if( !hwnd )
	{
		MessageBoxA(NULL, "Could not create window!", "Error!", MB_OK);
		goto _end;
	}

	if( !InitControls() )
	{
		MessageBoxA(NULL, "Could not init controls!", "Error!", MB_OK);
		goto _end;
	}

	ShowWindow(hwnd, SW_SHOWDEFAULT);
	UpdateWindow(hwnd);

	MSG msg;
	ZeroMemory(&msg, sizeof(msg));

	while( msg.message != WM_QUIT )
	{
		while( PeekMessage(&msg, NULL, 0U, 0U, PM_REMOVE) )
		{
			TranslateMessage(&msg);
			DispatchMessage(&msg);
		}
	}

_end:
	if( combo1 )
		delete combo1;

	if( combo2 )
		delete combo2;

	if( animgif )
		animgif->Dispose();

	if( gdiplustoken )
		Gdiplus::GdiplusShutdown(gdiplustoken);

	UnregisterClass("TestClass", wc.hInstance);
	return 0;
}
Example #27
0
int WINAPI WinMain(HINSTANCE hinstance, HINSTANCE hprev, PSTR cmdline, int ishow)
{
  	HWND hwnd;
    MSG msg;
    WNDCLASSEX wndclassex = {0};
										
	// Init the fields we care about			
    wndclassex.cbSize = sizeof(WNDCLASSEX);
    wndclassex.style = CS_HREDRAW | CS_VREDRAW;
    wndclassex.lpfnWndProc = WinProc;
    wndclassex.hInstance = hinstance;
	wndclassex.hbrBackground = (HBRUSH)GetStockObject(BLACK_BRUSH);
	wndclassex.lpszClassName = class_name;
	wndclassex.hCursor = (HCURSOR)LoadImage(NULL, MAKEINTRESOURCE(IDC_ARROW), IMAGE_CURSOR,
											0, 0, LR_SHARED);

    RegisterClassEx(&wndclassex);

	// Create the window
    hwnd = CreateWindowEx(WS_EX_APPWINDOW,
						  class_name,
						  "www.GameTutorials.com -- Shortest Path",
						  WS_OVERLAPPED | WS_SYSMENU, // Window won't be resizable
						  CW_USEDEFAULT, 
						  CW_USEDEFAULT, 
						  WIN_WID,
						  WIN_HGT,
						  NULL,
						  NULL,
						  hinstance,
						  NULL);

		// Error Check
		if(!hwnd)
			return EXIT_FAILURE;
		
	// Init our CWinObj (sets up double buffering as well)
	if(gWinObj.init(hwnd) == false)
		return EXIT_FAILURE;

	// Show and update window
    ShowWindow(hwnd, ishow);
    UpdateWindow(hwnd);
	
	while(1)
	{
		// Checking for window messages -- If we get one we'll deal with it
		if(PeekMessage(&msg,NULL,0,0,PM_REMOVE))
		{
			if(msg.message == WM_QUIT)
				break;
				
			TranslateMessage(&msg);
			DispatchMessage(&msg);
		}
		else if(LockFrameRate(FRAME_RATE))	// Otherwise we'll redraw the screen if we have to
		{	
			// Fill the window to black
			FillRect(gWinObj.getBackHDC(),&(gWinObj.getClientRect()),
					(HBRUSH)GetStockObject(BLACK_BRUSH));

			gGrid.draw(gWinObj.getBackHDC(),XPOS,YPOS);

			// Blit the back buffer to the front buffer
			BitBlt(gWinObj.getHDC(),0,0,gWinObj.getClientWid(),gWinObj.getClientHgt(),
				   gWinObj.getBackHDC(),0,0,SRCCOPY);

			// If done drawing, prompt the user to see if they want to do it again
			if(gGrid.doneDrawing())
			{
				if(MessageBox(hwnd,"Do again?","Shortest path completed!!!",
							  MB_YESNO | MB_ICONQUESTION) == IDYES)
				{
					gGrid.init();
					gRbTimes = 0;
				}
				else
					break; // We're done with the app
			}

		} // end of else if(LockFrameRate(FRAME_RATE))

	} // end of while(1)

	UnregisterClass(class_name,hinstance); // Unregister the WNDCLASSEX
		return msg.wParam;
}
Example #28
0
// Main message pump
//-----------------------------------------------------------------------------
int CPUTWindowWin::StartMessageLoop()
{
    // Clear message queue
MSG msg;
//for(;;)
//{
//    while( PeekMessage( &msg, NULL, 0, 0, PM_REMOVE ) )
//    {
//        if (msg.message == WM_DESTROY)
//            return CPUT_ERROR;
//        TranslateMessage( &msg );
//        DispatchMessage( &msg );
    //
//    }
//}

    //
    // Message pump
    //
    bool fRunning = true;
    while(fRunning)
    {
        // PeekMessage() is a passthru on no events
        // so it allows us to render while no events are present
        if( PeekMessage(&msg, NULL, 0, 0, PM_REMOVE) )
        {
            if (msg.message == WM_QUIT)
            {
                PostQuitMessage(0);
                fRunning = false;
            }
            TranslateMessage( &msg );
            DispatchMessage( &msg );
        }
        else if (IsWindowMinimized()) 
        {
            Sleep(100);
        }
        else
        {
            // trigger render and other calls
            for (const auto &callBack : mLoopEventCallbacks) {
                callBack();
            }
        }
    }
    Destroy();
    //
    // Drain out the rest of the message queue.
    //
    while( PeekMessage(&msg, NULL, 0, 0, PM_REMOVE) )
    {
        TranslateMessage( &msg );
        DispatchMessage( &msg );
    }

    uint32_t numWChars = MultiByteToWideChar(CP_UTF8, 0, mAppTitle.c_str(), -1, NULL, 0);
    wchar_t* wstr = new wchar_t[numWChars];
    MultiByteToWideChar(CP_UTF8, 0, mAppTitle.c_str(), -1, wstr, numWChars);

    if (UnregisterClass(wstr, mhInstance) == 0) {
        HandleWin32Error();
    }

    delete[] wstr;

    //
    // Set the window handle to NULL to indicate window shutdown is complete
    //
    mhWnd = NULL;

    // return code
    mAppClosedReturnCode =  (int) msg.wParam;
    return mAppClosedReturnCode;
}
Example #29
0
File: main.cpp Project: Gxsghsn/xy2
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nShowCmd)
{
	WNDCLASSEX wndClass = { 0 };							//用WINDCLASSEX定义了一个窗口类
	wndClass.cbSize = sizeof(WNDCLASSEX);			//设置结构体的字节数大小
	wndClass.style = CS_HREDRAW | CS_VREDRAW;	//设置窗口的样式
	wndClass.lpfnWndProc = WndProc;					//设置指向窗口过程函数的指针
	wndClass.cbClsExtra = 0;								//窗口类的附加内存,取0就可以了
	wndClass.cbWndExtra = 0;							//窗口的附加内存,依然取0就行了
	wndClass.hInstance = hInstance;						//指定包含窗口过程的程序的实例句柄。
	wndClass.hIcon = (HICON)::LoadImage(NULL, L"icon.ico", IMAGE_ICON, 0, 0, LR_DEFAULTSIZE | LR_LOADFROMFILE);  //本地加载自定义ico图标
	wndClass.hCursor = (HICON)::LoadImage(NULL, L"icon.ico", IMAGE_ICON, 0, 0, LR_DEFAULTSIZE | LR_LOADFROMFILE);    //指定窗口类的光标句柄。
	wndClass.hbrBackground = (HBRUSH)GetStockObject(WHITE_BRUSH);  //为hbrBackground成员指定一个白色画刷句柄	
	wndClass.lpszMenuName = NULL;						//用一个以空终止的字符串,指定菜单资源的名字。
	wndClass.lpszClassName = L"ForTheDreamOfGameDevelop";		//用一个以空终止的字符串,指定窗口类的名字。

	if (!RegisterClassEx(&wndClass))				//设计完窗口后,需要对窗口类进行注册,这样才能创建该类型的窗口
		return -1;

	HWND hwnd = CreateWindow(L"ForTheDreamOfGameDevelop", WINDOW_TITLE,				//喜闻乐见的创建窗口函数CreateWindow
		WS_OVERLAPPEDWINDOW, CW_USEDEFAULT, CW_USEDEFAULT, WINDOW_WIDTH,
		WINDOW_HEIGHT, NULL, NULL, hInstance, NULL);

	MoveWindow(hwnd, 250, 80, WINDOW_WIDTH, WINDOW_HEIGHT, true);		//调整窗口显示时的位置,使窗口左上角位于(250,80)处
	ShowWindow(hwnd, nShowCmd);    //调用ShowWindow函数来显示窗口
	UpdateWindow(hwnd);						//对窗口进行更新,就像我们买了新房子要装修一样

	//游戏资源的初始化,若初始化失败,弹出一个消息框,并返回FALSE
	if (!Game_Init(hwnd))
	{
		MessageBox(hwnd, L"资源初始化失败", L"消息窗口", 0); //使用MessageBox函数,创建一个消息窗口
		return FALSE;
	}
	PlaySound(L"GameMedia\\梦幻西游原声-战斗1-森林.wav", NULL, SND_FILENAME | SND_ASYNC | SND_LOOP); //循环播放背景音乐 

	hMenu = LoadMenu(hInstance, MAKEINTRESOURCE(123));
	SetMenu(hwnd, hMenu);

	MSG msg = { 0 };				//定义并初始化msg
	while (msg.message != WM_QUIT)		//使用while循环,如果消息不是WM_QUIT消息,就继续循环
	{
		if (PeekMessage(&msg, 0, 0, 0, PM_REMOVE))   //查看应用程序消息队列,有消息时将队列中的消息派发出去。
		{
			TranslateMessage(&msg);		//将虚拟键消息转换为字符消息
			DispatchMessage(&msg);			//分发一个消息给窗口程序。
		}
		else
		{
			g_tNow = GetTickCount();   //获取当前系统时间
			if (g_tNow - g_tPre >= 60){
				if (nowscen == 1)
					Game_Fight(hwnd);
				else{
					Game_Paint(hwnd);
				}
			}
		}
	}

	UnregisterClass(L"ForTheDreamOfGameDevelop", wndClass.hInstance);  //程序准备结束,注销窗口类
	return 0;
}
Example #30
0
/*
* main
*
* Purpose:
*
* Program entry point.
*
*/
void main()
{

	PTEB			teb = NtCurrentTeb();
	PPEB			peb = teb->ProcessEnvironmentBlock;
	WNDCLASSEX		wincls;
	HINSTANCE		hinst = GetModuleHandle(NULL);
	BOOL			rv = TRUE;
	MSG				msg1;
	ATOM			class_atom;
	HWND			MainWindow;
	DWORD			prot;
	OSVERSIONINFOW	osver;

	DWORD					cch;
	TCHAR					cmdbuf[MAX_PATH * 2], sysdir[MAX_PATH + 1];
	STARTUPINFO				startupInfo;
	PROCESS_INFORMATION		processInfo;


	RtlSecureZeroMemory(&osver, sizeof(osver));
	osver.dwOSVersionInfoSize = sizeof(osver);
	RtlGetVersion(&osver);
	
	if (osver.dwBuildNumber > 7601) {
		ExitProcess((UINT)-1);
		return;
	}

	if (supIsProcess32bit(GetCurrentProcess())) {
		ExitProcess((UINT)-2);
		return;
	}

	g_OurPID = GetCurrentProcessId();
	g_PsLookupProcessByProcessIdPtr = (PVOID)GetPsLookupProcessByProcessId();

#ifdef _WIN64
	g_EPROCESS_TokenOffset = 0x208;
#else
	g_EPROCESS_TokenOffset = 0xF8;
#endif


	if (g_PsLookupProcessByProcessIdPtr == NULL) {
		ExitProcess((UINT)-3);
		return;
	}

	RtlSecureZeroMemory(&wincls, sizeof(wincls));
	wincls.cbSize = sizeof(WNDCLASSEX);
	wincls.lpfnWndProc = &MainWindowProc;
	wincls.hIcon = LoadIcon(NULL, IDI_APPLICATION);
	wincls.lpszClassName = MAINWINDOWCLASSNAME;

	class_atom = RegisterClassEx(&wincls);
	while (class_atom) {

		g_w32theadinfo = teb->Win32ThreadInfo;

		g_ppCCI = &((PVOID *)peb->KernelCallbackTable)[0x36]; //  <--- User32_ClientCopyImage INDEX
	
		if (!VirtualProtect(g_ppCCI, sizeof(PVOID), PAGE_EXECUTE_READWRITE, &prot)) {
			break;
		}
		g_originalCCI = InterlockedExchangePointer(g_ppCCI, &hookCCI);

		MainWindow = CreateWindowEx(0, MAKEINTATOM(class_atom),
			NULL, 0, 0, 0, 0, 0, NULL, NULL, NULL, NULL);

		if (g_shellCalled == 1) {

			RtlSecureZeroMemory(&startupInfo, sizeof(startupInfo));
			RtlSecureZeroMemory(&processInfo, sizeof(processInfo));
			startupInfo.cb = sizeof(startupInfo);
			GetStartupInfo(&startupInfo);

			RtlSecureZeroMemory(sysdir, sizeof(sysdir));
			cch = ExpandEnvironmentStrings(TEXT("%systemroot%\\system32\\"), sysdir, MAX_PATH);
			if ((cch != 0) && (cch < MAX_PATH)) {
				RtlSecureZeroMemory(cmdbuf, sizeof(cmdbuf));
				_strcpy(cmdbuf, sysdir);
				_strcat(cmdbuf, TEXT("cmd.exe"));

				if (CreateProcess(cmdbuf, NULL, NULL, NULL, FALSE, 0, NULL,
					sysdir, &startupInfo, &processInfo))
				{
					CloseHandle(processInfo.hProcess);
					CloseHandle(processInfo.hThread);
				}
			}

		}
		else {
			OutputDebugString(TEXT(" Failed \r\n"));
		}

		if (!MainWindow)
			break;

		do {
			rv = GetMessage(&msg1, NULL, 0, 0);

			if (rv == -1)
				break;

			TranslateMessage(&msg1);
			DispatchMessage(&msg1);
		} while (rv != 0);

		break;
	}

	if (class_atom)
		UnregisterClass(MAKEINTATOM(class_atom), hinst);

	ExitProcess(0);
}