Software Archive
Read-only legacy content
17061 Discussions

Is there a colour definition component in CVF?

davidgraham
Beginner
954 Views
I would like the user to be able to define a coulor using red, blue & green - being able to select the amounts of each colour and showing visually the colour that they will give.

I have seen this type of component in VB, is there one in CVF?

Or with Multi-language support can I use a VB component in a CVF project?

Thanks,

David
0 Kudos
7 Replies
Intel_C_Intel
Employee
954 Views
Hi David,

Since you want a visual, why not use the Common Dialog control (it has a Show Color method to display the color picker dialog). It's just using an Active control in a CVF project. You may have already done this before.

nth,
John
0 Kudos
davidgraham
Beginner
954 Views
John,
Where do I find this ShowColor method, I had a look in the Help and it wasn't mentioned?
Thanks,
David
0 Kudos
Jugoslav_Dujic
Valued Contributor II
954 Views
Actually, it is ChooseColor common dialog. The help on it
is in "Common Dialogs" section of the help. Here is a
brief sample (a fragment from the code managing a dialog
which displays the actual color, and has a "change..."
button which opens ChooseColor dialog):

SUBROUTINE OnBojaChange(Dlg,ID,iType)
!Callback for "Change" button
...

TYPE(Dialog):: Dlg
INCLUDE 'Resource.fd'

TYPE(T_CHOOSECOLOR):: CC
INTEGER:: nCustColors(16)

nCustColors(1:4)=jBojaNap(1:4,0)
nCustColors(5:)=#FFFFFF
IDBoja=ID-10

!DLG_BKCOLOR is my tweak of DFLOGM
iSt=DlgGet(Dlg,IDBoja,iBoja,DLG_BKCOLOR)
CC=T_CHOOSECOLOR(36,Dlg%Hwnd,hInst,iBoja,LOC(nCustColors),CC_FULLOPEN.OR.CC_RGBINIT,NULL,NULL,NULL)

bRet=ChooseColor(CC)

...

HTH
Jugoslav
0 Kudos
Intel_C_Intel
Employee
954 Views
Hi David,

Jugoslav showed a straight SDK example using the ChooseColor API function. I had suggested using the Common Dialog Control (COMDLG32.OCX). Using a COM module, it would look something like

retlog = DlgGet( dlg, IDC_COMMONDIALOG1, pdisp, DLG_IDISPATCH )
hr = $ICommonDialog_ShowColor(pdisp)
hr = $ICommonDialog_GetColor(pdisp, clrColor)
! ...

Of course, you'd have to follow the CVF docs on Using ActiveX Controls.

The help you're trying to find is in MSDN. One place to look is http://msdn.microsoft.com/library/default.asp?URL=/library/devprods/vs6/vbasic/cmdlg98/vbctlcommondialogcontrolcolordialog.htm.

So, you have your choice which method to use.

hth,
John
0 Kudos
davidgraham
Beginner
954 Views
Thanks to Jugoslav & John for their help.

The ChooseColor common dialog allows you to define 16 colours, but I want to define 256.

The users wants to define 256 colours, I'm not sure how I can do that.
They want to be able to set up 256 colours so they can be the same as AutoCAD.

Or how can I just define one colour?

Thanks,

David
0 Kudos
Jugoslav_Dujic
Valued Contributor II
954 Views
Hi David,
You probably could reuse the ActiveX control from VB you mentioned,
which would require COM and Module Wizard... perhaps John could
elaborate more, since I'm not very familiar.
If it is not possible, my suggestion is that you try to design your own
dialog from scratch. As one could conclude, the code fragment I posted
is from a dialog for color customization (though there are only about
20 colors). As I concluded, user of your application should be able
to customize entire 256-color palette.
The way I would do it is to design a dialog with 256, say,
push-like check-boxes with IDs in contiguous range
(e.g. 1400-1655), and provide a mechanism for changing the color.
(either via a "Change..." button with ChooseColor as a callback
or to define, say, three edit-boxes with spin buttons for RGB
definition).
Here is some code that illustrates the technique (it is written ad hoc
- perhaps it is not quite correct). Let us say that your dialog contains
255 pushlike check-boxes with IDs IDC_CHECK0...IDC_CHECK255
in contiguous range, a "Change" button and an "OK" button:

INTEGER FUNCTION ColorDlgProc(hWnd,Msg,wParam,lParam)

USE DFWIN
USE MYGLOBALS !Store global iColor,hInst, etc.

INTEGER,INTENT(IN):: hWnd,Msg,wParam,lParam
INCLUDE "Resource.fd"
INTEGER,SAVE:: hBrush(0:255)
INTEGER, SAVE:: nSelected = 0
TYPE(T_CHOOSECOLOR):: CC

SELECT CASE(Msg)
CASE(WM_INITDIALOG)
...DO i=1,255
......hBrush(i)=CreateSolidBrush(iColor(i))
...END DO
...iSt=SendMessage(GetDlgItem(hWnd,IDC_CHECK0),BM_SETCHECK,1,0)
...nSelected=0
...ColorDlgProc=0
CASE (WM_CTLCOLORBTN)
...ID=GetDlgCtrlID(lParam)
...nIndex=ID - IDC_CHECK0
...IF (nIndex.GE.0 .AND. nIndex.LE.255) THEN
......ColorDlgProc=hBrush(nIndex)
...ELSE
......ColorDlgProc=0
...END IF
CASE(WM_COMMAND)
...ID=wParam.AND.#FFFF
...SELECT CASE (ID)
...CASE (IDC_CHECK0:IDC_CHECKID)
......nSelected=ID - IDC_CHECK0
...CASE (IDC_BUTTON_CHANGE)
......nColor=iColor(nSelected)
......CC=T_CHOOSECOLOR(36,hWnd,hInst,nColor,NULL,
CC_FULLOPEN,NULL,NULL,NULL)
......bOK=ChooseColor(CC)
......IF (bOK) THEN
.........iSt=DeleteObject(hBrush(nSelected))
.........hBrush(nSelected)=CreateSolidBrush(CC%rgbResult)
.........iColor(nSelected)=CC%rgbResult
......END IF
...CASE(IDOK)
.....!TODO dialog destruction & clearing
...END SELECT
...ColorDlgProc=0
CASE(WM_DESTROY)
...!Don't forget to delete brushes
...DO i=1,255
......iSt=DeleteObject(hBrush(i))
...END DO
...ColorDlgProc=0
END SELECT

END FUNCTION ColorDlgProc
!==============================================
Uh, it took a little longer than I thought. As you see, the trick is
to use WM_CTLCOLORBTN to display the color palette on an array
of controls. The trick with contiguous IDs spares quite
a number of lines (you can manually edit resource.h - _NOT_
resource.fd to obtain this).
Hope this would be helpful,
Jugoslav
0 Kudos
davidgraham
Beginner
954 Views
Thanks, I will use a grid of 256 colours etc.

David
0 Kudos
Reply