public IntPtr GetHandle() { StringBuilder lpszFileName = new StringBuilder(260); IntPtr foregroundWindow = TaskDialogNative.GetForegroundWindow(); TaskDialogNative.GetWindowModuleFileName(foregroundWindow, lpszFileName, 260U); if (Path.GetFileName(lpszFileName.ToString().Replace(".vshost", "")) == Path.GetFileName(Assembly.GetEntryAssembly().Location)) { return(foregroundWindow); } return(IntPtr.Zero); }
public IntPtr GetHandle() { StringBuilder fileNameSelf = new StringBuilder(260); StringBuilder fileNameActive = new StringBuilder(260); IntPtr foregroundWindow = TaskDialogNative.GetForegroundWindow(); TaskDialogNative.GetWindowModuleFileName(foregroundWindow, fileNameActive, 260U); TaskDialogNative.GetModuleFileName(IntPtr.Zero, fileNameSelf, fileNameSelf.Capacity); if (Path.GetFileName(fileNameActive.ToString().Replace(".vshost", "")) == Path.GetFileName(fileNameSelf.ToString())) { return(foregroundWindow); } return(IntPtr.Zero); }