[python-win32] OnCtlColor not working?

Mike Driscoll mdriscoll at co.marshall.ia.us
Mon Mar 2 15:18:01 CET 2009


Greg Ewing wrote:
> <div class="moz-text-flowed" style="font-family: -moz-fixed">Has 
> anyone successfully used the PyCWnd.OnCtlColor
> virtual function to change the appearance of a
> control?
>
> The program below tries to use it to set the colour
> of the text in a PyCButton. My OnCtlColor method gets
> called, but it doesn't have any effect on the appearance
> of the button.
>
> Also, if I attempt to return a PyCBrush from the
> OnCtlColor method as the docs suggest, I get
> "TypeError: An integer is required" errors.
>
> Am I doing something wrong?
>
> #-------------------------------------------------------------------------------- 
>
>
> import win32con, win32ui
> from pywin.mfc.object import Object
>
> class MyFrame(Object):
>
>     def OnCtlColor(self, dc, btn, typ):
>         print "MyFrame.OnCtlColor:", self ###
>         dc.SetTextColor(0x0000ff)
>         # Doing the following causes "TypeError: An integer is required"
>         #b = win32ui.CreateBrush()
>         #b.CreateSolidBrush(0x00ff00)
>         #return b
>
> frame = MyFrame(win32ui.CreateFrame())
> frame.CreateWindow(None, "Test", win32con.WS_CAPTION,
>     (100, 100, 300, 300))
> button = win32ui.CreateButton()
> style = win32con.BS_CHECKBOX
> button.CreateWindow("Hello", style, (20, 20, 100, 40),
>     frame, 0)
> button.ShowWindow(win32con.SW_SHOW)
> frame.ShowWindow()
> app = win32ui.GetApp()
> app.Run()
>
> #-------------------------------------------------------------------------------- 
>
>

I'm probably being naive, but why don't you just use one of Python 
excellent GUI toolkits? You'll get cross-platform code out of the box, 
if you're careful with Tkinter and wxPython...

IronPython may be helpful too since you can use Visual Studio to layout 
your application and IronPython to control it.

-------------------
Mike Driscoll

Blog:   http://blog.pythonlibrary.org
Python Extension Building Network:     http://www.pythonlibrary.org



More information about the python-win32 mailing list