 |
| Using the ChooseColor function |
User rating: 0/10 (0 votes) | | |
|
 |
 |
Versions: click to open |
 |
|
 |
 |
| Before you begin: |
 |
| Not much a difference from the native VFP function GetColor(). |
 |
 |
using System;
using System.Runtime.InteropServices;
namespace ChooseColor
{
class Program
{
[StructLayout(LayoutKind.Sequential)]
public struct CHOOSECOLOR
{
public Int32 lStructSize;
public Int32 hwndOwner;
public Int32 hInstance;
public Int32 rgbResult;
public IntPtr lpCustColors;
public Int32 Flags;
public Int32 lCustData;
public Int32 lpfnHook;
public Int32 lpTemplateName;
}
static void Main(string[] args)
{
CHOOSECOLOR choosecolor = new CHOOSECOLOR();
choosecolor.lStructSize = Marshal.SizeOf(choosecolor);
choosecolor.hwndOwner = 0; //GetDesktopWindow();
choosecolor.rgbResult = 0x808080;
choosecolor.lpCustColors = Marshal.AllocCoTaskMem(64);
choosecolor.Flags = 3;
ChooseColorA(ref choosecolor);
//get the color from rgbResult member
}
[DllImport("comdlg32.dll")]
public static extern int
ChooseColorA(ref CHOOSECOLOR pChoosecolor);
[DllImport("user32.dll")]
public static extern int GetDesktopWindow();
}
}
|
 |
User rating: 0/10 (0 votes) | | | 1283 bytes Created: 2002-01-25 19:49:18 Modified: 2008-03-20 15:58:27 Visits in 7 days: 158 |
|
 |
 |
| Listed functions: |
 |
|
 |
 |
| My comment: |
 |
WIth the ChooseColor you have some more control on the form presentation, but not its positioning.
16 custom colors are available for reading and writing through a memory block, which -- if you are interested in -- you have to allocate and release directly.
Using the VFP native GetColor function you can access the custom colors as well, but only changing their values within the Color dialog is available. I guess that VFP keeps that array in its memory during the whole session, exclusively to be used in the ChooseColor calls. To my knowledge there is no regular way to reach it.
Then, not many advantages this function gives to dump the good old GetColor, which is still present unchanged in each VFP version. |
 |
 |
| Word Index links for this example: |
 |
|
|
 |
 |
| Translate this page: |
 |
|