in reply to Re^4: Disable Control in Win32::GUI
in thread Disable Control in Win32::GUI

The greying of disabled controls is performed by the OS itself. You say it's disabled and the OS uses the appropriate colors as defined in the system palette to display them. These colors are system wide and whilst you can change them, you would affect all other apps on the desktop which isn't very freindly.

The second alternative is to create your own application palette that has the same colors for disabled controls as for enabled, and then realize that palette when required. This is a lot of work, and Win32::Gui doesn't support these functions, so you would have to use Win32::API to get at them.

A third alternative would be to place a transparent window that does nothing over the top of the control that you wish to disable. This transparent window would serve to prevent the user from clicking on the control, by intercepting the clicks and discarding them. Teh fly in that ointment is that you would also have to arrange for focus changes caused by keyboard input (tabbing) to be intercepted. Again, quite a lot of work involved, though I think Win32::Gui gives you most of what you need to do this.

A fourth possibility would be to intercept the WM_DISABLE message for the control, do a grab of the bits of the window, pass the disable message through to the system so that all it's associated functions happen. You would also intercept the WM_PAINT message and blit the bits you grabbed earlier back onto the screen when the control redraws. This is fairly simple to do, though again, I think you would probably need to use Win32::API to get at some of the functions required. It may also cause some flashing of the disabled controls when they are redrawn unless you do it correctly.

There may be another simpler method, but I am not aware of it.

All in all, doing any of these is non-trivial, and of course prompts the question, why? Why would you want to have a disabled control masquerade as enabled?


Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
Lingua non convalesco, consenesco et abolesco. -- Rule 1 has a caveat! -- Who broke the cabal?
"Science is about questioning the status quo. Questioning authority".
In the absence of evidence, opinion is indistinguishable from prejudice.

Replies are listed 'Best First'.
Re^6: Disable Control in Win32::GUI
by ChrisR (Hermit) on Dec 20, 2005 at 02:42 UTC
    Thanks for the good information. I was unaware that there was that much to it. I will give your fourth option some thought/research/testing.

    As for the why, I have been playing around with a wysiwyg gui designer. It's mainly for my own education and practice. In a previous life, I did a lot of VB programming and really liked the IDE so I thought I'd take a stab at creating one for perl and win32::gui. I know this has been done but I learn the most while re-creating the wheel.

    Again, thanks for taking the time to reply and supply useful information .

      It sounds like you are aware of The GUI Loft, so I suggest you take a look at how it's done in the Design window (drawing on a Graphic control).

      /J

        Thanks. I am aware of the Loft and tried it out some time ago when I had absolutely no understanding of Win32::GUI. I felt that I had to learn to hand code the windows or I would never get very far. That is what prompted me to try this now that I know at least a little about Win32::GUI. I've been trying not to look at the Loft so that I may find my own way and learn more. I may find very soon that I am in over my head and dig into your code.