.NET下,如何使windows应用程序最小化之后回到任务栏右边(在日期旁边)?

wwfttelne 2003-09-16 05:20:22
我在编写一个小玩意,如果最小化之后,回到任务栏右边,可能效果更酷。
有什么办法实现吗?
我现在一点头绪也没有。

另外,有些应用程序,启动后,就会启用一些快捷键。
比如ctrl+alt+z
这样可以激发一些事件,比如使应用程序弹回桌面。
这个是怎么实现的呢?
...全文
107 8 打赏 收藏 转发到动态 举报
写回复
用AI写文章
8 条回复
切换为时间正序
请发表友善的回复…
发表回复
lengfeng8866 2004-01-06
  • 打赏
  • 举报
回复
keep it
wwfttelne 2003-09-16
  • 打赏
  • 举报
回复
一番挣扎,我总算把任务栏图标问题解决。


快捷键难度有点大,需要用到win32 api 暂时还没有实现。


书到用时方恨少啊!
wwfttelne 2003-09-16
  • 打赏
  • 举报
回复
notifyicon我加进去了。
可是一些我想要的功能还是实现不了。
比如:点击最小化,程序消失,点击任务栏的图标,程序出现。


还有上面那个人给的快捷键方法太复杂。

能不能先说说思想?
wwfttelne 2003-09-16
  • 打赏
  • 举报
回复
好啊,终于有人回复了。
今天晚上我就看看。
争取在自己的机器上实现。
kuangren 2003-09-16
  • 打赏
  • 举报
回复
用notifyicon不就行了么,
调用winapi不好移植
AhBian 2003-09-16
  • 打赏
  • 举报
回复
上面 Msg.WM_HOTKEY = 0x0312


以下是相关的一些代码,是从我的项目中扣出来,有点支离破碎的,难免有错。

public struct RECT
{
public int left;
public int top;
public int right;
public int bottom;
public static RECT FromRectangle(Rectangle rc)
{
RECT RCTO = new RECT();
RCTO.left = rc.Left;
RCTO.top = rc.Top;
RCTO.right = rc.Right;
RCTO.bottom = rc.Bottom;
return RCTO;
}
}

[StructLayout(LayoutKind.Sequential)]
public struct POINT
{
public POINT(Point point)
{
this.x = point.X;
this.y = point.Y;
}

public Point ToPoint()
{
return new Point(this.x, this.y);
}
public int x;
public int y;
}

[StructLayout(LayoutKind.Sequential, CharSet=CharSet.Auto)]
public struct WINDOWPLACEMENT
{
public uint length;
public uint flags;
public uint showCmd;
public POINT ptMinPosition;
public POINT ptMaxPosition;
public RECT rcNormalPosition;
}

public enum ShowWindowStyles : uint
{
SW_HIDE = 0,
SW_SHOWNORMAL = 1,
SW_NORMAL = 1,
SW_SHOWMINIMIZED = 2,
SW_SHOWMAXIMIZED = 3,
SW_MAXIMIZE = 3,
SW_SHOWNOACTIVATE = 4,
SW_SHOW = 5,
SW_MINIMIZE = 6,
SW_SHOWMINNOACTIVE = 7,
SW_SHOWNA = 8,
SW_RESTORE = 9,
SW_SHOWDEFAULT = 10,
SW_FORCEMINIMIZE = 11,
SW_MAX = 11
}

[Flags]
public enum KeyModifiers
{
None = 0x00,
Alt = 0x01,
Ctrl = 0x02,
Shift = 0x04,
Window = 0x08
}


[DllImport("user32.dll", CharSet=CharSet.Auto)]
static public extern bool ShowWindowAsync(IntPtr hWnd, short State);

[DllImport("user32.dll", CharSet=CharSet.Auto)]
static public extern bool SetForegroundWindow(IntPtr hWnd);

[DllImport("user32.dll", CharSet=CharSet.Auto)]
public static extern bool GetWindowPlacement(IntPtr hWnd, ref WINDOWPLACEMENT wp);

[DllImport("kernel32.dll", ExactSpelling=true, CharSet=CharSet.Auto)]
public static extern int GetLastError();

[DllImport("Kernel32.dll", CharSet=CharSet.Auto)]
public static extern int GlobalAddAtom(string lpString);

[DllImport("Kernel32.dll", CharSet=CharSet.Auto)]
public static extern int GlobalDeleteAtom(int nAtom);

[DllImport("user32.dll", ExactSpelling=true, CharSet=CharSet.Auto, SetLastError = true)]
public static extern bool RegisterHotKey(IntPtr hWnd, int id, KeyModifiers fsModifiers, System.Windows.Forms.Keys vKey);

[DllImport("user32.dll", ExactSpelling=true, CharSet=CharSet.Auto, SetLastError = true)]
public static extern bool UnregisterHotKey(IntPtr hWnd, int id);

AhBian 2003-09-16
  • 打赏
  • 举报
回复
窗体最小化后,将 ShowInTaskBar 置为 false. NotifyIcon 是必须的。但 .NET 的 NotifyIcon 并不完美。查一下帖,斑竹 ARLI 2003 最近刚发表一个有关 NotifyIcon 的好帖。

系统快捷键,需要使用一个自定义类,调用系统 API 实现。
public class AppHotKey : System.Windows.Forms.NativeWindow, IDisposable
{
// Error codes
const int ERROR_HOTKEY_ALREADY_REGISTERED = 1409;

// Member variables
private int m_AtomID = 0;
private bool registerSuccess;
private KeyModifiers hotKeyMod;
private Keys hotKey;

public AppHotKey(IntPtr handle, KeyModifiers modifiers, Keys hotKey)//
{
if (!WindowsAPI.IsWindow(handle))
throw new ArgumentException();

this.hotKey = hotKey;
this.hotKeyMod = modifiers;

this.AssignHandle(handle);
m_AtomID = WindowsAPI.GlobalAddAtom(DateTime.Now.ToString());
registerSuccess = WindowsAPI.RegisterHotKey(handle, m_AtomID, modifiers, hotKey);
if (!registerSuccess)
{
if (WindowsAPI.GetLastError() == ERROR_HOTKEY_ALREADY_REGISTERED)
throw new InvalidOperationException();
}
}

~AppHotKey()
{
this.Dispose(false);
}

public Keys HotKey
{
get
{
return hotKey;
}
}

public KeyModifiers ModifierKey
{
get
{
return hotKeyMod;
}
}

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

protected virtual void Dispose(bool disposing)
{
lock(this)
{
if (disposing)
{
}
try
{
// Unregister the hotkey.
if (registerSuccess)
WindowsAPI.UnregisterHotKey(this.Handle, m_AtomID);

if (m_AtomID != 0)
{
// Delete Atom
WindowsAPI.GlobalDeleteAtom(m_AtomID);
m_AtomID = 0;
}
}
catch
{
}
}
}

protected override void WndProc(ref Message m)
{
base.WndProc(ref m);

switch(m.Msg)
{
case (int)Msg.WM_HOTKEY:
this.ProcessHotKey();
break;
}
}

protected virtual void ProcessHotKey()
{
WINDOWPLACEMENT wp = new WINDOWPLACEMENT();
wp.length = (uint)Marshal.SizeOf(typeof(WINDOWPLACEMENT));
WindowsAPI.GetWindowPlacement(this.Handle, ref wp);
//Make sure the window is not minimized or maximized
if (wp.showCmd == (uint)ShowWindowStyles.SW_SHOWMAXIMIZED)
WindowsAPI.ShowWindowAsync(this.Handle,(short)ShowWindowStyles.SW_MAXIMIZE);
else
WindowsAPI.ShowWindowAsync(this.Handle,(short)ShowWindowStyles.SW_SHOWNORMAL);
//Set the real intance to foreground window
WindowsAPI.SetForegroundWindow(this.Handle);

}
}

这是我实现的一个类
维她奶 2003-09-16
  • 打赏
  • 举报
回复
1.将窗体的MaximiseBox、MinimiseBox、ShowInTaskbar属性均设置为False。
2.再往窗体上NotifyIcon控件。

这是最简单的托盘程序,其他的功能就要自己加上去了^^

110,538

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Web++
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧