Hi,
I'm having some problems with native code, where I'm attempting to activate a minimized window using the Win32 ShowWindow method. It all works like a charm, except, I have a DDE Server Interface added as a listener for DDE Commands, which, when the instance is created, adds a listener to the window. This causes the app to find a different Window handle when minimized, and I can then not restore the minimied window. When I remove the DDE instance, it successuflly finds the correct handle, and restores the window.
Since I'm accessing the window from the current process, it appears as if the listener takes over the process, and I would assume that this process would be the actuall DDE listener. My code is as follows:
[DLLImport("User32")]
public static extern int SetForegroundWindow(IntPtr hWnd);
[DLLImportAttribute("User32.DLL")]
public static extern bool ShowWindow(IntPtr hWnd, int nCmdShow);
public const int SW_RESTORE = 9;
...
static void Main(string[] args) {
Process[] procs = Process.GetProcesses();
Process thisProc = Process.GetCurrentProcess();
foreach (Process proc in procs) {
...
if (proc.ProcessName == thisProc.ProcessName && proc.Id != thisProc.Id) {
if (proc.Responding) {
IntPtr hWnd = proc.MainWindowHandle;
ShowWindow(hWnd, SW_RESTORE);
SetForegroundWindow(hWnd);
} else {
...
}
}
}
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
Application.Run(new AUIApplication());
}
Like I said, this code works perfectly without the DDE listener, which is defined in the main form like such:
...
DDE = new DDEQuery();
...
// DDEQuery:
DDEServer theServer = DDEServer.getInstance();
theServer.addListener(this);
I've had a look at the actual DDEServer code, and I can't really see anything wrong with it. The server works fine when commands are passed to it.
Either way, I am obviously not too clued up with how to work around this. Maybe there is a way that I could create the DDEServer instance on another process, so that it wouldn't replace or use my MainWindowHandle process?
If anyone has any idea how I could overcome this terribly confusing issue, which is literally keeping me awake for days in a row, it would be much much appreciated.
Thanx,
Pip
No one has replied yet! Why not be the first?
Sign in or Join us (it's free).