Python win32con.WM_CLOSE Examples

The following are 24 code examples of win32con.WM_CLOSE(). You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may also want to check out all available functions/classes of the module win32con , or try the search function .
Example #1
Source File: gui.py    From peach with Mozilla Public License 2.0 7 votes vote down vote up
def enumCallback(hwnd, self):
            title = win32gui.GetWindowText(hwnd)

            for name in self.WindowNames:
                if title.find(name) > -1:
                    try:
                        self.FoundWindowEvent.set()

                        if self.CloseWindows:
                            win32gui.PostMessage(hwnd, win32con.WM_CLOSE, 0, 0)
                    except:
                        pass
                else:
                    try:
                        win32gui.EnumChildWindows(hwnd, _WindowWatcher.enumChildCallback, self)
                    except:
                        pass

            return True 
Example #2
Source File: desktopmanager.py    From ironpython2 with Apache License 2.0 6 votes vote down vote up
def get_new_desktop_name(parent_hwnd):
    """ Create a dialog box to ask the user for name of desktop to be created """
    msgs={win32con.WM_COMMAND:desktop_name_dlgproc,
          win32con.WM_CLOSE:desktop_name_dlgproc,
          win32con.WM_DESTROY:desktop_name_dlgproc}
    # dlg item [type, caption, id, (x,y,cx,cy), style, ex style
    style=win32con.WS_BORDER|win32con.WS_VISIBLE|win32con.WS_CAPTION|win32con.WS_SYSMENU  ## |win32con.DS_SYSMODAL
    h=win32gui.CreateDialogIndirect(
        win32api.GetModuleHandle(None),
        [['One ugly dialog box !',(100,100,200,100),style,0],
         ['Button','Create', win32con.IDOK, (10,10,30,20),win32con.WS_VISIBLE|win32con.WS_TABSTOP|win32con.BS_HOLLOW|win32con.BS_DEFPUSHBUTTON],
         ['Button','Never mind', win32con.IDCANCEL, (45,10,50,20),win32con.WS_VISIBLE|win32con.WS_TABSTOP|win32con.BS_HOLLOW],
         ['Static','Desktop name:',71,(10,40,70,10),win32con.WS_VISIBLE],
         ['Edit','',72,(75,40,90,10),win32con.WS_VISIBLE]],
        parent_hwnd, msgs)     ## parent_hwnd, msgs)

    win32gui.EnableWindow(h,True)
    hcontrol=win32gui.GetDlgItem(h,72)
    win32gui.EnableWindow(hcontrol,True)
    win32gui.SetFocus(hcontrol) 
Example #3
Source File: cutthecrap.py    From fame_modules with GNU General Public License v3.0 6 votes vote down vote up
def foreach_window(self):
        def callback(hwnd, lparam):
            title = win32gui.GetWindowText(hwnd).lower()

            for window in self.to_close:
                if window in title:
                    win32gui.PostMessage(hwnd, win32con.WM_CLOSE, 0, 0)
                    print "Closed window ({})".format(title)

            for window in self.clicks:
                if window in title:
                    self._windows[hwnd] = {
                        "matches": self.clicks[window],
                        "to_click": [],
                        "buttons": []
                    }
                    try:
                        win32gui.EnumChildWindows(hwnd, self.foreach_child(), hwnd)
                    except:
                        print "EnumChildWindows failed, moving on."

                    for button_toclick in self._windows[hwnd]['to_click']:
                        for button in self._windows[hwnd]['buttons']:
                            if button_toclick in button['text']:
                                win32gui.SetForegroundWindow(button['handle'])
                                win32gui.SendMessage(button['handle'], win32con.BM_CLICK, 0, 0)
                                print "Clicked on button ({} / {})".format(title, button['text'])

                    del self._windows[hwnd]

            return True

        return callback 
Example #4
Source File: __init__.py    From pyrexecd with MIT License 6 votes vote down vote up
def initialize(klass):
        WM_RESTART = win32gui.RegisterWindowMessage('TaskbarCreated')
        klass.WM_NOTIFY = win32con.WM_USER+1
        klass.WNDCLASS = win32gui.WNDCLASS()
        klass.WNDCLASS.hInstance = win32gui.GetModuleHandle(None)
        klass.WNDCLASS.lpszClassName = 'Py_'+klass.__name__
        klass.WNDCLASS.style = win32con.CS_VREDRAW | win32con.CS_HREDRAW;
        klass.WNDCLASS.hCursor = win32gui.LoadCursor(0, win32con.IDC_ARROW)
        klass.WNDCLASS.hIcon = win32gui.LoadIcon(0, win32con.IDI_APPLICATION)
        klass.WNDCLASS.hbrBackground = win32con.COLOR_WINDOW
        klass.WNDCLASS.lpfnWndProc = {
            WM_RESTART: klass._restart,
            klass.WM_NOTIFY: klass._notify,
            win32con.WM_CLOSE: klass._close,
            win32con.WM_DESTROY: klass._destroy,
            win32con.WM_COMMAND: klass._command,
            }
        klass.CLASS_ATOM = win32gui.RegisterClass(klass.WNDCLASS)
        klass._instance = {}
        return 
Example #5
Source File: process.py    From peach with Mozilla Public License 2.0 6 votes vote down vote up
def enumChildCallback(hwnd, windowName):
            """
            Will get called by win32gui.EnumWindows, once for each
            top level application window.
            """

            try:

                # Get window title
                title = win32gui.GetWindowText(hwnd)

                # Is this our guy?
                if title.find(windowName) == -1:
                    return

                # Send WM_CLOSE message
                win32gui.PostMessage(hwnd, win32con.WM_CLOSE, 0, 0)

            except:
                pass
            #print sys.exc_info() 
Example #6
Source File: process.py    From peach with Mozilla Public License 2.0 6 votes vote down vote up
def enumChildCallback(hwnd, windowName):
            """
            Will get called by win32gui.EnumWindows, once for each
            top level application window.
            """

            try:

                # Get window title
                title = win32gui.GetWindowText(hwnd)

                # Is this our guy?
                if title.find(windowName) == -1:
                    return

                # Send WM_CLOSE message
                win32gui.PostMessage(hwnd, win32con.WM_CLOSE, 0, 0)

            except:
                pass
            #print sys.exc_info() 
Example #7
Source File: file.py    From peach with Mozilla Public License 2.0 6 votes vote down vote up
def enumCallback(hwnd, args):
            """
            Will get called by win32gui.EnumWindows, once for each
            top level application window.
            """

            proc = args[0]
            windowName = args[1]

            try:
                # Get window title
                title = win32gui.GetWindowText(hwnd)

                # Is this our guy?
                if title.find(windowName) == -1:
                    win32gui.EnumChildWindows(hwnd, FileWriterLauncherGui.enumChildCallback, args)
                    return

                # Send WM_CLOSE message
                win32gui.PostMessage(hwnd, win32con.WM_CLOSE, 0, 0)
            except:
                pass 
Example #8
Source File: file.py    From peach with Mozilla Public License 2.0 6 votes vote down vote up
def enumChildCallback(hwnd, args):
            """
            Will get called by win32gui.EnumWindows, once for each
            top level application window.
            """

            proc = args[0]
            windowName = args[1]

            try:

                # Get window title
                title = win32gui.GetWindowText(hwnd)

                # Is this our guy?
                if title.find(windowName) == -1:
                    return

                # Send WM_CLOSE message
                win32gui.PostMessage(hwnd, win32con.WM_CLOSE, 0, 0)

            except:
                pass
            #print sys.exc_info() 
Example #9
Source File: win32gui_dialog.py    From ironpython2 with Apache License 2.0 5 votes vote down vote up
def _DoCreate(self, fn):
        message_map = {
            win32con.WM_SIZE: self.OnSize,
            win32con.WM_COMMAND: self.OnCommand,
            win32con.WM_NOTIFY: self.OnNotify,
            win32con.WM_INITDIALOG: self.OnInitDialog,
            win32con.WM_CLOSE: self.OnClose,
            win32con.WM_DESTROY: self.OnDestroy,
            WM_SEARCH_RESULT: self.OnSearchResult,
            WM_SEARCH_FINISHED: self.OnSearchFinished,
        }
        dlgClassName = self._RegisterWndClass()
        template = self._GetDialogTemplate(dlgClassName)
        return fn(self.hinst, template, 0, message_map) 
Example #10
Source File: simpledialog.py    From eavatar-me with Apache License 2.0 5 votes vote down vote up
def _DoCreate(self, fn):
        message_map = {
            win32con.WM_SIZE: self.OnSize,
            win32con.WM_COMMAND: self.OnCommand,
            win32con.WM_NOTIFY: self.OnNotify,
            win32con.WM_INITDIALOG: self.OnInitDialog,
            win32con.WM_CLOSE: self.OnClose,
            win32con.WM_DESTROY: self.OnDestroy,
        }

        dlgClassName = self._RegisterWndClass()
        template = self._GetDialogTemplate(dlgClassName)
        return fn(self.hinst, template, 0, message_map) 
Example #11
Source File: notice_dlg.py    From eavatar-me with Apache License 2.0 5 votes vote down vote up
def _DoCreate(self, fn):
        message_map = {
            win32con.WM_SIZE: self.OnSize,
            win32con.WM_COMMAND: self.OnCommand,
            win32con.WM_NOTIFY: self.OnNotify,
            win32con.WM_INITDIALOG: self.OnInitDialog,
            win32con.WM_CLOSE: self.OnClose,
            win32con.WM_DESTROY: self.OnDestroy,
        }

        dlgClassName = self._RegisterWndClass()
        template = self._GetDialogTemplate(dlgClassName)
        return fn(self.hinst, template, 0, message_map) 
Example #12
Source File: console.py    From eavatar-me with Apache License 2.0 5 votes vote down vote up
def _DoCreate(self, fn):
        message_map = {
            win32con.WM_SIZE: self.OnSize,
            win32con.WM_COMMAND: self.OnCommand,
            win32con.WM_NOTIFY: self.OnNotify,
            win32con.WM_INITDIALOG: self.OnInitDialog,
            win32con.WM_CLOSE: self.OnClose,
            win32con.WM_DESTROY: self.OnDestroy,
        }

        dlgClassName = self._RegisterWndClass()
        template = self._GetDialogTemplate(dlgClassName)
        return fn(self.hinst, template, 0, message_map) 
Example #13
Source File: __init__.py    From pyrexecd with MIT License 5 votes vote down vote up
def close(self):
        self.logger.info('close')
        win32gui.PostMessage(self.hwnd, win32con.WM_CLOSE, 0, 0)
        return 
Example #14
Source File: process.py    From peach with Mozilla Public License 2.0 5 votes vote down vote up
def enumCallback(hwnd, windowName):
            """
            Will get called by win32gui.EnumWindows, once for each
            top level application window.
            """

            try:
                # Get window title
                title = win32gui.GetWindowText(hwnd)

                # Is this our guy?
                if title.find(windowName) == -1:
                    win32gui.EnumChildWindows(hwnd, FileWriterLauncherGui.enumChildCallback, windowName)
                    return

                # Send WM_CLOSE message
                win32gui.PostMessage(hwnd, win32con.WM_CLOSE, 0, 0)
            except:
                pass 
Example #15
Source File: tcp.py    From peach with Mozilla Public License 2.0 5 votes vote down vote up
def enumCallback(hwnd, windowName):
            """
            Will get called by win32gui.EnumWindows, once for each
            top level application window.
            """

            try:

                # Get window title
                title = win32gui.GetWindowText(hwnd)

                # Is this our guy?
                if title.find(windowName) == -1:
                    return

                (threadId, processId) = win32process.GetWindowThreadProcessId(hwnd)

                # Send WM_CLOSE message
                try:
                    win32gui.PostMessage(hwnd, win32con.WM_CLOSE, 0, 0)
                    win32gui.PostQuitMessage(hwnd)
                except:
                    pass

                # Give it upto 5 sec
                for i in range(100):
                    if win32process.GetExitCodeProcess(processId) != win32con.STILL_ACTIVE:
                        # Process exited already
                        return

                    time.sleep(0.25)

                try:
                    # Kill application
                    win32process.TerminateProcess(processId, 0)
                except:
                    pass
            except:
                pass 
Example #16
Source File: gui.py    From peach with Mozilla Public License 2.0 5 votes vote down vote up
def enumChildCallback(hwnd, self):
            title = win32gui.GetWindowText(hwnd)

            for name in self.WindowNames:
                if title.find(name) > -1:
                    try:
                        self.FoundWindowEvent.set()

                        if self.CloseWindows:
                            win32gui.PostMessage(hwnd, win32con.WM_CLOSE, 0, 0)
                    except:
                        pass

            return True 
Example #17
Source File: main.py    From PUBG with The Unlicense 5 votes vote down vote up
def crashwindow():
	top_windows = []
	win32gui.EnumWindows(windowEnumerationHandler, top_windows)
	for i in top_windows:
		if "BATTLEGROUNDS Crash Reporter" in i[1]:
			win32gui.PostMessage(i[0],win32con.WM_CLOSE,0,0)
			l("crash window closed")
			return True
	return False

# pyinput helper functions 
Example #18
Source File: windows.py    From airtest with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
def stop(self, appname, extra={}):
        '''appname is not used in windows interferences'''
        win32gui.SendMessage(self.HWND,win32con.WM_CLOSE,0,0) 
Example #19
Source File: dialog_base.py    From dragonfly with GNU Lesser General Public License v3.0 5 votes vote down vote up
def _dialog_build_message_map(self):
        # Collect all controls which expect callbacks.
        map = {}
        for control in self._dialog_controls:
            for message, callback in control.message_callbacks.items():
                map.setdefault(message, {})[control.id] = callback

        # Create dispatchers for each type of message.
        for message, control_callbacks in map.items():
            def dispatcher(hwnd, msg, wparam, lparam):
                id = win32api.LOWORD(wparam)
                if id in control_callbacks:
                    control_callbacks[id](hwnd, msg, wparam, lparam)
            map[message] = dispatcher

        # Add the top-level callbacks handled by the window itself.
        map.update({
                    win32con.WM_SIZE:           self.on_size,
                    win32con.WM_INITDIALOG:     self.on_init_dialog,
                    win32con.WM_GETMINMAXINFO:  self.on_getminmaxinfo,
                    win32con.WM_CLOSE:          self.on_close,
                    win32con.WM_DESTROY:        self.on_destroy,
                  })
        return map


    #-----------------------------------------------------------------------
    # Message handler methods. 
Example #20
Source File: win32rcparser_demo.py    From ironpython2 with Apache License 2.0 5 votes vote down vote up
def _DoCreate(self, fn):
        message_map = {
            win32con.WM_INITDIALOG: self.OnInitDialog,
            win32con.WM_CLOSE: self.OnClose,
            win32con.WM_DESTROY: self.OnDestroy,
            win32con.WM_COMMAND: self.OnCommand,
        }
        return fn(0, self.dlg_template, 0, message_map) 
Example #21
Source File: winprocess.py    From ironpython2 with Apache License 2.0 5 votes vote down vote up
def kill(self, gracePeriod=5000):
        """
        Kill process. Try for an orderly shutdown via WM_CLOSE.  If
        still running after gracePeriod (5 sec. default), terminate.
        """
        win32gui.EnumWindows(self.__close__, 0)
        if self.wait(gracePeriod) != win32event.WAIT_OBJECT_0:
            win32process.TerminateProcess(self.hProcess, 0)
            win32api.Sleep(100) # wait for resources to be released 
Example #22
Source File: desktopmanager.py    From ironpython2 with Apache License 2.0 5 votes vote down vote up
def desktop_name_dlgproc(hwnd,msg,wparam,lparam):
    """ Handles messages from the desktop name dialog box """
    if msg in (win32con.WM_CLOSE,win32con.WM_DESTROY):
        win32gui.DestroyWindow(hwnd)
    elif msg == win32con.WM_COMMAND:
        if wparam == win32con.IDOK:
            desktop_name=win32gui.GetDlgItemText(hwnd, 72)
            print 'new desktop name: ',desktop_name
            win32gui.DestroyWindow(hwnd)
            create_desktop(desktop_name)
            
        elif wparam == win32con.IDCANCEL:
            win32gui.DestroyWindow(hwnd) 
Example #23
Source File: debugger.py    From ironpython2 with Apache License 2.0 5 votes vote down vote up
def GUIAboutToBreak(self):
		"Called as the GUI debugger is about to get context, and take control of the running program."
		self.GUICheckInit()
		self.RespondDebuggerState(DBGSTATE_BREAK)
		self.GUIAboutToInteract()
		if self.pumping:
			print "!!! Already pumping - outa here"
			return
		self.pumping = 1
		win32ui.StartDebuggerPump() # NOTE - This will NOT return until the user is finished interacting
		assert not self.pumping, "Should not be pumping once the pump has finished"
		if self.frameShutdown: # User shut down app while debugging
			win32ui.GetMainFrame().PostMessage(win32con.WM_CLOSE) 
Example #24
Source File: winapi.py    From gui-o-matic with GNU Lesser General Public License v3.0 4 votes vote down vote up
def __init__(self, title, style,
                 size = (win32con.CW_USEDEFAULT,
                         win32con.CW_USEDEFAULT),
                 messages = {}):
        '''Setup a window class and a create window'''
        self.layers = []
        self.module_handle = win32gui.GetModuleHandle(None)
        self.systray = False
        self.systray_map = {
            win32con.WM_RBUTTONDOWN: self._show_menu
            }
        
        # Setup window class
        #
        self.window_class_name = self._make_window_class_name()
        self.message_map = {
             win32con.WM_PAINT: self._on_paint,
             win32con.WM_CLOSE: self._on_close,
             win32con.WM_COMMAND: self._on_command,
             self._notify_event_id: self._on_notify,
             }
        self.message_map.update( messages )
        self.window_class = win32gui.WNDCLASS()
        self.window_class.style = win32con.CS_HREDRAW | win32con.CS_VREDRAW
        self.window_class.lpfnWndProc = self.message_map
        self.window_class.hInstance = self.module_handle
        self.window_class.hCursor = win32gui.LoadCursor( None, win32con.IDC_ARROW )
        self.window_class.hbrBackground = win32con.COLOR_WINDOW
        self.window_class.lpszClassName = self.window_class_name
            
        self.window_classHandle = win32gui.RegisterClass( self.window_class )

        self.window_handle = win32gui.CreateWindow(
            self.window_class_name,
            title,
            style,
            win32con.CW_USEDEFAULT,
            win32con.CW_USEDEFAULT,
            size[ 0 ],
            size[ 1 ],
            None,
            None,
            self.module_handle,
            None )