Click here to Skip to main content
16,004,927 members
Home / Discussions / C#
   

C#

 
GeneralRe: How to start a form from another thread Pin
Michael Potter20-Dec-04 11:11
Michael Potter20-Dec-04 11:11 
GeneralRe: How to start a form from another thread Pin
SebbaP20-Dec-04 20:59
SebbaP20-Dec-04 20:59 
GeneralProblem getting array out of arraylist Pin
sciamachy20-Dec-04 6:20
sciamachy20-Dec-04 6:20 
GeneralRe: Problem getting array out of arraylist Pin
Heath Stewart20-Dec-04 6:33
protectorHeath Stewart20-Dec-04 6:33 
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 
Hello,

I run the program below to handle winmessages from an application written in a 4GL. If I close the 4GL window which uses this program, the C# program receives the WM_DESTROY message, but rebuilding the C# program after that fails because it is 'in use'. I suspect that I have to dispose some objects on WM_DESTROY? How can I code for that? I just started learning C#, if you can point me to some info about this I would be happy too.

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

namespace WindowsApplication1
{
[ClassInterface(ClassInterfaceType.AutoDual)]
public class GenericWindow : NativeWindow
{
public const int WM_ERASEBKGND = 0x14;
public const int WM_DESTROY = 0x0002;
private const int GWL_WNDPROC = -4;
private const int WM_SYNCPAINT = 0x0088;
private const int WM_NCPAINT = 0x0085;
private const int WM_PAINT = 0x000F;
private IntPtr oldWndProc = IntPtr.Zero;
private Win32WndProc newWndProc = null;
private int hIcon;

#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 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()
{

}

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();
}
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();
return pHandle;
case WM_DESTROY:
pHandle = CallWindowProc(oldWndProc, hWnd,Msg, wParam, lParam);


//MessageBox.Show("dest");
return pHandle;
default:
return CallWindowProc(oldWndProc, hWnd, Msg,
wParam, lParam);
}
}


public void PaintExtras()
{
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, 1, 1, hIcon);
ret = DestroyIcon (hIcon);
ret = ReleaseDC(this.Handle.ToInt32(),hdc);
}
}
}
}


regards,

Stefan.
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 
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 

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.