Jump to content

WM_COMMAND and ColorPicker UDF Conflict


Recommended Posts

Hello!

I've been using Yashied's wonderful ColorPicker UDF for a portion of my program.

It says right in it that:

"The library registers (permanently) the following window messages: WM_ACTIVATE, WM_COMMAND, WM_MOUSEWHEEL, WM_SETCURSOR."

My trouble is that a different portion of my program (Search Function) was already using WM_COMMAND, so when I stick the two portions together, I can either make the ColorPicker work, or I can make the search function work.

This is the portion of my code that doesn't get along with the ColorPicker:

Func WM_COMMAND($hWnd, $iMsg, $wParam, $lParam) ;search function primer
   #forceref $hWnd, $iMsg
   Local $hWndFrom, $iIDFrom, $iCode
   $hWndFrom = $lParam
   $iIDFrom = BitAND($wParam, 0xFFFF)
   $iCode = BitShift($wParam, 16)
   Switch $iIDFrom
   Case $Search_Field
      Switch $iCode
         Case $EN_CHANGE 
            If GUICtrlRead($Search_Field) <> "" Then
               ConsoleWrite("Search Item 1: " & GUICtrlRead($Search_Field) & @CRLF)
               Search_Function()
            EndIf
      EndSwitch
   EndSwitch
   Return $GUI_RUNDEFMSG
EndFunc

If I leave it in, I can't pick colors. If I take it out, I can't search.

Does anyone have any idea how to make them get along?

Link to comment
Share on other sites

Does that UDF do anything more than the included UDF _ChooseColor?

If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Link to comment
Share on other sites

@BrewManNH

Instead of creating a whole dialogue box like _ChooseColor does, the ColorPicker creates a nice little ToolTip-esque 2D matrix of color samples that a user can click.

 

@faustf

My script is over 4000 lines long. Let me see what I can cut to make a smaller example.

Link to comment
Share on other sites

@faustf

Here's a sample:

Opt("GUIOnEventMode", 1)
#include <GUIConstants.au3>
#include <MsgBoxConstants.au3>
#Include <ColorPicker.au3>

#Region Color Palette
Dim $aPalette[64] = _
   [0xFFFFFF, 0xFFDDDD, 0xFDF0DF, 0xFFFFDD, 0xDDFFDD, 0xDDFFFF, 0xDDDDFF, 0xFFDDFF, _
    0xEEEEEE, 0xFFCCCC, 0xFCE6BF, 0xFFFFCC, 0xCCFFCC, 0xCCFFFF, 0xCCCCFF, 0xFFCCFF, _
    0xDDDDDD, 0xFFBBBB, 0xFBDA9F, 0xFFFFBB, 0xBBFFBB, 0xBBFFFF, 0xBBBBFF, 0xFFBBFF, _
    0xCCCCCC, 0xFFAAAA, 0xFACE7F, 0xFFFFAA, 0xAAFFAA, 0xAAFFFF, 0xAAAAFF, 0xFFAAFF, _
    0xBBBBBB, 0xFF9999, 0xF9C15F, 0xFFFF99, 0x99FF99, 0x99FFFF, 0x9999FF, 0xFF99FF, _
    0xAAAAAA, 0xFF7777, 0xF8B53F, 0xFFFF77, 0x77FF77, 0x77FFFF, 0x7777FF, 0xFF77FF, _
    0x999999, 0xFF4444, 0xF7A91F, 0xFFFF44, 0x44FF44, 0x44FFFF, 0x4444FF, 0xFF44FF, _
    0x888888, 0xFF0000, 0xF69D00, 0xFFFF00, 0x00FF00, 0x00FFFF, 0x0000FF, 0xFF00FF]
#EndRegion

#Region GUI
Global $GUI_Main = GUICreate("Test", 180, 40)
GUICtrlCreateLabel("Search:", 5,2,50,20)
Global $Search_Field = GUICtrlCreateInput("", 50,0,130,20)
Global $Color_Button = _GUIColorPicker_Create('ColorPicker Button', 0, 20, 100, 20, 0xFFFFFF, BitOR($CP_FLAG_TIP, $CP_FLAG_MAGNIFICATION), $aPalette, 8, 8)
GUISetOnEvent($GUI_EVENT_CLOSE, "Exit_GUI")
GUIRegisterMsg($WM_COMMAND, "WM_COMMAND")
GUICtrlSetOnEvent($Color_Button, "GUI_Color_Function")
GUISetState(@SW_SHOW, $GUI_Main)
#EndRegion

While 1
   Sleep(10)
WEnd

Func WM_COMMAND($hWnd, $iMsg, $wParam, $lParam)
   #forceref $hWnd, $iMsg
   Local $hWndFrom, $iIDFrom, $iCode
   $hWndFrom = $lParam
   $iIDFrom = BitAND($wParam, 0xFFFF)
   $iCode = BitShift($wParam, 16)
   Switch $iIDFrom
   Case $Search_Field
      Switch $iCode
         Case $EN_CHANGE
            If GUICtrlRead($Search_Field) <> "" Then
               ConsoleWrite("Search Item 1: " & GUICtrlRead($Search_Field) & @CRLF)
               Search_Function()
            EndIf
      EndSwitch
   EndSwitch
   Return $GUI_RUNDEFMSG
EndFunc

Func GUI_Color_Function()
   GUICtrlSetBkColor($Search_Field, _GUIColorPicker_GetColor($Color_Button))
EndFunc

Func Search_Function()
   MsgBox($MB_OK, "This will be a search function.", "You started typing in the search field." & @CRLF & "The search function is not here included.")
EndFunc

Func Exit_GUI()
   Exit
EndFunc

You'll notice that the search function works but the color bit doesn't. If you comment out the WM_COMMAND part, the color bit works but the search function does not.

Link to comment
Share on other sites

You should read through the thread you got the color UDF from, page 2 has a post in it that explains how to get around this, ask in that thread how to implement it if you can't figure it out.

If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...