Page 1 of 1

What`s wrong with this code?

Posted: Tue Jan 01, 2008 10:31 pm
by Yam
Code:
CONST CC_RGBINIT = &H1
CONST CC_FULLOPEN = &H2
CONST CC_PREVENTFULLOPEN = &H4
CONST CC_SHOWHELP = &H8
CONST CC_ENABLEHOOK = &H10
CONST CC_ENABLETEMPLATE = &H20
CONST CC_ENABLETEMPLATEHANDLE = &H40
CONST CC_SOLIDCOLOR = &H80
CONST CC_ANYCOLOR = &H100

TYPE TCHOOSECOLOR
 lStructSize AS LONG
 hWndOwner AS LONG
 hInstance AS LONG
rgbResult AS LONG
CustColors(1 TO 16) AS LONG
 Flags AS Double
lCustData AS LONG
lpfnHook AS LONG
lpTemplateName AS LONG
 END TYPE

dim cc as TCHOOSECOLOR

`-- 16 of these custom colors, whatever you want...
   cc.CustColors(1) = &HFF0000
   cc.CustColors(2) = &H00FF00
   cc.CustColors(3) = &H0000FF
   cc.CustColors(4) = &HFF00FF
   cc.CustColors(5) = &H00FFFF
   cc.CustColors(6) = &HFFFFFF
   cc.CustColors(7) = &H559911
   cc.CustColors(8) = &HEE44BB
   cc.CustColors(9) = &HBB44EE
   cc.CustColors(10) = &H115599
   cc.CustColors(11) = &H333333
   cc.CustColors(12) = &H666666
   cc.CustColors(13) = &H999999
   cc.CustColors(14) = &HABABAB
   cc.CustColors(15) = &HDDDDDD
   cc.CustColors(16) = &H550000

DECLARE ChooseColorDlg as  ChooseColorA  of  "COMDLG32"
  cc AS LONG
         Return AS LONG
  end declare


dim colordlg as colordialog
object form3 as form  
 Caption = "Color Value"
   Width = 400
   Height = 225
   color = &H0080FF80

   object Edit1 AS EDIT
       Text = ""
       Left = 151
       Top = 22
   END object
   object Label1 As LABEL
   Caption = "           Decimal"
   Top = 2
   Left = 158
   END object
   
 object Label2 As LABEL
   Caption = "       Hexdecimal"
   Top = 52
   Left = 158
   END object

   object Edit2 AS EDIT
       Text = ""
       Left = 151
       Top = 72
   END object
   object button1 as button
       Caption = "Choose color "
       Left = 5
       Top = 10
       Width = 100
       TabOrder = 0
       onclick=buttonClick
   end object

 END object


form3.ShowModal

SUB ButtonClick()
colordlg.show
  DIM ReturnVal AS LONG
dim Hex1 as double
dim Hex2 as string
`  cc.lStructSize = CC
`  cc.hWndOwner = Form3.Handle
`   CC.Flags = CC_RGBINIT + CC_FULLOPEN
`cc.rgbResult = Form3.Color

 `  ReturnVal = ChooseColorDlg(cc)

   `-- rgbResult is in BGR format, so no conversion is necessary.
   IF ReturnVal <> 0 THEN Form3.Color = CC.rgbResult
  Edit1.text = Str$(CC.rgbResult)
  Hex1 = Val(Edit1.text)
   Hex2 = HEX$(Hex1)
  Edit2.text = "&H" + Hex2

END SUB
:o

What`s wrong with this code?

Posted: Wed Jan 02, 2008 8:22 am
by vdobiasch
It`s all build in, you don`t need the API:

dim colordlg as colordialog
`-- 16 of these custom colors, whatever you want...
   colordlg.CustomColor(0)="FF0000"
   colordlg.CustomColor(1)="00FF00"
   colordlg.CustomColor(2)="0000FF"
   colordlg.CustomColor(3)="FF00FF"
   colordlg.CustomColor(4)="00FFFF"
   colordlg.CustomColor(5)="FFFFFF"
   colordlg.CustomColor(6)="559911"
   colordlg.CustomColor(7)="EE44BB"
   colordlg.CustomColor(8)="BB44EE"
   colordlg.CustomColor(9)="115599"
   colordlg.CustomColor(10)="333333"
   colordlg.CustomColor(11)="666666"
   colordlg.CustomColor(12)="999999"
   colordlg.CustomColor(13)="ABABAB"
   colordlg.CustomColor(14)="DDDDDD"
   colordlg.CustomColor(15)="550000"

object form3 as form  
     Caption = "Color Value"
     Width = 400
     Height = 225
     color = &H0080FF80
     object Edit1 AS EDIT
               Text = ""
           Left = 151
           Top = 22
         END object
         object Label1 As LABEL
               Caption = "           Decimal"
           Top = 2
           Left = 158
     END object
     object Label2 As LABEL
               Caption = "       Hexdecimal"
           Top = 52
           Left = 158
     END object
     object Edit2 AS EDIT
           Text = ""
           Left = 151
           Top = 72
     END object
         object button1 as button
           Caption = "Choose color "
           Left = 5
           Top = 10
           Width = 100
           TabOrder = 0
           onclick=buttonClick
     end object  
END object

form3.ShowModal

SUB ButtonClick()
     if colordlg.show=True then
           Form3.Color = colordlg.color
             Edit1.text = Str$(colordlg.color)
           Edit2.text = "&H" + Hex$(colordlg.color)
      end if
END SUB