Advertisement Jump to content
Sign in to follow this  

Loosing keyboard control of 3d window

This topic is 4880 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

    //set up the screen in windowed or fullscreen mode?
    DWORD style;
    //else	        style = WS_OVERLAPPEDWINDOW | WS_POPUP;

	//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
    if (!hWnd) return FALSE;	//was there an error creating the window?
    ShowWindow(hWnd, nCmdShow);	//display the window
    //Initialize: Direct3D
		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
            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
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,


Share this post

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

  • Advertisement

Important Information

By using, you agree to our community Guidelines, Terms of Use, and Privacy Policy. is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!