Jump to content
  • Advertisement
Sign in to follow this  
trick

un-dying process

This topic is 4221 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I am working on the very basics of a windows program, but I am having a strange problem. (Well, strange to me anyways). I am working in Visual C++ 6.0, and below is the WinMain function. The problem is that even after I close the window out, the program still shows up in the "Processes" tab of the Task Manager, usually at CPU usages around the 90%+ range.
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPTSTR lpCmdLine, int nCmdShow){
	float last_time = 0.0f;
	if(!initWindow(hInstance))
		return false;
	if(!initDirect3D())
		return false;

	MSG msg;
	ZeroMemory(&msg, sizeof(msg));
	timer.FindFreq();
	while(1){
		if(PeekMessage(&msg, NULL, 0, 0, PM_REMOVE)){
			TranslateMessage(&msg);
			DispatchMessage(&msg);
		}else{
			timer.Begin();
			update(last_time);
			render();
			last_time = timer.End();
		}
	}

	cleanup();
	return 0;
}

void cleanup(){
	if(pd3dDevice != NULL)
		pd3dDevice->Release();
	
	if(pD3D != NULL)
		pD3D->Release();
}

bool initWindow(HINSTANCE hInstance){
	WNDCLASSEX wc;
	wc.cbSize = sizeof(WNDCLASSEX);
	wc.style = CS_HREDRAW | CS_VREDRAW;
	wc.lpfnWndProc = (WNDPROC)WndProc;
	wc.cbClsExtra = 0;
	wc.cbWndExtra = 0;
	wc.hInstance = hInstance;
	wc.hIcon = 0;
	wc.hCursor = LoadCursor(NULL, IDC_ARROW);
	wc.hbrBackground = (HBRUSH)(COLOR_WINDOW+1);
	wc.lpszMenuName = NULL;
	wc.lpszClassName = "Block Buster";
	wc.hIconSm = 0;
	RegisterClassEx(&wc);

	wndHandle = CreateWindow("Block Buster", "Block Buster", WS_OVERLAPPEDWINDOW, CW_USEDEFAULT, CW_USEDEFAULT, 640, 480, NULL, NULL, hInstance, NULL);

	if(!wndHandle)
		return false;
	ShowWindow(wndHandle, SW_SHOW);
	UpdateWindow(wndHandle);
	return true;
}

LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam){
	switch(message){
	case WM_DESTROY:
		PostQuitMessage(0);
		break;
	}
	return DefWindowProc(hWnd, message, wParam, lParam);
}

bool initDirect3D(){
	pD3D = NULL;
	pd3dDevice = NULL;

	if(NULL == (pD3D = Direct3DCreate9(D3D_SDK_VERSION))){
		return false;
	}

	D3DPRESENT_PARAMETERS d3dpp;
	ZeroMemory(&d3dpp, sizeof(d3dpp));
	d3dpp.Windowed = TRUE;
	d3dpp.SwapEffect = D3DSWAPEFFECT_DISCARD;
	d3dpp.BackBufferFormat = D3DFMT_UNKNOWN;
	d3dpp.BackBufferCount = 1;
	d3dpp.BackBufferHeight = 480;
	d3dpp.BackBufferWidth = 640;
	d3dpp.hDeviceWindow = wndHandle;

	if(FAILED(pD3D->CreateDevice(D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, wndHandle, D3DCREATE_SOFTWARE_VERTEXPROCESSING, &d3dpp, &pd3dDevice))){
		return false;
	}
	return true;
}

Share this post


Link to post
Share on other sites
Advertisement
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!