Advertisement
Guest User

eqswitch

a guest
Dec 20th, 2014
203
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 4.19 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <tchar.h>
  3. #include <windows.h>
  4. #include <winuser.h>
  5. #include <string>
  6. #include <sstream>
  7.  
  8.  
  9. void SetForegroundWindowInternal(HWND hWnd)
  10. {
  11.  if(!::IsWindow(hWnd)) return;
  12.  
  13.  BYTE keyState[256] = {0};
  14.  //to unlock SetForegroundWindow we need to imitate Alt pressing
  15.  if(::GetKeyboardState((LPBYTE)&keyState))
  16.  {
  17.   if(!(keyState[VK_MENU] & 0x80))
  18.   {
  19.    ::keybd_event(VK_MENU, 0, KEYEVENTF_EXTENDEDKEY | 0, 0);
  20.   }
  21.  }
  22.  
  23.  ::SetForegroundWindow(hWnd);
  24.  
  25.  if(::GetKeyboardState((LPBYTE)&keyState))
  26.  {
  27.   if(!(keyState[VK_MENU] & 0x80))
  28.   {
  29.    ::keybd_event(VK_MENU, 0, KEYEVENTF_EXTENDEDKEY | KEYEVENTF_KEYUP, 0);
  30.   }
  31.  }
  32. }
  33.  
  34.  
  35. void EnableDebugPriv( )
  36.  {
  37.     HANDLE hToken;
  38.     LUID sedebugnameValue;
  39.     TOKEN_PRIVILEGES tkp;
  40.     OpenProcessToken( GetCurrentProcess( ), TOKEN_ADJUST_PRIVILEGES |TOKEN_QUERY, &hToken );
  41.     LookupPrivilegeValue( NULL, SE_DEBUG_NAME, &sedebugnameValue );
  42.     tkp.PrivilegeCount = 1;tkp.Privileges[0].Luid = sedebugnameValue;
  43.     tkp.Privileges[0].Attributes = SE_PRIVILEGE_ENABLED;
  44.     AdjustTokenPrivileges( hToken, false, &tkp, sizeof( tkp ), NULL, NULL );
  45.     CloseHandle( hToken );
  46.  }
  47.  
  48.  
  49. int main()
  50. {      
  51.  //Find each EQ Window and set to appropriate name
  52.  //1. First ask how many EQ windows will be open
  53.  DWORD pId;
  54.  int x = 0;
  55.  int numOfWindows = 0;
  56.  printf("Please enter # of EQ instances");
  57.  scanf ("%d",&numOfWindows);
  58.  EnableDebugPriv();
  59.  
  60.  //Loop through each instance and set all but first new names
  61.  //x<numOfWindows - 1 so you always leave 1 with original name
  62.  for(x=0; x<numOfWindows-1; x++)
  63.  {
  64.   HWND hWindow = FindWindow(NULL,"EQW beta 2.32");
  65.   if(!hWindow)
  66.   {
  67.    printf("EQ window not found\n");
  68.    system( "pause" );
  69.    return 0;
  70.   }
  71.   else
  72.   {
  73.      GetWindowThreadProcessId(hWindow, &pId);
  74.      HANDLE hOpen = OpenProcess( PROCESS_ALL_ACCESS, false, pId );
  75.      if(!hOpen)
  76.      {
  77.       printf("Cannot open process.");
  78.      system( "pause" );
  79.      return 1;
  80.      }
  81.      else
  82.      {
  83.       std::string name = "EQWindow";
  84.       std::ostringstream convert;
  85.       convert << x+1;
  86.       name += convert.str();
  87.       char *charName = new char[name.size()+1];
  88.       charName[name.size()] = 0;
  89.       memcpy(charName,name.c_str(),name.size());
  90.       SetWindowText(hWindow, charName);
  91.      }
  92.   }
  93.  }
  94.    
  95.  
  96.  
  97.  enum{ZERO_KEYID = 0, ONE_KEYID = 1, TWO_KEYID = 2, THREE_KEYID = 3, FOUR_KEYID = 4, FIVE_KEYID = 5};
  98.  RegisterHotKey(0, ZERO_KEYID, 0, 0x60); // register NumPad0 key as hotkey
  99.  RegisterHotKey(0, ONE_KEYID, 0, 0x61); // register NumPad1 key as hotkey
  100.  RegisterHotKey(0, TWO_KEYID, 0, 0x64); // register NumPad4 key as hotkey
  101.  RegisterHotKey(0, THREE_KEYID, 0, 0x67); // register NumPad7 key as hotkey
  102.  RegisterHotKey(0, FOUR_KEYID, 0, 0x62); // register NumPad2 key as hotkey
  103.  RegisterHotKey(0, FIVE_KEYID, 0, 0x68); // register NumPad8 key as hotkey
  104.  MSG msg;
  105.        
  106.  HWND eqWindow0 = FindWindow(NULL, "EQW beta 2.32");//Change window title name here
  107.  HWND eqWindow1 = FindWindow(NULL, "EQWindow1");//example: "Untitled - Notepad"
  108.  HWND eqWindow2 = FindWindow(NULL, "EQWindow2");
  109.  HWND eqWindow3 = FindWindow(NULL, "EQWindow3");
  110.  HWND eqWindow4 = FindWindow(NULL, "EQWindow4");
  111.  HWND eqWindow5 = FindWindow(NULL, "EQWindow5");
  112.    
  113.  //The while loop which waits for a keypress to then switch windows
  114.  while(GetMessage(&msg, 0, 0, 0))
  115.  {
  116.   PeekMessage(&msg, 0, 0, 0, 0x0001);
  117.   switch(msg.message)
  118.   {
  119.   case WM_HOTKEY:
  120.    if(msg.wParam == ZERO_KEYID)
  121.    {
  122.     SetForegroundWindowInternal(eqWindow0);
  123.     printf("Activated Window 0\n");
  124.    }
  125.    if(msg.wParam == ONE_KEYID)
  126.    {
  127.     SetForegroundWindowInternal(eqWindow1);
  128.     printf("Activated Window 1\n");
  129.    }
  130.    if(msg.wParam == TWO_KEYID)
  131.    {
  132.     SetForegroundWindowInternal(eqWindow2);
  133.     printf("Activated Window 2\n");
  134.    }
  135.    if(msg.wParam == THREE_KEYID)
  136.    {
  137.     SetForegroundWindowInternal(eqWindow3);
  138.     printf("Activated Window 3\n");
  139.    }
  140.    if(msg.wParam == FOUR_KEYID)
  141.    {
  142.     SetForegroundWindowInternal(eqWindow4);
  143.     printf("Activated Window 4\n");
  144.    }
  145.    if(msg.wParam == FIVE_KEYID)
  146.    {
  147.     SetForegroundWindowInternal(eqWindow5);
  148.     printf("Activated Window 5\n");
  149.    }
  150.   }
  151.  }
  152.  return 0;
  153. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement