Ovviamente funziona! Grazie ho risolto tutti i problemi a compile time, ore mi resta da capire perché a run time non funziona....
Nello specifico
codice:
[DllImport("uxtheme.dll", EntryPoint="DrawThemeBackground", SetLastError = true)]
public extern static Int32 drawThemeBackground(IntPtr hTheme, IntPtr hdc, int iPartId, int iStateId, RECT pRect, IntPtr pClipRect);
RECT r = new RECT(new Rectangle(pos.X, pos.Y, Convert.ToInt32(btn_w), Convert.ToInt32(btn_h)));
IntPtr thema = openThemeData(this.Handle, "Window");
IntPtr hDC = g.GetHdc();
Int32 ret = drawThemeBackground(thema, hDC, 15, 1, r, IntPtr.Zero);
Non funziona drawThemeBackground invece di S_OK mi restituisce -2147467261
il codice vb .net è così:
codice:
<DllImport("Uxtheme", EntryPoint:="DrawThemeBackground", SetLastError:=True)> _
Friend Shared Function drawThemeBackground(ByVal hTheme As IntPtr, ByVal hDC As IntPtr, ByVal iPartId As Int32, ByVal iStateId As Int32, ByRef pRect As RECT, ByVal nullRECT As IntPtr) As <MarshalAs(UnmanagedType.Error)> Int32
End Function
Dim r As RECT = New RECT(New Rectangle(pos.X, pos.Y, btn_width, btn_height))
Dim thema As IntPtr = openThemeData(Me.Handle, "Window")
Dim hDC As IntPtr = g.GetHdc
Dim ret As Integer = drawThemeBackground(thema, hDC, 15, 1, r, IntPtr.Zero)
e ovviamente funziona in quanto ret == 0
ho controllato e r viene istanziato correttamente, thema e hDC sono IntPtr validi
g è un oggetto Graphics
codice:
IntPtr handle = new IntPtr(GetWindowDC(parent.Handle.ToInt32()));
Graphics g = Graphics.FromHdc(handle);
Proprio non riesco a venirne a capo suggerimenti?
Allego anche la classe completa in modo da dare più informazioni.
Per testare la classe dentro il metodo InitializeComponent()
codice:
titleButton myButton = new titleButton(this);
http://rapidshare.com/files/99298879...Button.cs.html