Click here to Skip to main content
15,914,500 members
Home / Discussions / C#
   

C#

 
GeneralRe: Problem getting array out of arraylist Pin
CoolDadTx21-Dec-04 4:11
CoolDadTx21-Dec-04 4:11 
GeneralStreams and Unmanaged code Pin
Tristan Rhodes20-Dec-04 5:44
Tristan Rhodes20-Dec-04 5:44 
GeneralRe: Streams and Unmanaged code Pin
Heath Stewart20-Dec-04 6:38
protectorHeath Stewart20-Dec-04 6:38 
GeneralNativeWindow disposing on WM_DESTROY Pin
stefan houtz20-Dec-04 0:53
stefan houtz20-Dec-04 0:53 
GeneralRe: NativeWindow disposing on WM_DESTROY Pin
Heath Stewart20-Dec-04 5:57
protectorHeath Stewart20-Dec-04 5:57 
GeneralRe: NativeWindow disposing on WM_DESTROY Pin
stefan houtz21-Dec-04 1:05
stefan houtz21-Dec-04 1:05 
GeneralRe: NativeWindow disposing on WM_DESTROY Pin
Heath Stewart21-Dec-04 7:55
protectorHeath Stewart21-Dec-04 7:55 
GeneralRe: NativeWindow disposing on WM_DESTROY Pin
stefan houtz22-Dec-04 2:52
stefan houtz22-Dec-04 2:52 
Thank you. The code compiles now, but I still get errors stating that files are in use on rebuilding after I closed the 4GL window. With spy++ I see as last received messages WM_ESTROY and WM_NCDESTROY.
I placed a debugging message in de decontructor ~GenericWindow(), it does not show up after the closingaction. Calling Dispose() from within my 4GL does not help either. Any idea how to get this working?

using System;
using System.Windows.Forms;
using System.Runtime.InteropServices;

namespace WindowsApplication1
{
[ClassInterface(ClassInterfaceType.AutoDual)]
public class GenericWindow : NativeWindow, IDisposable
{
private delegate Int32 EnumChildProc(IntPtr hWnd, IntPtr lParam);
private const int GWL_WNDPROC = -4;
private const int WM_PAINT = 0x000F;
private IntPtr oldWndProc = IntPtr.Zero;
private Win32WndProc newWndProc = null;
private int hIcon;
private int XPos;
private int YPos;

#region Imported User32.DLL functions

[DllImport("user32.dll", CharSet=CharSet.Auto)]
static public extern int GetDC(int hWnd);
[DllImport("user32.dll", CharSet=CharSet.Auto)]
public static extern int ReleaseDC(int hWnd,int hDc);
[DllImport("User32.dll")]
private static extern int DestroyIcon(int hIcon);
[DllImport("user32.dll")]
public static extern int DrawIcon(int hdc, int x,int y, int hIcon);
[DllImport("user32.dll", EntryPoint="CallWindowProc")]
private static extern int CallWindowProc(IntPtr lpPrevWndFunc, IntPtr hWnd, int Msg, int wParam, int lParam);
[DllImport("shell32.dll", CharSet=CharSet.Auto)]
public static extern int ExtractIcon(int hInst, string lpszExeFileName, int nIconIndex);
[DllImport("user32.dll")]
private static extern IntPtr SetWindowLong(IntPtr hWnd, int nIndex, Win32WndProc newProc);
[DllImport("user32.dll")]
private static extern IntPtr SetWindowLong(IntPtr hWnd, int nIndex, IntPtr newProc);
[DllImport("user32.dll")]
private static extern IntPtr GetWindowLong(IntPtr hWnd, int nIndex);

#endregion

// A delegate that matches Win32 WNDPROC:
private delegate int Win32WndProc(IntPtr hWnd, int Msg, int wParam, int lParam);

public GenericWindow()
{

}

~GenericWindow()
{ MessageBox.Show("destr");
Dispose(false);
}

void IDisposable.Dispose()
{
Dispose(true);
GC.SuppressFinalize(this);
}

protected virtual void Dispose(bool disposing)
{
if (disposing)
{
// Dispose managed resources
}
// Dispose unmanaged resources. Ex: NativeWindow.DestroyHandle
this.DestroyHandle();
}

public void NotifyWindow(int windowHandle)
{
this.AssignHandle((IntPtr)windowHandle);
oldWndProc = GetWindowLong((IntPtr)windowHandle,GWL_WNDPROC);
newWndProc = new Win32WndProc(MyWndProc);
SetWindowLong((IntPtr)windowHandle, GWL_WNDPROC,newWndProc);
PaintExtras(1,1);
}
private int MyWndProc(IntPtr hWnd, int Msg, int
wParam, int lParam)
{
int pHandle;
switch(Msg)
{
case WM_PAINT:
pHandle = CallWindowProc(oldWndProc, hWnd,Msg, wParam, lParam);
PaintExtras(XPos, YPos);
return pHandle;
default:
return CallWindowProc(oldWndProc, hWnd, Msg, wParam, lParam);
}
}

public void setPos(int xPos, int yPos)
{
XPos = xPos;
YPos = yPos;
}

private void PaintExtras(int xPos, int yPos)
{
XPos = xPos;
YPos = yPos;
int hdc = GetDC(this.Handle.ToInt32());
if (hdc != 0)
{
hIcon = ExtractIcon(this.Handle.ToInt32(),"C:\\progress10\\wrk\\experim\\down.ico",0);
int ret = DrawIcon (hdc, xPos, yPos, hIcon);
ret = DestroyIcon (hIcon);
ret = ReleaseDC(this.Handle.ToInt32(),hdc);
}
}
}
}

regards,

Stefan.
GeneralRe: NativeWindow disposing on WM_DESTROY Pin
Heath Stewart22-Dec-04 6:38
protectorHeath Stewart22-Dec-04 6:38 
GeneralRe: NativeWindow disposing on WM_DESTROY Pin
stefan houtz27-Dec-04 6:01
stefan houtz27-Dec-04 6:01 
GeneralDataTable.ColumnChanged doesn't rais an event after ReadXml() Pin
Dogan Gunay20-Dec-04 0:05
Dogan Gunay20-Dec-04 0:05 
Generalhelp request..., Pin
50519-Dec-04 23:56
50519-Dec-04 23:56 
GeneralRe: help request..., Pin
Colin Angus Mackay20-Dec-04 1:46
Colin Angus Mackay20-Dec-04 1:46 
Generalpropagating datagrid changes in the source database tables Pin
Rashid_Mehmood19-Dec-04 23:24
Rashid_Mehmood19-Dec-04 23:24 
GeneralRe: propagating datagrid changes in the source database tables Pin
Skynyrd20-Dec-04 0:13
Skynyrd20-Dec-04 0:13 
GeneralRe: propagating datagrid changes in the source database tables Pin
siddlingaSwami20-Dec-04 2:03
susssiddlingaSwami20-Dec-04 2:03 
GeneralReal Time Display Sound WaveForm While Acquiring Pin
Siew Eng19-Dec-04 19:22
Siew Eng19-Dec-04 19:22 
GeneralLate Bound Assemblies and SoapFormatter.Deserialize problem... Pin
Chris Richner19-Dec-04 14:53
Chris Richner19-Dec-04 14:53 
GeneralRe: Late Bound Assemblies and SoapFormatter.Deserialize problem... Pin
Daniel Turini19-Dec-04 17:13
Daniel Turini19-Dec-04 17:13 
GeneralRe: Late Bound Assemblies and SoapFormatter.Deserialize problem... Pin
Chris Richner19-Dec-04 21:51
Chris Richner19-Dec-04 21:51 
GeneralRe: Late Bound Assemblies and SoapFormatter.Deserialize problem... Pin
Chris Richner19-Dec-04 22:25
Chris Richner19-Dec-04 22:25 
Generalhashtable in extended properties Pin
esakal19-Dec-04 14:19
esakal19-Dec-04 14:19 
Generalhashtable in extended properties Pin
esakal19-Dec-04 14:09
esakal19-Dec-04 14:09 
Generaldynamically create multiple controls Pin
fredza19-Dec-04 8:04
fredza19-Dec-04 8:04 
GeneralRe: dynamically create multiple controls Pin
Heath Stewart20-Dec-04 6:28
protectorHeath Stewart20-Dec-04 6:28 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.