- PR -

ShowInTaskbarをFalseに設定した時の挙動

投稿者投稿内容
清華
ベテラン
会議室デビュー日: 2005/12/21
投稿数: 50
投稿日時: 2006-01-12 15:48
僕のところからは問題なく飛べますが…なぜでしょうか?

一応引用しておきますね
引用:

BUG: The icon that represents your form appears as a blank form icon in Visual C# .NET if you set the ShowInTaskBar property to False

SYMPTOMS
You set the ShowInTaskBar property of a Microsoft Windows form to False. When you press the ALT+TAB key combination to move the control focus from the form to any other program, the icon that represents your form appears as a blank form icon.

WORKAROUND
To make sure that the correct icon appears when you press the ALT+TAB key combination to move the control focus from the form to any other program while the ShowInTaskbar property is set to False, use the following code.
コード:
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
using System.Runtime.InteropServices;
namespace WindowsApplication1
{
	/// <summary>
	/// Summary description for Form1.
	/// </summary>
	public class Form1 : System.Windows.Forms.Form
	{
		/// <summary>
		/// Required designer variable.
		/// </summary>
		private System.ComponentModel.Container components = null;
		public Form1()
		{
			//
			// Required for Windows Form Designer support
			//
			InitializeComponent();

			//
			// TODO: Add any constructor code after InitializeComponent call
			//
		}
		/// <summary>
		/// Clean up any resources being used.
		/// </summary>
		protected override void Dispose( bool disposing )
		{
			if( disposing )
			{
				if (components != null)
				{
					components.Dispose();
				}
			}
			base.Dispose( disposing );
		}
		#region Windows Form Designer generated code
		/// <summary>
		/// Required method for Designer support - do not modify
		/// the contents of this method with the code editor.
		/// </summary>
		private void InitializeComponent()
		{
			System.Resources.ResourceManager resources = new System.Resources.ResourceManager(typeof(Form1));
			//
			// Form1
			//
			this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
			this.ClientSize = new System.Drawing.Size(292, 266);
			this.Icon = ((System.Drawing.Icon)(resources.GetObject("$this.Icon")));
			this.Name = "Form1";
			this.ShowInTaskbar = false;
			this.Text = "Form1";
			this.Load += new System.EventHandler(this.Form1_Load);
		}
		#endregion

		/// <summary>
		/// The main entry point for the application.
		/// </summary>
		[STAThread]

		static void Main()
		{
			Application.Run(new Form1());
		}
		[DllImport("user32.dll")]
		private static extern int SendMessage(IntPtr hwnd, int message, int wParam, IntPtr lParam);
		[DllImport("user32.dll", ExactSpelling=true)]
		private static extern IntPtr GetWindow(IntPtr hwnd, int cmd);
		private IntPtr GetTopLevelOwner(Control c)
		{
			IntPtr hwndOwner = c.Handle;
			IntPtr hwndCurrent = c.Handle;
			while (hwndCurrent != (IntPtr)0)
			{
				hwndCurrent = GetWindow(hwndCurrent, GW_OWNER);
				if (hwndCurrent != (IntPtr)0) { hwndOwner = hwndCurrent; }
			}
			return hwndOwner;
                }
		private const int WM_SETICON = 0x80;
		private const int GW_OWNER = 4;
		private const int ICON_SMALL = 0;
		private const int ICON_BIG = 1;
		private void Form1_Load(object sender, System.EventArgs e)
		{
			SendMessage(GetTopLevelOwner(this), WM_SETICON, ICON_BIG, this.Icon.Handle);
                }
		private void Form1_Closed(object sender, System.EventArgs e)
		{
			SendMessage(GetTopLevelOwner(this), WM_SETICON, ICON_BIG, new IntPtr(0));
		}
	}
}




もっかいセットしなおせってことですね、結局は……。


引用:

STATUS
Microsoft has confirmed that this is a bug in the Microsoft products that are listed in the "Applies to" section.


ムックさん大正解ですね(笑。

加えて僕と似たような問題(?)持ってる方いますね
引用:

Joe Report As Irrelevant
Written: 6/10/2005 1:02 PM
This appears to work ok, except when I wish my app to start in minimized mode, and am using an NotifyIcon component, I don't want the application icon to show up in the Alt+Tab listing unless the actual form is visible... If I put the initial SendMessage in my Form_Loading event, then the icon shows up in the Alt+Tab list...


これに対する返信が無いことから結構難しいんでしょう……orz

こんなところです。
一応元記事URL: http://www.kbalertz.com/kb_836673.aspx
_________________
9uiet Design - http://quietdesign.rental.allinoneserver.net/
デザインにこだわったソフトの配布とプログラミングTipsの公開(予定)をしています。
9uiet Blog - http://seiga.blog44.fc2.com/
笑ったことやプログラミングのことなど書
じゃんぬねっと
ぬし
会議室デビュー日: 2004/12/22
投稿数: 7811
お住まい・勤務地: 愛知県名古屋市
投稿日時: 2006-01-12 15:57
引用:

清華さんの書き込み (2006-01-12 15:48) より:

僕のところからは問題なく飛べますが…なぜでしょうか?


今は大丈夫みたいです。
サーバが落ちていただけかもしれません。

引用:

一応引用しておきますね


ありがとうございます。
って、BUG でしたか... (^^;)

まあ、仕方なしですね... (;_ _)

_________________
C# と VB.NET の入門サイト
じゃんぬねっと日誌
さらだ
会議室デビュー日: 2003/07/11
投稿数: 17
投稿日時: 2006-02-28 00:54
なんかすごいひさしぶりの書き込みなのですが、先日Visual Studio 2005を
買ってきて、少しずつ触っているのですが、このバグ(たぶん)がまだ直ってないの
を知り、ちょっとがっかりしてしまいました。
以前時計のアプリを作った時に、私もこの問題にひっかかって、あれこれ調査した
のですが、根本的な解決にはならないのですが、私の見つけた回避法(Alt+Tab
でアイコンを表示させない方法)をご紹介させていただきます。

それは、FormBorderStyleでFixedToolWindowか、SizableToolWindowを
選択する事です。このどちらかを選ぶとAlt+Tabでアイコンは表示されません。
ただ、私が作りたかったのは、タイトルバーを持たないウインドウだったため、
Webであれこれ調べた結果、FixedToolWindowを選択し、さらにWindowsAPIの
SetWindowLongを使い、タイトルバーのないウインドウで、Alt+Tab時のアイコン
を非表示にすることに成功しました。
通常のタイトルバーを持つウインドウには使えない方法ですが、ご参考までに。
渋木宏明(ひどり)
ぬし
会議室デビュー日: 2004/01/14
投稿数: 1155
お住まい・勤務地: 東京
投稿日時: 2006-02-28 10:51
引用:

SetWindowLongを使い、タイトルバーのないウインドウで、Alt+Tab時のアイコン
を非表示にすることに成功しました。



フォーム生成時のウィンドウスタイル指定を変更するだけなら、Form.CreatePrams プロパティをオーバーライドでできると思います。

_________________
// 渋木宏明 (Hiroaki SHIBUKI)
// http://hidori.jp/
// Microsoft MVP for Visual C#
//
// @IT会議室 RSS 配信中: http://hidori.jp/rss/atmarkIT/

スキルアップ/キャリアアップ(JOB@IT)