closing the splash-screen when any keyboard key is pressed
-
In my start-up i have a splash-screen which waits for 30 seconds and then the main application starts up. Now i have to do this :-- Within this interval if any keyboard key is pressed i want to hide/close the splash-screeen and move to the application directly I have implemented the splash-screen as : BOOL CSplashWnd::ShowSplashScreen(UINT uTimeOut, UINT uBitmapID, CWnd* pParentWnd /*= NULL*/) { ASSERT(uTimeOut && uBitmapID); if (!m_bShowSplashWnd || m_pSplashWnd != NULL) { return FALSE; } // Allocate a new splash screen, and create the window. m_pSplashWnd = new CSplashWnd; if (!m_pSplashWnd->m_bitmap.LoadBitmap(uBitmapID)) { return FALSE; } BITMAP bm; m_pSplashWnd->m_bitmap.GetBitmap(&bm); CString strWndClass = AfxRegisterWndClass(0, AfxGetApp()->LoadStandardCursor(IDC_ARROW)); if (!m_pSplashWnd->CreateEx(0, strWndClass, NULL, WS_POPUP | WS_VISIBLE, 0, 0, bm.bmWidth, bm.bmHeight, pParentWnd->GetSafeHwnd(), NULL)) { TRACE0("Failed to create splash screen.\n"); delete m_pSplashWnd; return FALSE; } // Center the window. m_pSplashWnd->CenterWindow(); m_pSplashWnd->UpdateWindow(); // Set a timer to destroy the splash screen. m_pSplashWnd->SetTimer(1, uTimeOut, NULL); return TRUE; } where CSplashWnd is derived from CWnd Can any body plz tell me how to do it?
-
In my start-up i have a splash-screen which waits for 30 seconds and then the main application starts up. Now i have to do this :-- Within this interval if any keyboard key is pressed i want to hide/close the splash-screeen and move to the application directly I have implemented the splash-screen as : BOOL CSplashWnd::ShowSplashScreen(UINT uTimeOut, UINT uBitmapID, CWnd* pParentWnd /*= NULL*/) { ASSERT(uTimeOut && uBitmapID); if (!m_bShowSplashWnd || m_pSplashWnd != NULL) { return FALSE; } // Allocate a new splash screen, and create the window. m_pSplashWnd = new CSplashWnd; if (!m_pSplashWnd->m_bitmap.LoadBitmap(uBitmapID)) { return FALSE; } BITMAP bm; m_pSplashWnd->m_bitmap.GetBitmap(&bm); CString strWndClass = AfxRegisterWndClass(0, AfxGetApp()->LoadStandardCursor(IDC_ARROW)); if (!m_pSplashWnd->CreateEx(0, strWndClass, NULL, WS_POPUP | WS_VISIBLE, 0, 0, bm.bmWidth, bm.bmHeight, pParentWnd->GetSafeHwnd(), NULL)) { TRACE0("Failed to create splash screen.\n"); delete m_pSplashWnd; return FALSE; } // Center the window. m_pSplashWnd->CenterWindow(); m_pSplashWnd->UpdateWindow(); // Set a timer to destroy the splash screen. m_pSplashWnd->SetTimer(1, uTimeOut, NULL); return TRUE; } where CSplashWnd is derived from CWnd Can any body plz tell me how to do it?
Well one simple solution would be using WM_KEYDOWN message or OnKeyDown() in MFC which i hope you already know. Another way out is to use Keyboard Hook. When the splash screen is created, create a keyboard hook and use a callback function to trap any(really any) key pressed. Destroy the Splash Screen window in the callback function. And also don't forget to unhook the Keyboard callback as soon as the splash screen is destroyed (important). Refer to following functions in MSDN: SetWindowsHookEx() KeyboardProc() UnhookWindowsHookEx()