I'm trying to call the
chooseColor function from the comdlg32.dll; and altho I have succeeded in being able to define the initial color, I haven't been able to set up the
lpCustColors array to work properly.
MSDN describes
lpCustColors as..
Quote: "
Pointer to an array of 16 values that contain red, green, blue (RGB) values for the custom color boxes in the dialog box. If the user modifies these colors, the system updates the array with the new RGB values. To preserve new custom colors between calls to the ChooseColor function, you should allocate static memory for the array. To create a COLORREF color value, use the RGB macro.
"
I'm using IanM's arrayPtr commands to get the pointer for the array.
I create an array(15), set all the values to 0x00ffffff (So all 16 squares of the custom colors bit should be white. But they end up with 2 pink ones and a load of murky colors)
Here is my code, can someone plz tell me where I'm going wrong with this.
//******************************************************
// chooseColor example for forum
//******************************************************
//******************************************************
// Requires IanM's Matrix1 Utils plugin
//******************************************************
// DLL number constants
#constant User32dll 1
#constant comdlg32dll 2
#constant kernel32dll 3
// color chooser constants
#constant CC_RGBINIT 0x001
#constant CC_FULLOPEN 0x002
#constant CC_PREVENTFULLOPEN 0x004
#constant CC_SOLIDCOLOR 0x80
#constant CC_ANYCOLOR 0x100
//************************************************************
// Main code
//************************************************************
initGui()
chooseColor()
wait key
end
//************************************************************
// End of code - Avast! 'ere be functions!
//************************************************************
//************************************************************
// Init GUI system
//************************************************************
function initGui()
// loads the user32.dll
load dll "User32.dll", user32dll
if dll exist(user32dll)=false
print "user32.dll failed to load"
wait key
end
endif
// loads the comdlg32.dll
load dll "comdlg32.dll", comdlg32dll
if dll exist(comdlg32dll)=false
print "comdlg32.dll failed to load"
wait key
end
endif
// loads the kernal32.dll
load dll "kernel32.dll", kernel32dll
if dll exist(kernel32dll)=false
print "kernel32.dll failed to load"
wait key
end
endif
endfunction
//************************************************************
// ColorChooser
//************************************************************
function chooseColor()
`The choose color function explained
`http://msdn.microsoft.com/en-us/library/ms646912(VS.85).aspx
`The Choose color structure description
`http://msdn.microsoft.com/en-us/library/ms646830(VS.85).aspx
// choosecolor structure
`typedef struct {
`DWORD lStructSize; 4
`HWND hwndOwner; 4
`HWND hInstance; 4
`COLORREF rgbResult; 4
`COLORREF *lpCustColors; 4
`DWORD Flags; 4
`LPARAM lCustData; 4
`LPCCHOOKPROC lpfnHook; 4
`LPCTSTR lpTemplateName; 4
`} CHOOSECOLOR, *LPCHOOSECOLOR;
// declare some variables
local ptr as dword
local col as dword
local ptr2 as dword
ptr=make memory(36)
// the array of colors
dim array(15) as dword
// gets the pointer for the array
ptr2=get arrayptr(array())
// fill the array with "white"
for a=0 to 15
array(a)=0x00ffffff
next a
` current selected color
col=0x00ffffff
// enter information into chooseColor structure
addy=ptr : *addy=36 :` size of structure in bytes
addy=ptr+4 : *addy=getHWnd() :` handle to the parent window !! THIS IS A BLUE GUI COMMAND, WORK OUT HOW TO DO IT WITH DLL CALLS !!
addy=ptr+8 : *addy=getHInstance() :` get hInstance
addy=ptr+12 : *addy=rgbr(col) :` color result? can I preset it this way?
addy=ptr+13 : *addy=rgbg(col) :` color result? can I preset it this way?
addy=ptr+14 : *addy=rgbb(col) :` color result? can I preset it this way?
addy=ptr+16 : *addy=ptr2
addy=ptr+20 : *addy=cc_rgbinit+cc_fullopen+cc_anycolor+cc_solidcolor:` flags :/ refer to webpage
addy=ptr+24 : *addy=0
addy=ptr+28 : *addy=0
addy=ptr+32 : *addy=0
// debug
print "Pointer:"+str$(ptr)
print
print "hWnd: "+str$(getHWnd())
print "hInstance: "+str$(getHInstance())
print "Color: "+hex$(col)
print "Array Ptr: "+str$(ptr2)
print "Flags: "+str$(cc_rgbInit+cc_fullOpen)
print
print "calling dll"
ptr=call dll(comdlg32dll,"ChooseColorA",ptr)
print "done"
print
print "Press any key to exit"
delete memory ptr
delete memory ptr2
endfunction
//************************************************************
// Exit GUI - delete the gui dll's
//************************************************************
function exitGui()
// just deletes the dll's which are loaded for the GUI library
delete dll user32dll
delete dll comdlg32dll
delete dll kernel32dll
endfunction
//************************************************************
//
// GUI System functions - these are called inside the functions
//
//************************************************************
function stringToPointer(text$ as string)
// declare variables
local lenText as integer : lenText=len(text$)
local temp$ as string : temp$=""
local addy as integer : addy=0
local ptr as integer : ptr=0
// assign pointer for Word
ptr=make Memory(lenText)
// put the string into memory
for a=0 to lenText-1
temp$=mid$(text$,a+1,1)
addy=ptr+a
*addy=asc(temp$)
next a
endfunction ptr
//************************************************************
// hInstance
//************************************************************
function getHInstance()
local result as dword
result=call dll(kernel32dll,"GetModuleHandleA","Temp.exe")
endfunction result
//************************************************************
// hWnd - gets the window handle
//************************************************************
function getHWnd()
local result as dword
result = Call dll(user32dll,"GetActiveWindow")
endfunction result
