win32gui DialogBox

lohgan at my-deja.com lohgan at my-deja.com
Mon Jun 19 04:54:00 EDT 2000


Hi all.  I'm attempting to open a dialog box on a click event from a
task bar icon.  I do not have much experience with Win32 programming
and am experiencing unexpected results.

I load the dialog template from a resource only DLL.  Then when I try
to show the dialog box, the function "DialogBox" blocks after handling
the message "WM_INITDIALOG".  The main and child (dialog) windows
freeze up as if the message loop is broken.  When I double click on the
task bar icon and the WM_QUIT message gets posted, all the blocked
DialogBox functions release control.

I hope this is something stupid like simply needing another message
loop somewhere.

Any help is appreciated.  Please CC me on responses.  Mail me
personally if you wish a copy of 'Resources.dll' and other files.

Thanks,
-Sean

---> application.py
from win32api import *
from win32gui import *
import win32con

class MainWindow:
    def __init__(self):
        self.message_map = {
            win32con.WM_DESTROY: self.OnDestroy,
            win32con.WM_USER+20 : self.OnTaskbarNotify,
        }

        # Register the Window class.
        wc = WNDCLASS()
        hinst = wc.hInstance = GetModuleHandle(None)
        wc.lpszClassName = "PythonTaskbarDemo"
        wc.style = win32con.CS_VREDRAW | win32con.CS_HREDRAW;
        wc.hCursor = LoadCursor( 0, win32con.IDC_ARROW )
        wc.hbrBackground = win32con.COLOR_WINDOW
        wc.lpfnWndProc = self.message_map # could also specify a
wndproc.
        classAtom = RegisterClass(wc)

        # Create the Window.
        style = win32con.WS_OVERLAPPED | win32con.WS_SYSMENU
        self.hwnd = CreateWindow( classAtom, "Taskbar Demo", style, \
                 0, 0, win32con.CW_USEDEFAULT, win32con.CW_USEDEFAULT, \
                 0, 0, hinst, None)
        UpdateWindow(self.hwnd)
        ShowWindow(self.hwnd, win32con.SW_SHOW)

        # Add the taskbar icon
        hicon = LoadIcon(0, win32con.IDI_APPLICATION)
        flags = NIF_ICON | NIF_MESSAGE | NIF_TIP
        nid = (self.hwnd, 0, flags, win32con.WM_USER+20, hicon, "Python
Demo")
        Shell_NotifyIcon(NIM_ADD, nid)

    def OnDestroy(self, hwnd, msg, wparam, lparam):
        nid = (self.hwnd, 0)
        Shell_NotifyIcon(NIM_DELETE, nid)
        PostQuitMessage(0) # Terminate the app.

    def OnTaskbarNotify(self, hwnd, msg, wparam, lparam):
        if lparam==win32con.WM_LBUTTONUP:
            print "You clicked me."
            try:
                import ui_preferences
                prefs = ui_preferences.UIPreferences(self.hwnd)
            except:
                import sys, traceback
                traceback.print_exc(file=sys.stdout)
            print "Should be loaded?"
        elif lparam==win32con.WM_LBUTTONDBLCLK:
            print "You double-clicked me - goodbye"
            PostQuitMessage(0)
        return 1

---> ui_preferences.py
from win32api import *
from win32gui import *
import win32con

RESOURCE_FILE = 'Resources.dll'
ID_DIALOG = 106
ID_ICON = 101

ID_USERNAME = 1002
ID_PASSWORD = 1003
ID_CLOSE = 1000

class UIPreferences:
    def __init__(self, parentHWND):
        message_map = {
            win32con.WM_INITDIALOG: self.InitDialog,
            win32con.WM_DESTROY: self.OnDestroy,
        }

        self.parentHWND = parentHWND
        self.res = LoadLibrary(RESOURCE_FILE)
        self.id_dlg = DialogBox(self.res, ID_DIALOG, self.parentHWND,
message_map)
        print "ID:", self.id_dlg
        print "LastError", GetLastError()

    def InitDialog(self, hwnd, msg, wparam, lparam):
        print "InitDialog"
        return 1

    def OnDestroy(self, hwnd, msg, wparam, lparam):
        return 1




Sent via Deja.com http://www.deja.com/
Before you buy.



More information about the Python-list mailing list