Jump to content
  • Advertisement
Sign in to follow this  
calidev234

Loosing keyboard control of 3d window

This topic is 4811 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’m launching a non-mfc window from an mfc application; basically creating the window myself and handling all the messages. Anyway I want the window to be like a popup window that doesn’t allow any others to be opened while the 3D window is opened. Also, if I click on anything outside the 3D window, while it’s opened, and then click back to the 3D window (regaining the focus) I loose all keyboard control – no keyboard action is registered anymore. The code for launching my window is show here:
	MSG msg;
    HWND hWnd;

	HINSTANCE hInstance = _AtlBaseModule.GetModuleInstance();
	int       nCmdShow=1;

	msg.message = 0;
	
	// register the class
	MyRegisterClass(hInstance);

    //set up the screen in windowed or fullscreen mode?
    DWORD style;
    if (FULLSCREEN)	style = WS_EX_TOPMOST | WS_VISIBLE | WS_POPUP;
    //else	        style = WS_OVERLAPPEDWINDOW | WS_POPUP;
	else			style = WS_OVERLAPPEDWINDOW | WS_POPUPWINDOW;

	//CWindow gameWnd = new CWindow();
	
    //create a new window
    hWnd = CreateWindow(
       APPTITLE,				//window class
       APPTITLE,				//title bar
       style,					//window style
       CW_USEDEFAULT,			//x position of window
       CW_USEDEFAULT,			//y position of window
       SCREEN_WIDTH,			//width of the window
       SCREEN_HEIGHT,			//height of the window
       NULL,					//parent window
       NULL,					//menu
       hInstance,				//application instance
       NULL);					//window parameters
	
	CloseWindow(hWnd);
    if (!hWnd) return FALSE;	//was there an error creating the window?
    ShowWindow(hWnd, nCmdShow);	//display the window
    UpdateWindow(hWnd);
	
    //Initialize: Direct3D
	if (!Init_Direct3D(hWnd, SCREEN_WIDTH, SCREEN_HEIGHT, FULLSCREEN))
	{
		ShowWindow(hWnd, 0);	//display the window
		return 0;
	}

    //Initialize: DirectSound
    //if (!Init_DirectSound(hWnd))
    //{
    //    MessageBox(hWnd, "Error initializing DirectSound", "Error", MB_OK);
    //    return 0;
	//}

    //Initialize: DirectInput
    if (!Init_DirectInput(hWnd))
    {
        MessageBox(hWnd, "Error initializing DirectInput", "Error", MB_OK);
        return 0;
    }
    
	//Initialize: GAME
    if (!Game_Init(hWnd))
    {
        MessageBox(hWnd, "Error initializing the game", "Error", MB_OK);
        return 0;
    }

	// ------------------------------------
    // Main Message Loop (START)
	// ------------------------------------
	while (msg.message != WM_QUIT)
    {
        if (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE)) 
	    {
		    TranslateMessage(&msg);	//decode and pass messages on to WndProc
		    DispatchMessage(&msg);
	    }
        else
            Game_Run(hWnd);			//process game loop (else prevents running after window is closed)
    }
	// ------------------------------------
    // Main Message Loop (END)
	// ------------------------------------

	return msg.wParam;

Does anybody have any ideas? Thank you very much, j

Share this post


Link to post
Share on other sites
Advertisement
Ok, so I figured this out; simple and stupid. When I'm creating the mouse and the keyboard input I WAS setting the cooperativelevel for the keyboard. Now I simply removed this and it works fine; that is it always has keyboard control even when the 3d view window does not have the focus. So I just got rid of this code:

result = dikeyboard->SetCooperativeLevel(hwnd, DISCL_NONEXCLUSIVE | DISCL_FOREGROUND);
if (result != DI_OK)
return 0;

Thank you,

J

Share this post


Link to post
Share on other sites
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!