473,766 Members | 2,035 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Need a palette expert here

Below is a small but complete program that appears to show you
can't retrive a Palette from the clipboard.

This is true whether the palette is placed on the clipboard by Photoshop or
Photoshop or by the below program

It lets you place a palette from a file or from a program on the clipboard
and allows you to retrieve one from the clipboard. But you'll find the
retrieved one is always "Nothing"

I'd appreciate comments

Imports System.Drawing. Imaging

Public Class Form1

Inherits System.Windows. Forms.Form

Private WithEvents button1 As System.Windows. Forms.Button

Private WithEvents button2 As System.Windows. Forms.Button

Private WithEvents button3 As System.Windows. Forms.Button

Private components As System.Componen tModel.IContain er

Private cp As ColorPalette

Friend WithEvents ToolTip1 As System.Windows. Forms.ToolTip

Friend WithEvents TextBox1 As System.Windows. Forms.TextBox

Friend WithEvents TextBox2 As System.Windows. Forms.TextBox

Friend WithEvents Timer1 As System.Windows. Forms.Timer

Public Sub New()

InitializeCompo nent()

End Sub 'New

Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)

If disposing Then

If Not (components Is Nothing) Then

components.Disp ose()

End If

End If

MyBase.Dispose( disposing)

End Sub 'Dispose

#Region "Windows Form Designer generated code"

Private Sub InitializeCompo nent()

Me.components = New System.Componen tModel.Containe r

Me.button1 = New System.Windows. Forms.Button

Me.button2 = New System.Windows. Forms.Button

Me.button3 = New System.Windows. Forms.Button

Me.ToolTip1 = New System.Windows. Forms.ToolTip(M e.components)

Me.TextBox1 = New System.Windows. Forms.TextBox

Me.TextBox2 = New System.Windows. Forms.TextBox

Me.Timer1 = New System.Windows. Forms.Timer(Me. components)

Me.SuspendLayou t()

'

'button1

'

Me.button1.Loca tion = New System.Drawing. Point(186, 124)

Me.button1.Name = "button1"

Me.button1.Size = New System.Drawing. Size(130, 24)

Me.button1.TabI ndex = 2

Me.button1.Text = "Copy File Palette"

Me.ToolTip1.Set ToolTip(Me.butt on1, "Copy Palette from a GIF file to the
clipboard")

'

'button2

'

Me.button2.Loca tion = New System.Drawing. Point(13, 124)

Me.button2.Name = "button2"

Me.button2.Size = New System.Drawing. Size(156, 24)

Me.button2.TabI ndex = 2

Me.button2.Text = "Retrieve Clipboard Palette"

Me.ToolTip1.Set ToolTip(Me.butt on2, "Retrieve a palette from the clipboard")

'

'button3

'

Me.button3.Loca tion = New System.Drawing. Point(88, 167)

Me.button3.Name = "button3"

Me.button3.Size = New System.Drawing. Size(130, 24)

Me.button3.TabI ndex = 2

Me.button3.Text = "Exit"

'

'TextBox1

'

Me.TextBox1.Loc ation = New System.Drawing. Point(12, 24)

Me.TextBox1.Mul tiline = True

Me.TextBox1.Nam e = "TextBox1"

Me.TextBox1.Siz e = New System.Drawing. Size(304, 47)

Me.TextBox1.Tab Index = 3

Me.TextBox1.Tex t = "Palette can be placed on clipboard by using the 'Save
Palette"" button or by some " & _

"external program such as Photoshop"

'

'TextBox2

'

Me.TextBox2.Loc ation = New System.Drawing. Point(13, 85)

Me.TextBox2.Nam e = "TextBox2"

Me.TextBox2.Siz e = New System.Drawing. Size(302, 20)

Me.TextBox2.Tab Index = 4

'

'Timer1

'

Me.Timer1.Enabl ed = True

'

'Form1

'

Me.AutoScaleBas eSize = New System.Drawing. Size(5, 13)

Me.ClientSize = New System.Drawing. Size(328, 204)

Me.Controls.Add (Me.TextBox2)

Me.Controls.Add (Me.TextBox1)

Me.Controls.Add (Me.button1)

Me.Controls.Add (Me.button2)

Me.Controls.Add (Me.button3)

Me.Name = "Form1"

Me.Text = "Form1"

Me.ResumeLayout (False)

Me.PerformLayou t()

End Sub 'InitializeComp onent

#End Region

<STAThread()Sha red Sub Main()

Application.Run (New Form1)

End Sub 'Main

Private Sub button1_Click(B yVal sender As Object, ByVal e As
System.EventArg s) Handles button1.Click

Dim dlg As New OpenFileDialog

dlg.Filter = "GIF files|*.GIF"

If dlg.ShowDialog( ) = DialogResult.OK Then

Dim zz As Image = Image.FromFile( dlg.FileName)

Dim DataO As New DataObject

DataO.SetData(D ataFormats.Bitm ap, False, CType(zz, Bitmap))

DataO.SetData(D ataFormats.Pale tte.ToString, False, zz.Palette)

Clipboard.SetDa taObject(DataO, False)

End If

End Sub 'button1_Click

Private Sub button2_Click(B yVal sender As Object, ByVal e As
System.EventArg s) Handles button2.Click

Dim DataO As DataObject = CType(Clipboard .GetDataObject( ), DataObject)

If DataO.GetDataPr esent(DataForma ts.Palette, False) Then

cp = CType(DataO.Get Data(DataFormat s.Palette), ColorPalette)

If cp Is Nothing Then

MessageBox.Show ("Contains palette that is Nothing")

Else

MessageBox.Show (cp.ToString)

End If

Else

MessageBox.Show ("No Palette on Clipboard")

End If
End Sub 'button2_Click

Private Sub button3_Click(B yVal sender As Object, ByVal e As
System.EventArg s) Handles button3.Click

Application.Exi t()

End Sub 'button3_Click

Private Sub Timer1_Tick(ByV al sender As Object, ByVal e As System.EventArg s)
Handles Timer1.Tick

Dim DataO As DataObject = CType(Clipboard .GetDataObject( ), DataObject)

If DataO.GetDataPr esent(DataForma ts.Palette, False) Then

Dim cp As ColorPalette = CType(DataO.Get Data(DataFormat s.Palette),
ColorPalette)

TextBox2.Text = "There is a Palette on the Clipboard"

Else

TextBox2.Text = "The Clipboard does not contain a Palette"

End If

End Sub

End Class 'Form1

Jul 4 '07 #1
15 2055
The DataFormats.Pal ette is a private clipboard format.

Perhaps Microsoft intended this format to represent the new ColorPalette
format but they provided a flawed implementation of the DataObject class.

When you query the clipboard using GetDataPresent( DataFormats.Pal ette,
false) or GetDataPresent( DataFormats.Pal ette, true), the return value is
true.

If you try to retrieve the data using GetData(DataFor mats.Palette), the
return value is null.

The canonical clipboard format is CF_PALETTE which is represented as an GDI
HPALETTE.

I am unaware of any application that uses the private clipboard format
DataFormats.Pal ette and places the palette on the clipboard as a
ColorPalette object.

The Microsoft implementation of the DataObject class does not convert the
GDI HPALETTE to a ColorPalette object.

You need to do this on your own.

Use P-Invoke to get the HPALETTE using the CF_PALETTE clipboard format and
convert it to a new ColorPalette object using the GDI functions GetObject
and GetPaletteEntri es.
" active" <ac********** @a-znet.comwrote in message
news:OI******** ******@TK2MSFTN GP04.phx.gbl...
Below is a small but complete program that appears to show you
can't retrive a Palette from the clipboard.

This is true whether the palette is placed on the clipboard by Photoshop
or
Photoshop or by the below program

It lets you place a palette from a file or from a program on the clipboard
and allows you to retrieve one from the clipboard. But you'll find the
retrieved one is always "Nothing"

I'd appreciate comments

Imports System.Drawing. Imaging

Public Class Form1

Inherits System.Windows. Forms.Form

Private WithEvents button1 As System.Windows. Forms.Button

Private WithEvents button2 As System.Windows. Forms.Button

Private WithEvents button3 As System.Windows. Forms.Button

Private components As System.Componen tModel.IContain er

Private cp As ColorPalette

Friend WithEvents ToolTip1 As System.Windows. Forms.ToolTip

Friend WithEvents TextBox1 As System.Windows. Forms.TextBox

Friend WithEvents TextBox2 As System.Windows. Forms.TextBox

Friend WithEvents Timer1 As System.Windows. Forms.Timer

Public Sub New()

InitializeCompo nent()

End Sub 'New

Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)

If disposing Then

If Not (components Is Nothing) Then

components.Disp ose()

End If

End If

MyBase.Dispose( disposing)

End Sub 'Dispose

#Region "Windows Form Designer generated code"

Private Sub InitializeCompo nent()

Me.components = New System.Componen tModel.Containe r

Me.button1 = New System.Windows. Forms.Button

Me.button2 = New System.Windows. Forms.Button

Me.button3 = New System.Windows. Forms.Button

Me.ToolTip1 = New System.Windows. Forms.ToolTip(M e.components)

Me.TextBox1 = New System.Windows. Forms.TextBox

Me.TextBox2 = New System.Windows. Forms.TextBox

Me.Timer1 = New System.Windows. Forms.Timer(Me. components)

Me.SuspendLayou t()

'

'button1

'

Me.button1.Loca tion = New System.Drawing. Point(186, 124)

Me.button1.Name = "button1"

Me.button1.Size = New System.Drawing. Size(130, 24)

Me.button1.TabI ndex = 2

Me.button1.Text = "Copy File Palette"

Me.ToolTip1.Set ToolTip(Me.butt on1, "Copy Palette from a GIF file to the
clipboard")

'

'button2

'

Me.button2.Loca tion = New System.Drawing. Point(13, 124)

Me.button2.Name = "button2"

Me.button2.Size = New System.Drawing. Size(156, 24)

Me.button2.TabI ndex = 2

Me.button2.Text = "Retrieve Clipboard Palette"

Me.ToolTip1.Set ToolTip(Me.butt on2, "Retrieve a palette from the
clipboard")

'

'button3

'

Me.button3.Loca tion = New System.Drawing. Point(88, 167)

Me.button3.Name = "button3"

Me.button3.Size = New System.Drawing. Size(130, 24)

Me.button3.TabI ndex = 2

Me.button3.Text = "Exit"

'

'TextBox1

'

Me.TextBox1.Loc ation = New System.Drawing. Point(12, 24)

Me.TextBox1.Mul tiline = True

Me.TextBox1.Nam e = "TextBox1"

Me.TextBox1.Siz e = New System.Drawing. Size(304, 47)

Me.TextBox1.Tab Index = 3

Me.TextBox1.Tex t = "Palette can be placed on clipboard by using the 'Save
Palette"" button or by some " & _

"external program such as Photoshop"

'

'TextBox2

'

Me.TextBox2.Loc ation = New System.Drawing. Point(13, 85)

Me.TextBox2.Nam e = "TextBox2"

Me.TextBox2.Siz e = New System.Drawing. Size(302, 20)

Me.TextBox2.Tab Index = 4

'

'Timer1

'

Me.Timer1.Enabl ed = True

'

'Form1

'

Me.AutoScaleBas eSize = New System.Drawing. Size(5, 13)

Me.ClientSize = New System.Drawing. Size(328, 204)

Me.Controls.Add (Me.TextBox2)

Me.Controls.Add (Me.TextBox1)

Me.Controls.Add (Me.button1)

Me.Controls.Add (Me.button2)

Me.Controls.Add (Me.button3)

Me.Name = "Form1"

Me.Text = "Form1"

Me.ResumeLayout (False)

Me.PerformLayou t()

End Sub 'InitializeComp onent

#End Region

<STAThread()Sha red Sub Main()

Application.Run (New Form1)

End Sub 'Main

Private Sub button1_Click(B yVal sender As Object, ByVal e As
System.EventArg s) Handles button1.Click

Dim dlg As New OpenFileDialog

dlg.Filter = "GIF files|*.GIF"

If dlg.ShowDialog( ) = DialogResult.OK Then

Dim zz As Image = Image.FromFile( dlg.FileName)

Dim DataO As New DataObject

DataO.SetData(D ataFormats.Bitm ap, False, CType(zz, Bitmap))

DataO.SetData(D ataFormats.Pale tte.ToString, False, zz.Palette)

Clipboard.SetDa taObject(DataO, False)

End If

End Sub 'button1_Click

Private Sub button2_Click(B yVal sender As Object, ByVal e As
System.EventArg s) Handles button2.Click

Dim DataO As DataObject = CType(Clipboard .GetDataObject( ), DataObject)

If DataO.GetDataPr esent(DataForma ts.Palette, False) Then

cp = CType(DataO.Get Data(DataFormat s.Palette), ColorPalette)

If cp Is Nothing Then

MessageBox.Show ("Contains palette that is Nothing")

Else

MessageBox.Show (cp.ToString)

End If

Else

MessageBox.Show ("No Palette on Clipboard")

End If
End Sub 'button2_Click

Private Sub button3_Click(B yVal sender As Object, ByVal e As
System.EventArg s) Handles button3.Click

Application.Exi t()

End Sub 'button3_Click

Private Sub Timer1_Tick(ByV al sender As Object, ByVal e As
System.EventArg s)
Handles Timer1.Tick

Dim DataO As DataObject = CType(Clipboard .GetDataObject( ), DataObject)

If DataO.GetDataPr esent(DataForma ts.Palette, False) Then

Dim cp As ColorPalette = CType(DataO.Get Data(DataFormat s.Palette),
ColorPalette)

TextBox2.Text = "There is a Palette on the Clipboard"

Else

TextBox2.Text = "The Clipboard does not contain a Palette"

End If

End Sub

End Class 'Form1

Jul 4 '07 #2
The only non-DotNet way that I know of that I can use to put a Palette on
the clipboard is with Photoshop, which is what I use to test.

I do the following and always get HPalette=0

thanks for the info

Public Declare Auto Function OpenClipboard Lib "user32" (ByVal hWnd As
IntPtr) As Integer

Public Declare Auto Function GetClipboardDat a Lib "user32" (ByVal wFormat As
Integer) As IntPtr

Dim HPalette As IntPtr

Const CF_PALETTE As Integer = 9

If Wnd.OpenClipboa rd(IntPtr.Zero) <0 Then

HPalette = Wnd.GetClipboar dData(CF_PALETT E)


"Michael Phillips, Jr." <mp*********@no spam.jun0.c0mwr ote in message
news:uf******** ******@TK2MSFTN GP03.phx.gbl...
The DataFormats.Pal ette is a private clipboard format.

Perhaps Microsoft intended this format to represent the new ColorPalette
format but they provided a flawed implementation of the DataObject class.

When you query the clipboard using GetDataPresent( DataFormats.Pal ette,
false) or GetDataPresent( DataFormats.Pal ette, true), the return value is
true.

If you try to retrieve the data using GetData(DataFor mats.Palette), the
return value is null.

The canonical clipboard format is CF_PALETTE which is represented as an
GDI HPALETTE.

I am unaware of any application that uses the private clipboard format
DataFormats.Pal ette and places the palette on the clipboard as a
ColorPalette object.

The Microsoft implementation of the DataObject class does not convert the
GDI HPALETTE to a ColorPalette object.

You need to do this on your own.

Use P-Invoke to get the HPALETTE using the CF_PALETTE clipboard format and
convert it to a new ColorPalette object using the GDI functions GetObject
and GetPaletteEntri es.
" active" <ac********** @a-znet.comwrote in message
news:OI******** ******@TK2MSFTN GP04.phx.gbl...
>Below is a small but complete program that appears to show you
can't retrive a Palette from the clipboard.

This is true whether the palette is placed on the clipboard by Photoshop
or
Photoshop or by the below program

It lets you place a palette from a file or from a program on the
clipboard and allows you to retrieve one from the clipboard. But you'll
find the retrieved one is always "Nothing"

I'd appreciate comments

Imports System.Drawing. Imaging

Public Class Form1

Inherits System.Windows. Forms.Form

Private WithEvents button1 As System.Windows. Forms.Button

Private WithEvents button2 As System.Windows. Forms.Button

Private WithEvents button3 As System.Windows. Forms.Button

Private components As System.Componen tModel.IContain er

Private cp As ColorPalette

Friend WithEvents ToolTip1 As System.Windows. Forms.ToolTip

Friend WithEvents TextBox1 As System.Windows. Forms.TextBox

Friend WithEvents TextBox2 As System.Windows. Forms.TextBox

Friend WithEvents Timer1 As System.Windows. Forms.Timer

Public Sub New()

InitializeComp onent()

End Sub 'New

Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)

If disposing Then

If Not (components Is Nothing) Then

components.Dis pose()

End If

End If

MyBase.Dispose (disposing)

End Sub 'Dispose

#Region "Windows Form Designer generated code"

Private Sub InitializeCompo nent()

Me.component s = New System.Componen tModel.Containe r

Me.button1 = New System.Windows. Forms.Button

Me.button2 = New System.Windows. Forms.Button

Me.button3 = New System.Windows. Forms.Button

Me.ToolTip1 = New System.Windows. Forms.ToolTip(M e.components)

Me.TextBox1 = New System.Windows. Forms.TextBox

Me.TextBox2 = New System.Windows. Forms.TextBox

Me.Timer1 = New System.Windows. Forms.Timer(Me. components)

Me.SuspendLayo ut()

'

'button1

'

Me.button1.Loc ation = New System.Drawing. Point(186, 124)

Me.button1.Nam e = "button1"

Me.button1.Siz e = New System.Drawing. Size(130, 24)

Me.button1.Tab Index = 2

Me.button1.Tex t = "Copy File Palette"

Me.ToolTip1.Se tToolTip(Me.but ton1, "Copy Palette from a GIF file to the
clipboard")

'

'button2

'

Me.button2.Loc ation = New System.Drawing. Point(13, 124)

Me.button2.Nam e = "button2"

Me.button2.Siz e = New System.Drawing. Size(156, 24)

Me.button2.Tab Index = 2

Me.button2.Tex t = "Retrieve Clipboard Palette"

Me.ToolTip1.Se tToolTip(Me.but ton2, "Retrieve a palette from the
clipboard")

'

'button3

'

Me.button3.Loc ation = New System.Drawing. Point(88, 167)

Me.button3.Nam e = "button3"

Me.button3.Siz e = New System.Drawing. Size(130, 24)

Me.button3.Tab Index = 2

Me.button3.Tex t = "Exit"

'

'TextBox1

'

Me.TextBox1.Lo cation = New System.Drawing. Point(12, 24)

Me.TextBox1.Mu ltiline = True

Me.TextBox1.Na me = "TextBox1"

Me.TextBox1.Si ze = New System.Drawing. Size(304, 47)

Me.TextBox1.Ta bIndex = 3

Me.TextBox1.Te xt = "Palette can be placed on clipboard by using the 'Save
Palette"" button or by some " & _

"external program such as Photoshop"

'

'TextBox2

'

Me.TextBox2.Lo cation = New System.Drawing. Point(13, 85)

Me.TextBox2.Na me = "TextBox2"

Me.TextBox2.Si ze = New System.Drawing. Size(302, 20)

Me.TextBox2.Ta bIndex = 4

'

'Timer1

'

Me.Timer1.Enab led = True

'

'Form1

'

Me.AutoScaleBa seSize = New System.Drawing. Size(5, 13)

Me.ClientSiz e = New System.Drawing. Size(328, 204)

Me.Controls.Ad d(Me.TextBox2)

Me.Controls.Ad d(Me.TextBox1)

Me.Controls.Ad d(Me.button1)

Me.Controls.Ad d(Me.button2)

Me.Controls.Ad d(Me.button3)

Me.Name = "Form1"

Me.Text = "Form1"

Me.ResumeLayou t(False)

Me.PerformLayo ut()

End Sub 'InitializeComp onent

#End Region

<STAThread()Sh ared Sub Main()

Application.Ru n(New Form1)

End Sub 'Main

Private Sub button1_Click(B yVal sender As Object, ByVal e As
System.EventAr gs) Handles button1.Click

Dim dlg As New OpenFileDialog

dlg.Filter = "GIF files|*.GIF"

If dlg.ShowDialog( ) = DialogResult.OK Then

Dim zz As Image = Image.FromFile( dlg.FileName)

Dim DataO As New DataObject

DataO.SetData( DataFormats.Bit map, False, CType(zz, Bitmap))

DataO.SetData( DataFormats.Pal ette.ToString, False, zz.Palette)

Clipboard.SetD ataObject(DataO , False)

End If

End Sub 'button1_Click

Private Sub button2_Click(B yVal sender As Object, ByVal e As
System.EventAr gs) Handles button2.Click

Dim DataO As DataObject = CType(Clipboard .GetDataObject( ), DataObject)

If DataO.GetDataPr esent(DataForma ts.Palette, False) Then

cp = CType(DataO.Get Data(DataFormat s.Palette), ColorPalette)

If cp Is Nothing Then

MessageBox.Sho w("Contains palette that is Nothing")

Else

MessageBox.Sho w(cp.ToString)

End If

Else

MessageBox.Sho w("No Palette on Clipboard")

End If
End Sub 'button2_Click

Private Sub button3_Click(B yVal sender As Object, ByVal e As
System.EventAr gs) Handles button3.Click

Application.Ex it()

End Sub 'button3_Click

Private Sub Timer1_Tick(ByV al sender As Object, ByVal e As
System.EventAr gs)
Handles Timer1.Tick

Dim DataO As DataObject = CType(Clipboard .GetDataObject( ), DataObject)

If DataO.GetDataPr esent(DataForma ts.Palette, False) Then

Dim cp As ColorPalette = CType(DataO.Get Data(DataFormat s.Palette),
ColorPalette )

TextBox2.Tex t = "There is a Palette on the Clipboard"

Else

TextBox2.Tex t = "The Clipboard does not contain a Palette"

End If

End Sub

End Class 'Form1


Jul 5 '07 #3
I forgot the IsClipboardForm atAvailable lines
The only non-DotNet way that I know of that I can use to put a Palette on
the clipboard is with Photoshop, which is what I use to test.

I do the following and always get HPalette=0

thanks for the info

Public Declare Auto Function OpenClipboard Lib "user32" (ByVal hWnd As
IntPtr) As Integer

Public Declare Auto Function GetClipboardDat a Lib "user32" (ByVal wFormat
As Integer) As IntPtr
Public Declare Auto Function IsClipboardForm atAvailable Lib "user32" (ByVal
wFormat As Integer) As Boolean
>
Dim HPalette As IntPtr

Const CF_PALETTE As Integer = 9
If IsClipboardForm atAvailable(CF_ PALETTE) Then
If OpenClipboard(I ntPtr.Zero) <0 Then
HPalette = GetClipboardDat a(CF_PALETTE)


"Michael Phillips, Jr." <mp*********@no spam.jun0.c0mwr ote in message
news:uf******** ******@TK2MSFTN GP03.phx.gbl...
>The DataFormats.Pal ette is a private clipboard format.

Perhaps Microsoft intended this format to represent the new ColorPalette
format but they provided a flawed implementation of the DataObject class.

When you query the clipboard using GetDataPresent( DataFormats.Pal ette,
false) or GetDataPresent( DataFormats.Pal ette, true), the return value
is true.

If you try to retrieve the data using GetData(DataFor mats.Palette), the
return value is null.

The canonical clipboard format is CF_PALETTE which is represented as an
GDI HPALETTE.

I am unaware of any application that uses the private clipboard format
DataFormats.Pa lette and places the palette on the clipboard as a
ColorPalette object.

The Microsoft implementation of the DataObject class does not convert the
GDI HPALETTE to a ColorPalette object.

You need to do this on your own.

Use P-Invoke to get the HPALETTE using the CF_PALETTE clipboard format
and convert it to a new ColorPalette object using the GDI functions
GetObject and GetPaletteEntri es.
" active" <ac********** @a-znet.comwrote in message
news:OI******* *******@TK2MSFT NGP04.phx.gbl.. .
>>Below is a small but complete program that appears to show you
can't retrive a Palette from the clipboard.

This is true whether the palette is placed on the clipboard by Photoshop
or
Photoshop or by the below program

It lets you place a palette from a file or from a program on the
clipboard and allows you to retrieve one from the clipboard. But you'll
find the retrieved one is always "Nothing"

I'd appreciate comments

Imports System.Drawing. Imaging

Public Class Form1

Inherits System.Windows. Forms.Form

Private WithEvents button1 As System.Windows. Forms.Button

Private WithEvents button2 As System.Windows. Forms.Button

Private WithEvents button3 As System.Windows. Forms.Button

Private components As System.Componen tModel.IContain er

Private cp As ColorPalette

Friend WithEvents ToolTip1 As System.Windows. Forms.ToolTip

Friend WithEvents TextBox1 As System.Windows. Forms.TextBox

Friend WithEvents TextBox2 As System.Windows. Forms.TextBox

Friend WithEvents Timer1 As System.Windows. Forms.Timer

Public Sub New()

InitializeCom ponent()

End Sub 'New

Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)

If disposing Then

If Not (components Is Nothing) Then

components.Di spose()

End If

End If

MyBase.Dispos e(disposing)

End Sub 'Dispose

#Region "Windows Form Designer generated code"

Private Sub InitializeCompo nent()

Me.componen ts = New System.Componen tModel.Containe r

Me.button1 = New System.Windows. Forms.Button

Me.button2 = New System.Windows. Forms.Button

Me.button3 = New System.Windows. Forms.Button

Me.ToolTip1 = New System.Windows. Forms.ToolTip(M e.components)

Me.TextBox1 = New System.Windows. Forms.TextBox

Me.TextBox2 = New System.Windows. Forms.TextBox

Me.Timer1 = New System.Windows. Forms.Timer(Me. components)

Me.SuspendLay out()

'

'button1

'

Me.button1.Lo cation = New System.Drawing. Point(186, 124)

Me.button1.Na me = "button1"

Me.button1.Si ze = New System.Drawing. Size(130, 24)

Me.button1.Ta bIndex = 2

Me.button1.Te xt = "Copy File Palette"

Me.ToolTip1.S etToolTip(Me.bu tton1, "Copy Palette from a GIF file to the
clipboard")

'

'button2

'

Me.button2.Lo cation = New System.Drawing. Point(13, 124)

Me.button2.Na me = "button2"

Me.button2.Si ze = New System.Drawing. Size(156, 24)

Me.button2.Ta bIndex = 2

Me.button2.Te xt = "Retrieve Clipboard Palette"

Me.ToolTip1.S etToolTip(Me.bu tton2, "Retrieve a palette from the
clipboard")

'

'button3

'

Me.button3.Lo cation = New System.Drawing. Point(88, 167)

Me.button3.Na me = "button3"

Me.button3.Si ze = New System.Drawing. Size(130, 24)

Me.button3.Ta bIndex = 2

Me.button3.Te xt = "Exit"

'

'TextBox1

'

Me.TextBox1.L ocation = New System.Drawing. Point(12, 24)

Me.TextBox1.M ultiline = True

Me.TextBox1.N ame = "TextBox1"

Me.TextBox1.S ize = New System.Drawing. Size(304, 47)

Me.TextBox1.T abIndex = 3

Me.TextBox1.T ext = "Palette can be placed on clipboard by using the
'Save
Palette"" button or by some " & _

"external program such as Photoshop"

'

'TextBox2

'

Me.TextBox2.L ocation = New System.Drawing. Point(13, 85)

Me.TextBox2.N ame = "TextBox2"

Me.TextBox2.S ize = New System.Drawing. Size(302, 20)

Me.TextBox2.T abIndex = 4

'

'Timer1

'

Me.Timer1.Ena bled = True

'

'Form1

'

Me.AutoScaleB aseSize = New System.Drawing. Size(5, 13)

Me.ClientSi ze = New System.Drawing. Size(328, 204)

Me.Controls.A dd(Me.TextBox2)

Me.Controls.A dd(Me.TextBox1)

Me.Controls.A dd(Me.button1)

Me.Controls.A dd(Me.button2)

Me.Controls.A dd(Me.button3)

Me.Name = "Form1"

Me.Text = "Form1"

Me.ResumeLayo ut(False)

Me.PerformLay out()

End Sub 'InitializeComp onent

#End Region

<STAThread()S hared Sub Main()

Application.R un(New Form1)

End Sub 'Main

Private Sub button1_Click(B yVal sender As Object, ByVal e As
System.EventA rgs) Handles button1.Click

Dim dlg As New OpenFileDialog

dlg.Filter = "GIF files|*.GIF"

If dlg.ShowDialog( ) = DialogResult.OK Then

Dim zz As Image = Image.FromFile( dlg.FileName)

Dim DataO As New DataObject

DataO.SetData (DataFormats.Bi tmap, False, CType(zz, Bitmap))

DataO.SetData (DataFormats.Pa lette.ToString, False, zz.Palette)

Clipboard.Set DataObject(Data O, False)

End If

End Sub 'button1_Click

Private Sub button2_Click(B yVal sender As Object, ByVal e As
System.EventA rgs) Handles button2.Click

Dim DataO As DataObject = CType(Clipboard .GetDataObject( ), DataObject)

If DataO.GetDataPr esent(DataForma ts.Palette, False) Then

cp = CType(DataO.Get Data(DataFormat s.Palette), ColorPalette)

If cp Is Nothing Then

MessageBox.Sh ow("Contains palette that is Nothing")

Else

MessageBox.Sh ow(cp.ToString)

End If

Else

MessageBox.Sh ow("No Palette on Clipboard")

End If
End Sub 'button2_Click

Private Sub button3_Click(B yVal sender As Object, ByVal e As
System.EventA rgs) Handles button3.Click

Application.E xit()

End Sub 'button3_Click

Private Sub Timer1_Tick(ByV al sender As Object, ByVal e As
System.EventA rgs)
Handles Timer1.Tick

Dim DataO As DataObject = CType(Clipboard .GetDataObject( ), DataObject)

If DataO.GetDataPr esent(DataForma ts.Palette, False) Then

Dim cp As ColorPalette = CType(DataO.Get Data(DataFormat s.Palette),
ColorPalett e)

TextBox2.Te xt = "There is a Palette on the Clipboard"

Else

TextBox2.Te xt = "The Clipboard does not contain a Palette"

End If

End Sub

End Class 'Form1



Jul 5 '07 #4

I forgot the IsClipboardForm atAvailable lines
Then I put it in the wrong place
>
>The only non-DotNet way that I know of that I can use to put a Palette on
the clipboard is with Photoshop, which is what I use to test.

I do the following and always get HPalette=0
Public Declare Auto Function OpenClipboard Lib "user32" (ByVal hWnd As
IntPtr) As Integer

Public Declare Auto Function GetClipboardDat a Lib "user32" (ByVal wFormat
As Integer) As IntPtr
Public Declare Auto Function IsClipboardForm atAvailable Lib "user32"
(ByVal wFormat As Integer) As Boolean
>>
Dim HPalette As IntPtr
Const CF_PALETTE As Integer = 9
If OpenClipboard(I ntPtr.Zero) <0 Then
>If IsClipboardForm atAvailable(CF_ PALETTE) Then

HPalette = GetClipboardDat a(CF_PALETTE)


"Michael Phillips, Jr." <mp*********@no spam.jun0.c0mwr ote in message
news:uf******* *******@TK2MSFT NGP03.phx.gbl.. .
>>The DataFormats.Pal ette is a private clipboard format.

Perhaps Microsoft intended this format to represent the new ColorPalette
format but they provided a flawed implementation of the DataObject
class.

When you query the clipboard using GetDataPresent( DataFormats.Pal ette,
false) or GetDataPresent( DataFormats.Pal ette, true), the return value
is true.

If you try to retrieve the data using GetData(DataFor mats.Palette), the
return value is null.

The canonical clipboard format is CF_PALETTE which is represented as an
GDI HPALETTE.

I am unaware of any application that uses the private clipboard format
DataFormats.P alette and places the palette on the clipboard as a
ColorPalett e object.

The Microsoft implementation of the DataObject class does not convert
the GDI HPALETTE to a ColorPalette object.

You need to do this on your own.

Use P-Invoke to get the HPALETTE using the CF_PALETTE clipboard format
and convert it to a new ColorPalette object using the GDI functions
GetObject and GetPaletteEntri es.
" active" <ac********** @a-znet.comwrote in message
news:OI****** ********@TK2MSF TNGP04.phx.gbl. ..
Below is a small but complete program that appears to show you
can't retrive a Palette from the clipboard.

This is true whether the palette is placed on the clipboard by
Photoshop or
Photoshop or by the below program

It lets you place a palette from a file or from a program on the
clipboard and allows you to retrieve one from the clipboard. But you'll
find the retrieved one is always "Nothing"

I'd appreciate comments

Imports System.Drawing. Imaging

Public Class Form1

Inherits System.Windows. Forms.Form

Private WithEvents button1 As System.Windows. Forms.Button

Private WithEvents button2 As System.Windows. Forms.Button

Private WithEvents button3 As System.Windows. Forms.Button

Private components As System.Componen tModel.IContain er

Private cp As ColorPalette

Friend WithEvents ToolTip1 As System.Windows. Forms.ToolTip

Friend WithEvents TextBox1 As System.Windows. Forms.TextBox

Friend WithEvents TextBox2 As System.Windows. Forms.TextBox

Friend WithEvents Timer1 As System.Windows. Forms.Timer

Public Sub New()

InitializeCo mponent()

End Sub 'New

Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)

If disposing Then

If Not (components Is Nothing) Then

components.D ispose()

End If

End If

MyBase.Dispo se(disposing)

End Sub 'Dispose

#Region "Windows Form Designer generated code"

Private Sub InitializeCompo nent()

Me.component s = New System.Componen tModel.Containe r

Me.button1 = New System.Windows. Forms.Button

Me.button2 = New System.Windows. Forms.Button

Me.button3 = New System.Windows. Forms.Button

Me.ToolTip 1 = New System.Windows. Forms.ToolTip(M e.components)

Me.TextBox 1 = New System.Windows. Forms.TextBox

Me.TextBox 2 = New System.Windows. Forms.TextBox

Me.Timer1 = New System.Windows. Forms.Timer(Me. components)

Me.SuspendLa yout()

'

'button1

'

Me.button1.L ocation = New System.Drawing. Point(186, 124)

Me.button1.N ame = "button1"

Me.button1.S ize = New System.Drawing. Size(130, 24)

Me.button1.T abIndex = 2

Me.button1.T ext = "Copy File Palette"

Me.ToolTip1. SetToolTip(Me.b utton1, "Copy Palette from a GIF file to the
clipboard" )

'

'button2

'

Me.button2.L ocation = New System.Drawing. Point(13, 124)

Me.button2.N ame = "button2"

Me.button2.S ize = New System.Drawing. Size(156, 24)

Me.button2.T abIndex = 2

Me.button2.T ext = "Retrieve Clipboard Palette"

Me.ToolTip1. SetToolTip(Me.b utton2, "Retrieve a palette from the
clipboard" )

'

'button3

'

Me.button3.L ocation = New System.Drawing. Point(88, 167)

Me.button3.N ame = "button3"

Me.button3.S ize = New System.Drawing. Size(130, 24)

Me.button3.T abIndex = 2

Me.button3.T ext = "Exit"

'

'TextBox1

'

Me.TextBox1. Location = New System.Drawing. Point(12, 24)

Me.TextBox1. Multiline = True

Me.TextBox1. Name = "TextBox1"

Me.TextBox1. Size = New System.Drawing. Size(304, 47)

Me.TextBox1. TabIndex = 3

Me.TextBox1. Text = "Palette can be placed on clipboard by using the
'Save
Palette"" button or by some " & _

"external program such as Photoshop"

'

'TextBox2

'

Me.TextBox2. Location = New System.Drawing. Point(13, 85)

Me.TextBox2. Name = "TextBox2"

Me.TextBox2. Size = New System.Drawing. Size(302, 20)

Me.TextBox2. TabIndex = 4

'

'Timer1

'

Me.Timer1.En abled = True

'

'Form1

'

Me.AutoScale BaseSize = New System.Drawing. Size(5, 13)

Me.ClientSiz e = New System.Drawing. Size(328, 204)

Me.Controls. Add(Me.TextBox2 )

Me.Controls. Add(Me.TextBox1 )

Me.Controls. Add(Me.button1)

Me.Controls. Add(Me.button2)

Me.Controls. Add(Me.button3)

Me.Name = "Form1"

Me.Text = "Form1"

Me.ResumeLay out(False)

Me.PerformLa yout()

End Sub 'InitializeComp onent

#End Region

<STAThread() Shared Sub Main()

Application. Run(New Form1)

End Sub 'Main

Private Sub button1_Click(B yVal sender As Object, ByVal e As
System.Event Args) Handles button1.Click

Dim dlg As New OpenFileDialog

dlg.Filter = "GIF files|*.GIF"

If dlg.ShowDialog( ) = DialogResult.OK Then

Dim zz As Image = Image.FromFile( dlg.FileName)

Dim DataO As New DataObject

DataO.SetDat a(DataFormats.B itmap, False, CType(zz, Bitmap))

DataO.SetDat a(DataFormats.P alette.ToString , False, zz.Palette)

Clipboard.Se tDataObject(Dat aO, False)

End If

End Sub 'button1_Click

Private Sub button2_Click(B yVal sender As Object, ByVal e As
System.Event Args) Handles button2.Click

Dim DataO As DataObject = CType(Clipboard .GetDataObject( ), DataObject)

If DataO.GetDataPr esent(DataForma ts.Palette, False) Then

cp = CType(DataO.Get Data(DataFormat s.Palette), ColorPalette)

If cp Is Nothing Then

MessageBox.S how("Contains palette that is Nothing")

Else

MessageBox.S how(cp.ToString )

End If

Else

MessageBox.S how("No Palette on Clipboard")

End If
End Sub 'button2_Click

Private Sub button3_Click(B yVal sender As Object, ByVal e As
System.Event Args) Handles button3.Click

Application. Exit()

End Sub 'button3_Click

Private Sub Timer1_Tick(ByV al sender As Object, ByVal e As
System.Event Args)
Handles Timer1.Tick

Dim DataO As DataObject = CType(Clipboard .GetDataObject( ), DataObject)

If DataO.GetDataPr esent(DataForma ts.Palette, False) Then

Dim cp As ColorPalette = CType(DataO.Get Data(DataFormat s.Palette),
ColorPalette )

TextBox2.Tex t = "There is a Palette on the Clipboard"

Else

TextBox2.Tex t = "The Clipboard does not contain a Palette"

End If

End Sub

End Class 'Form1





Jul 5 '07 #5
Here are the steps:
1) OpenClipboard
2) IsClipboardForm atAvailable(CF_ PALETTE)
3) If true, then GetClipboardDat a(CF_PALETTE)
4) Use OleDuplicateDat a to duplicate the palette handle as the clipboard
owns the HPALETTE
5) Use GetObject to get the number of palette entries
6) Use GetPaletteEntri es to retrieve the palette
7) Use Image property Palette to get the current ColorPalette from the image
8) Use the palette from step 5 to populate the ColorPalette object with the
new palette
9) Assign the Image.Palette property with the new palette
10) CloseClipboard

" active" <ac********** @a-znet.comwrote in message
news:uW******** ******@TK2MSFTN GP05.phx.gbl...
>
I forgot the IsClipboardForm atAvailable lines
Then I put it in the wrong place
>>
>>The only non-DotNet way that I know of that I can use to put a Palette
on the clipboard is with Photoshop, which is what I use to test.

I do the following and always get HPalette=0
Public Declare Auto Function OpenClipboard Lib "user32" (ByVal hWnd As
IntPtr) As Integer

Public Declare Auto Function GetClipboardDat a Lib "user32" (ByVal
wFormat As Integer) As IntPtr
Public Declare Auto Function IsClipboardForm atAvailable Lib "user32"
(ByVal wFormat As Integer) As Boolean
>>>
Dim HPalette As IntPtr
Const CF_PALETTE As Integer = 9
If OpenClipboard(I ntPtr.Zero) <0 Then
>>If IsClipboardForm atAvailable(CF_ PALETTE) Then

HPalette = GetClipboardDat a(CF_PALETTE)


"Michael Phillips, Jr." <mp*********@no spam.jun0.c0mwr ote in message
news:uf****** ********@TK2MSF TNGP03.phx.gbl. ..
The DataFormats.Pal ette is a private clipboard format.

Perhaps Microsoft intended this format to represent the new
ColorPalet te format but they provided a flawed implementation of the
DataObject class.

When you query the clipboard using GetDataPresent( DataFormats.Pal ette,
false) or GetDataPresent( DataFormats.Pal ette, true), the return value
is true.

If you try to retrieve the data using GetData(DataFor mats.Palette), the
return value is null.

The canonical clipboard format is CF_PALETTE which is represented as an
GDI HPALETTE.

I am unaware of any application that uses the private clipboard format
DataFormats. Palette and places the palette on the clipboard as a
ColorPalet te object.

The Microsoft implementation of the DataObject class does not convert
the GDI HPALETTE to a ColorPalette object.

You need to do this on your own.

Use P-Invoke to get the HPALETTE using the CF_PALETTE clipboard format
and convert it to a new ColorPalette object using the GDI functions
GetObject and GetPaletteEntri es.
" active" <ac********** @a-znet.comwrote in message
news:OI***** *********@TK2MS FTNGP04.phx.gbl ...
Below is a small but complete program that appears to show you
can't retrive a Palette from the clipboard.
>
This is true whether the palette is placed on the clipboard by
Photoshop or
Photoshop or by the below program
>
It lets you place a palette from a file or from a program on the
clipboard and allows you to retrieve one from the clipboard. But
you'll find the retrieved one is always "Nothing"
>
I'd appreciate comments
>
>
>
Imports System.Drawing. Imaging
>
Public Class Form1
>
Inherits System.Windows. Forms.Form
>
Private WithEvents button1 As System.Windows. Forms.Button
>
Private WithEvents button2 As System.Windows. Forms.Button
>
Private WithEvents button3 As System.Windows. Forms.Button
>
Private components As System.Componen tModel.IContain er
>
Private cp As ColorPalette
>
Friend WithEvents ToolTip1 As System.Windows. Forms.ToolTip
>
Friend WithEvents TextBox1 As System.Windows. Forms.TextBox
>
Friend WithEvents TextBox2 As System.Windows. Forms.TextBox
>
Friend WithEvents Timer1 As System.Windows. Forms.Timer
>
Public Sub New()
>
InitializeC omponent()
>
End Sub 'New
>
Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
>
If disposing Then
>
If Not (components Is Nothing) Then
>
components. Dispose()
>
End If
>
End If
>
MyBase.Disp ose(disposing)
>
End Sub 'Dispose
>
#Region "Windows Form Designer generated code"
>
Private Sub InitializeCompo nent()
>
Me.componen ts = New System.Componen tModel.Containe r
>
Me.button 1 = New System.Windows. Forms.Button
>
Me.button 2 = New System.Windows. Forms.Button
>
Me.button 3 = New System.Windows. Forms.Button
>
Me.ToolTi p1 = New System.Windows. Forms.ToolTip(M e.components)
>
Me.TextBo x1 = New System.Windows. Forms.TextBox
>
Me.TextBo x2 = New System.Windows. Forms.TextBox
>
Me.Timer1 = New System.Windows. Forms.Timer(Me. components)
>
Me.SuspendL ayout()
>
'
>
'button1
>
'
>
Me.button1. Location = New System.Drawing. Point(186, 124)
>
Me.button1. Name = "button1"
>
Me.button1. Size = New System.Drawing. Size(130, 24)
>
Me.button1. TabIndex = 2
>
Me.button1. Text = "Copy File Palette"
>
Me.ToolTip1 .SetToolTip(Me. button1, "Copy Palette from a GIF file to
the
clipboard ")
>
'
>
'button2
>
'
>
Me.button2. Location = New System.Drawing. Point(13, 124)
>
Me.button2. Name = "button2"
>
Me.button2. Size = New System.Drawing. Size(156, 24)
>
Me.button2. TabIndex = 2
>
Me.button2. Text = "Retrieve Clipboard Palette"
>
Me.ToolTip1 .SetToolTip(Me. button2, "Retrieve a palette from the
clipboard ")
>
'
>
'button3
>
'
>
Me.button3. Location = New System.Drawing. Point(88, 167)
>
Me.button3. Name = "button3"
>
Me.button3. Size = New System.Drawing. Size(130, 24)
>
Me.button3. TabIndex = 2
>
Me.button3. Text = "Exit"
>
'
>
'TextBox1
>
'
>
Me.TextBox1 .Location = New System.Drawing. Point(12, 24)
>
Me.TextBox1 .Multiline = True
>
Me.TextBox1 .Name = "TextBox1"
>
Me.TextBox1 .Size = New System.Drawing. Size(304, 47)
>
Me.TextBox1 .TabIndex = 3
>
Me.TextBox1 .Text = "Palette can be placed on clipboard by using the
'Save
Palette"" button or by some " & _
>
"external program such as Photoshop"
>
'
>
'TextBox2
>
'
>
Me.TextBox2 .Location = New System.Drawing. Point(13, 85)
>
Me.TextBox2 .Name = "TextBox2"
>
Me.TextBox2 .Size = New System.Drawing. Size(302, 20)
>
Me.TextBox2 .TabIndex = 4
>
'
>
'Timer1
>
'
>
Me.Timer1.E nabled = True
>
'
>
'Form1
>
'
>
Me.AutoScal eBaseSize = New System.Drawing. Size(5, 13)
>
Me.ClientSi ze = New System.Drawing. Size(328, 204)
>
Me.Controls .Add(Me.TextBox 2)
>
Me.Controls .Add(Me.TextBox 1)
>
Me.Controls .Add(Me.button1 )
>
Me.Controls .Add(Me.button2 )
>
Me.Controls .Add(Me.button3 )
>
Me.Name = "Form1"
>
Me.Text = "Form1"
>
Me.ResumeLa yout(False)
>
Me.PerformL ayout()
>
End Sub 'InitializeComp onent
>
#End Region
>
<STAThread( )Shared Sub Main()
>
Application .Run(New Form1)
>
End Sub 'Main
>
Private Sub button1_Click(B yVal sender As Object, ByVal e As
System.Even tArgs) Handles button1.Click
>
Dim dlg As New OpenFileDialog
>
dlg.Filte r = "GIF files|*.GIF"
>
If dlg.ShowDialog( ) = DialogResult.OK Then
>
Dim zz As Image = Image.FromFile( dlg.FileName)
>
Dim DataO As New DataObject
>
DataO.SetDa ta(DataFormats. Bitmap, False, CType(zz, Bitmap))
>
DataO.SetDa ta(DataFormats. Palette.ToStrin g, False, zz.Palette)
>
Clipboard.S etDataObject(Da taO, False)
>
End If
>
End Sub 'button1_Click
>
Private Sub button2_Click(B yVal sender As Object, ByVal e As
System.Even tArgs) Handles button2.Click
>
Dim DataO As DataObject = CType(Clipboard .GetDataObject( ), DataObject)
>
If DataO.GetDataPr esent(DataForma ts.Palette, False) Then
>
cp = CType(DataO.Get Data(DataFormat s.Palette), ColorPalette)
>
If cp Is Nothing Then
>
MessageBox. Show("Contains palette that is Nothing")
>
Else
>
MessageBox. Show(cp.ToStrin g)
>
End If
>
Else
>
MessageBox. Show("No Palette on Clipboard")
>
End If
>
>
End Sub 'button2_Click
>
Private Sub button3_Click(B yVal sender As Object, ByVal e As
System.Even tArgs) Handles button3.Click
>
Application .Exit()
>
End Sub 'button3_Click
>
Private Sub Timer1_Tick(ByV al sender As Object, ByVal e As
System.Even tArgs)
Handles Timer1.Tick
>
Dim DataO As DataObject = CType(Clipboard .GetDataObject( ), DataObject)
>
If DataO.GetDataPr esent(DataForma ts.Palette, False) Then
>
Dim cp As ColorPalette = CType(DataO.Get Data(DataFormat s.Palette),
ColorPalett e)
>
TextBox2.Te xt = "There is a Palette on the Clipboard"
>
Else
>
TextBox2.Te xt = "The Clipboard does not contain a Palette"
>
End If
>
End Sub
>
End Class 'Form1
>
>
>




Jul 5 '07 #6
Thanks a lot for staying with this.
I can't think of anything to do that might help move forward even a little.
"Michael Phillips, Jr." <mp*********@no spam.jun0.c0mwr ote
Here are the steps:
1) OpenClipboard
2) IsClipboardForm atAvailable(CF_ PALETTE)
3) If true, then GetClipboardDat a(CF_PALETTE)
....snip

Isn't the above the same as I showed below.
If it is, step 3 always produces zero
I can't seem to get past that

Thanks again the info
....snip...
>I do the following and always get HPalette=0
Public Declare Auto Function OpenClipboard Lib "user32" (ByVal hWnd As
IntPtr) As Integer

Public Declare Auto Function IsClipboardForm atAvailable Lib "user32"
(ByVal wFormat As Integer) As Boolean

Public Declare Auto Function GetClipboardDat a Lib "user32" (ByVal wFormat
As Integer) As IntPtr

Dim HPalette As IntPtr
Const CF_PALETTE As Integer = 9
If OpenClipboard(I ntPtr.Zero) <0 Then
If IsClipboardForm atAvailable(CF_ PALETTE) Then
HPalette = GetClipboardDat a(CF_PALETTE)
....snip
Jul 5 '07 #7
2) IsClipboardForm atAvailable(CF_ PALETTE)
3) If true, then GetClipboardDat a(CF_PALETTE)
GetClipboardDat a should return a valid handle.

If it returns null, then use GetLastError() to determine why.

Use the free clipboard viewer that comes with all versions of windows. It
will display the palette if there is a CF_PALETTE on the clipboard.
If OpenClipboard(I ntPtr.Zero) <0
You should use a valid window handle of your application's form window. Do
not use the default, the desktop's window.
" active" <ac********** @a-znet.comwrote in message
news:eL******** ******@TK2MSFTN GP02.phx.gbl...
Thanks a lot for staying with this.
I can't think of anything to do that might help move forward even a
little.
"Michael Phillips, Jr." <mp*********@no spam.jun0.c0mwr ote
>Here are the steps:
1) OpenClipboard
2) IsClipboardForm atAvailable(CF_ PALETTE)
3) If true, then GetClipboardDat a(CF_PALETTE)
...snip

Isn't the above the same as I showed below.
If it is, step 3 always produces zero
I can't seem to get past that

Thanks again the info
...snip...
>>I do the following and always get HPalette=0
Public Declare Auto Function OpenClipboard Lib "user32" (ByVal hWnd As
IntPtr) As Integer

Public Declare Auto Function IsClipboardForm atAvailable Lib "user32"
(ByVal wFormat As Integer) As Boolean

Public Declare Auto Function GetClipboardDat a Lib "user32" (ByVal
wFormat As Integer) As IntPtr

Dim HPalette As IntPtr
Const CF_PALETTE As Integer = 9
If OpenClipboard(I ntPtr.Zero) <0 Then
If IsClipboardForm atAvailable(CF_ PALETTE) Then
HPalette = GetClipboardDat a(CF_PALETTE)
...snip


Jul 5 '07 #8

"Michael Phillips, Jr." <mp*********@no spam.jun0.c0mwr ote in message
news:%2******** ********@TK2MSF TNGP06.phx.gbl. ..
Here are the steps:
1) OpenClipboard
2) IsClipboardForm atAvailable(CF_ PALETTE)
3) If true, then GetClipboardDat a(CF_PALETTE)
4) Use OleDuplicateDat a to duplicate the palette handle as the clipboard
owns the HPALETTE
5) Use GetObject to get the number of palette entries
6) Use GetPaletteEntri es to retrieve the palette
7) Use Image property Palette to get the current ColorPalette from the
image
8) Use the palette from step 5 to populate the ColorPalette object with
the new palette
9) Assign the Image.Palette property with the new palette
10) CloseClipboard
I'm still chipping away at this but wanted to say how much I appreciate the
precise instructions.

Thanks
Jul 8 '07 #9
It may be frustrating but you will learn a great deal by working through a
complete test case yourself!
" active" <ac********** @a-znet.comwrote in message
news:OV******** ******@TK2MSFTN GP03.phx.gbl...
>
"Michael Phillips, Jr." <mp*********@no spam.jun0.c0mwr ote in message
news:%2******** ********@TK2MSF TNGP06.phx.gbl. ..
>Here are the steps:
1) OpenClipboard
2) IsClipboardForm atAvailable(CF_ PALETTE)
3) If true, then GetClipboardDat a(CF_PALETTE)
4) Use OleDuplicateDat a to duplicate the palette handle as the clipboard
owns the HPALETTE
5) Use GetObject to get the number of palette entries
6) Use GetPaletteEntri es to retrieve the palette
7) Use Image property Palette to get the current ColorPalette from the
image
8) Use the palette from step 5 to populate the ColorPalette object with
the new palette
9) Assign the Image.Palette property with the new palette
10) CloseClipboard

I'm still chipping away at this but wanted to say how much I appreciate
the precise instructions.

Thanks

Jul 8 '07 #10

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
3693
by: floobles | last post by:
Hi, I'm trying to obtain the number of colors and possibly the color table of png files. However, most of my files are RGB (not palette) mode. Does anyone know how to obtain those info? I am using the png.h library. I have tried using the png_set_dither function to convert the rgb mode to palette mode, but did not succeed. (I would prefer to be able to directly get the info from RGB mode though.) Thanks, much appreciated.
0
1850
by: Jean-Sebastien Carle | last post by:
I've been ripping my hair our trying to get this to work for a week and I can't seem to get it. I'm trying to display a 4BppIndexed Bitmap from within the ntoskrnl.exe file that contains no palette. This bitmap is the one everyone likes to change to customize their boot screen. My goal is not to edit the kernel, but simply to display the bitmap content in much the same way a resource editor does. My problem is that no matter what I do, the...
4
4100
by: Just Me | last post by:
I asked this in the VB NG and didn't get a response. I think this NG is no apt to know this kind of thing so I'm trying here. Trying to display the palette that is on the clipboard. I get a palette from the clipboard and I want to make the picturebox display it and realize it as its palette. Actually the picturebox is on a usercontrol which is on the form containing this code.
0
1084
by: Micus | last post by:
Hi all, Does anyone have experience with using a palette with a progress control? Everything works fine with a scrollbar control, but I think there are issues with the progress control because it's a common control. For the scrollbar, I can select the palette in the WM_CTLCOLORSCROLLBAR message which works fine, but the progress bar does not send a similar message. The progress control displays and works fine, but the color of the bar and...
1
5822
by: Stuart | last post by:
I am using the Python Imaging Library (PIL) to process GIF images. I need to be able to retrieve the RGB values for each color palette entry. I see that the 'Image' class has a 'palette' attribute which returns an object of type 'ImagePalette'. However, the documentation is a bit lacking regarding how to maniuplate the ImagePalette class to retrieve the palette entries' RGB values. Can anyone point me to a short example? Thanks!
0
1126
by: active | last post by:
I asked this in VB without results. I'm not surprised that no one there knows anything about because it's kind of an uncommon subject. Maybe some one here knows. Dim DataO As DataObject = CType(Clipboard.GetDataObject(), DataObject) If DataO.GetDataPresent(DataFormats.Palette, False) Then Dim cp As ColorPalette = CType(DataO.GetData(DataFormats.Palette),
6
1304
by: active | last post by:
I asked this in VB without results. I'm not surprised that no one there knows anything about because it's kind of an uncommon subject. Maybe some one here knows. Dim DataO As DataObject = CType(Clipboard.GetDataObject(), DataObject) If DataO.GetDataPresent(DataFormats.Palette, False) Then Dim cp As ColorPalette = CType(DataO.GetData(DataFormats.Palette),
8
2504
by: active | last post by:
Guess I'm looking for someone who likes to work difficult puzzles. I can't seem to ever retrieve a palette handle from the clipboard. Below is a simple test program that demonstrates the problem. The program uses windows api to get a handle to a palette from the clipboard. The palette needs to be put there by another program - maybe Photoshop.
3
2396
by: krishnasamy | last post by:
Hi, I have writing the code for change the Palette color of the Bitmap. But I didn't get any different between given image and result image. Here I given my code, Bitmap *bmp=new Bitmap(L"skumar3.bmp"); INT size = bmp->GetPaletteSize();// bitmap->GetPaletteSize(); printf("The size of the palette is %d bytes.\n", size);
0
9568
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10168
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10008
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
9837
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
7381
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5423
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3929
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3532
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2806
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.