mkv

chromeplug

mkv
Mar 4th, 2018
639
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 3.86 KB | None | 0 0
  1. #!/usr/bin/env python2
  2. # -*- coding: utf-8 -*-
  3. from __future__ import print_function
  4.  
  5.  
  6. from ctypes import windll, WINFUNCTYPE, POINTER, c_bool, c_int, create_unicode_buffer
  7.  
  8.  
  9. EnumWindows = windll.user32.EnumWindows
  10. EnumChildWindows = windll.user32.EnumChildWindows
  11.  
  12. SetWindowPos = windll.user32.SetWindowPos
  13. GetWindowLong = windll.user32.GetWindowLongA
  14. SetWindowLong = windll.user32.SetWindowLongA
  15. SetLayeredWindowAttributes = windll.user32.SetLayeredWindowAttributes
  16.  
  17. EnumWindowsProc = WINFUNCTYPE(c_bool, POINTER(c_int), POINTER(c_int))
  18. GetWindowText = windll.user32.GetWindowTextW
  19. GetWindowTextLength = windll.user32.GetWindowTextLengthW
  20. IsWindowVisible = windll.user32.IsWindowVisible
  21.  
  22.  
  23. windows = []
  24. def foreach_window(hwnd, lParam):
  25.     if IsWindowVisible(hwnd):
  26.         length = GetWindowTextLength(hwnd)
  27.         buff = create_unicode_buffer(length + 1)
  28.         GetWindowText(hwnd, buff, length + 1)
  29.         windows.append([hwnd, buff.value])
  30.     return True
  31.  
  32.  
  33. subwindows = []
  34. def foreach_subwindow(hwnd, lParam):
  35.     if IsWindowVisible(hwnd):
  36.         length = GetWindowTextLength(hwnd)
  37.         buff = create_unicode_buffer(length + 1)
  38.         GetWindowText(hwnd, buff, length + 1)
  39.         subwindows.append([hwnd, buff.value])
  40.     return True
  41.  
  42.  
  43. del windows[:]
  44. EnumWindows(EnumWindowsProc(foreach_window), 0)
  45.  
  46.  
  47. for hwnd, title in windows:
  48.     if 'Index of /dev/' in title:
  49.         print(hwnd, title)
  50.         if False:
  51.             # try to resize the entire window in fullscreen,
  52.             # works but bounces back on mouseover
  53.             SWP_NOZORDER = 0x0004
  54.             SWP_NOACTIVATE = 0x0010
  55.             SWP_NOSENDCHANGING = 0x0400
  56.             SWP_NOREPOSITION = 0x0200
  57.             SetWindowPos(hwnd, None, 256, 128, 512, 384,
  58.                 SWP_NOZORDER + SWP_NOACTIVATE + SWP_NOSENDCHANGING)
  59.             break
  60.        
  61.         else:
  62.             # "c:\Program Files (x86)\Google\Chrome\Application\chrome.exe" --app=https://ocv.me/dev/
  63.             #
  64.             GWL_STYLE     = -16;
  65.             WS_BORDER     = 0x800000; # has border
  66.             WS_DLGFRAME   = 0x400000; # has double border but no title
  67.             WS_CAPTION    = WS_BORDER + WS_DLGFRAME; # has title bar
  68.  
  69.             style = GetWindowLong(hwnd, GWL_STYLE)
  70.             style = style & ~WS_CAPTION
  71.            
  72.             SetWindowLong(hwnd, GWL_STYLE, style)
  73.                
  74.             # resize the window to trigger a redraw by chrome
  75.             SWP_NOACTIVATE = 0x0010
  76.             SWP_NOZORDER = 0x0004
  77.             SWP_NOMOVE = 0x0002
  78.             SWP_NOSIZE = 0x0001
  79.             SetWindowPos(hwnd, None, 256, 512, 1024, 768, \
  80.                 SWP_NOACTIVATE + \
  81.                 SWP_NOZORDER)
  82.             break
  83.  
  84.         del subwindows[:]
  85.         EnumChildWindows(hwnd, EnumWindowsProc(foreach_subwindow), 0)
  86.         for n, (hwnd2, title2) in enumerate(subwindows, 1):
  87.             #SetWindowPos(hwnd2, None, n * 256, n * 128, n * 512, n * 384, 0x4+0x400+0x200+0x10)
  88.            
  89.             if False:
  90.                 # move inner window up, works but mouse is off
  91.                 SWP_NOZORDER = 0x0004
  92.                 SWP_NOSENDCHANGING = 0x0400
  93.                 SWP_NOREPOSITION = 0x0200
  94.                 SWP_NOACTIVATE = 0x0010
  95.                 SWP_NOMOVE = 0x0002
  96.                 SWP_NOSIZE = 0x0001
  97.                 if n == 2:
  98.                     SetWindowPos(hwnd2, None, 0, -85, 0, 0, \
  99.                         SWP_NOZORDER + \
  100.                         SWP_NOACTIVATE + \
  101.                         SWP_NOSIZE)
  102.                     return
  103.             elif False:
  104.                 # set alpha of parent window, implementation error causes border to become fully black instead
  105.                 LWA_KEY = 1;
  106.                 LWA_ALPHA = 2;
  107.                 # bool SetLayeredWindowAttributes(
  108.                 #   IntPtr hWnd, uint crKey, byte bAlpha, uint dwFlags);
  109.        
  110.                 GWL_STYLE     = -16;
  111.                 GWL_EXSTYLE   = -20;
  112.                 WS_EX_LAYERED = 0x80000;
  113.                 WS_CHILD      = 0x40000000;
  114.                 WS_BORDER     = 0x800000; # has border
  115.                 WS_DLGFRAME   = 0x400000; # has double border but no title
  116.                 WS_CAPTION    = WS_BORDER + WS_DLGFRAME; # has title bar
  117.                
  118.                 # SetLayeredWindowAttributes(
  119.                 #   hwnd, 0, (byte)opac, LWA_ALPHA)
  120.                 if n == 2:
  121.                     wcfg = GetWindowLong(hwnd2, GWL_EXSTYLE)
  122.                     print(wcfg)
  123.                     #continue
  124.                     wcfg = wcfg ^ WS_EX_LAYERED
  125.                     print(wcfg)
  126.                     #continue
  127.                     SetWindowLong(hwnd2, GWL_EXSTYLE, wcfg)
  128.                     SetLayeredWindowAttributes(hwnd2, 0, LWA_ALPHA)
  129.                     return
Advertisement
Add Comment
Please, Sign In to add comment