Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. Can't Activate Window C++ [modified]

Can't Activate Window C++ [modified]

Scheduled Pinned Locked Moved C / C++ / MFC
c++business
4 Posts 4 Posters 1 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • S Offline
    S Offline
    sogou09
    wrote on last edited by
    #1

    Hi Guys I have a business full screen appliection (A.exe) run in Windows 98. I need a hotkey when the appliection is running,Press SPACE key ,Excute a Dialog based program "C.EXE". I try to use "RegisterHotKey" function ,But the hot key does not work. Now I try to use Keyboard hook, I create a Dialog based program "B.exe" and "B.dll",When "B.exe" excuted,It launched hook callback function in "B.dll". Excute Sequence :B.exe A.exe when A.exe is running ,I press SPACE key,the hook function catch the keyboard message, it call C.exe (use the "ShellExcute"),The window of C.exe appear. Qustion: The window of "C.exe" isn't current active window.the window of "A.exe" is active windows yet! I need the window of C.exe is active when it appeared.

    LRESULT CALLBACK LowLevelKeyboardProc(int nCode, WPARAM wParam, LPARAM lParam)
    {
    BOOL fEatKeystroke = FALSE;
    PKBDLLHOOKSTRUCT p = NULL;
    if (nCode == HC_ACTION)
    {
    p = (PKBDLLHOOKSTRUCT) lParam;
    switch (wParam)
    {
    case WM_KEYDOWN:
    if (p->vkCode == VK_SPACE)
    {
    return 1;
    }
    break;
    case WM_KEYUP:

    			if (p->vkCode == VK\_SPACE)
    			{
    				ShellExecute(NULL,"open","C:\\\\C.exe",NULL,NULL,SW\_SHOW);
    				HWND h=FindWindow(NULL,"Caption of C");
    				if(h) 
                                          {
                                                ShowWindow(h,SW\_SHOW);
                                          }
                                          return 1;
    			}
    			break;	
    		default:
    			break;
     		}
    	
    }
    return (CallNextHookEx(glhHook,nCode,wParam,lParam));
    

    }

    void _stdcall StartKeyMask()
    {
    glhHook = SetWindowsHookEx(WH_KEYBOARD_LL,LowLevelKeyboardProc,glhInstance,0);
    }

    void _stdcall StopKeyMask()
    {
    if (glhHook!=NULL)
    UnhookWindowsHookEx(glhHook);
    }

    modified on Sunday, February 22, 2009 10:53 AM

    D 1 Reply Last reply
    0
    • S sogou09

      Hi Guys I have a business full screen appliection (A.exe) run in Windows 98. I need a hotkey when the appliection is running,Press SPACE key ,Excute a Dialog based program "C.EXE". I try to use "RegisterHotKey" function ,But the hot key does not work. Now I try to use Keyboard hook, I create a Dialog based program "B.exe" and "B.dll",When "B.exe" excuted,It launched hook callback function in "B.dll". Excute Sequence :B.exe A.exe when A.exe is running ,I press SPACE key,the hook function catch the keyboard message, it call C.exe (use the "ShellExcute"),The window of C.exe appear. Qustion: The window of "C.exe" isn't current active window.the window of "A.exe" is active windows yet! I need the window of C.exe is active when it appeared.

      LRESULT CALLBACK LowLevelKeyboardProc(int nCode, WPARAM wParam, LPARAM lParam)
      {
      BOOL fEatKeystroke = FALSE;
      PKBDLLHOOKSTRUCT p = NULL;
      if (nCode == HC_ACTION)
      {
      p = (PKBDLLHOOKSTRUCT) lParam;
      switch (wParam)
      {
      case WM_KEYDOWN:
      if (p->vkCode == VK_SPACE)
      {
      return 1;
      }
      break;
      case WM_KEYUP:

      			if (p->vkCode == VK\_SPACE)
      			{
      				ShellExecute(NULL,"open","C:\\\\C.exe",NULL,NULL,SW\_SHOW);
      				HWND h=FindWindow(NULL,"Caption of C");
      				if(h) 
                                            {
                                                  ShowWindow(h,SW\_SHOW);
                                            }
                                            return 1;
      			}
      			break;	
      		default:
      			break;
       		}
      	
      }
      return (CallNextHookEx(glhHook,nCode,wParam,lParam));
      

      }

      void _stdcall StartKeyMask()
      {
      glhHook = SetWindowsHookEx(WH_KEYBOARD_LL,LowLevelKeyboardProc,glhInstance,0);
      }

      void _stdcall StopKeyMask()
      {
      if (glhHook!=NULL)
      UnhookWindowsHookEx(glhHook);
      }

      modified on Sunday, February 22, 2009 10:53 AM

      D Offline
      D Offline
      Dr Emmett Brown
      wrote on last edited by
      #2

      You can try with SetForegroundWindow[^]

      Doc

      G 1 Reply Last reply
      0
      • D Dr Emmett Brown

        You can try with SetForegroundWindow[^]

        Doc

        G Offline
        G Offline
        guamp
        wrote on last edited by
        #3

        use " SetForegroundWindow" no effect thank you

        G 1 Reply Last reply
        0
        • G guamp

          use " SetForegroundWindow" no effect thank you

          G Offline
          G Offline
          Graham Bradshaw
          wrote on last edited by
          #4

          guamp wrote:

          use " SetForegroundWindow" no effect

          See http://blogs.msdn.com/oldnewthing/archive/2009/02/20/9435239.aspx[^] for a possible explanation.

          1 Reply Last reply
          0
          Reply
          • Reply as topic
          Log in to reply
          • Oldest to Newest
          • Newest to Oldest
          • Most Votes


          • Login

          • Don't have an account? Register

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • World
          • Users
          • Groups