http://www.orangemaker.sakura.ne.jp/labo/memo/sdk-mfc/win7Desktop.html
を読んで"WorkerW"でいいんだろうと思い、buttonに端から登録して実行してみました。すると、非表示にはなりませんがおかしな挙動を取ります。
ここでは、タスクバー内でアイコンがスライドするような動きですね。
目的は「フォーム最背面に移動させる」です。
最背面に移動させる方法自体は見つけたのですが、OS上の違いなどあるのではと思い質問してみました。windows10上でこのコードを動作させるには何が必要なのでしょうか?
C#
1using System; 2using System.Runtime.InteropServices; 3using System.Windows.Forms; 4 5namespace WindowsFormsApplication9 6{ 7 public partial class Form1 : Form 8 { 9 // HWND GetDesktopWindow(VOID); 10 [DllImport("User32.Dll")] 11 static extern IntPtr GetDesktopWindow(); 12 13 14 [DllImport("User32.dll")] 15 static extern int SetForegroundWindow( 16 IntPtr hWnd 17 ); 18 [System.Runtime.InteropServices.DllImport("user32.dll", SetLastError = true)] 19 static extern IntPtr FindWindow(string lpClassName, string lpWindowName); 20 21 [System.Runtime.InteropServices.DllImport("user32.dll")] 22 static extern IntPtr SetParent(IntPtr hWndChild, IntPtr hWndNewParent); 23 24 25 public Form1() 26 { 27 InitializeComponent(); 28 29 MinimizeBox = false; 30 } 31 32 private void Form1_Deactivate(object sender, EventArgs e) 33 { 34 MinimizeBox = false; 35 // this.Focus(); 36 this.TopMost = true; 37 // this.TopMost = false; 38 39 } 40 41 private void button1_Click(object sender, EventArgs e) 42 { 43 44 //http://nanoappli.com/blog/archives/1844 45 46 IntPtr WinHandle = FindWindow(null, "WorkerW"); 47 if (WinHandle != null) 48 { 49 SetParent(this.Handle, WinHandle); 50 51 52 } 53 54 } 55 56 private void button2_Click(object sender, EventArgs e) 57 { 58 IntPtr WinHandle = GetDesktopWindow(); 59 if (WinHandle != null) 60 { 61 SetParent(this.Handle, WinHandle); 62 } 63 } 64 65 private void button4_Click(object sender, EventArgs e) 66 { 67 IntPtr WinHandle = FindWindow(null, "SHELLDLL_DefView"); 68 if (WinHandle != null) 69 { 70 SetParent(this.Handle, WinHandle); 71 72 73 } 74 } 75 76 77 78 79 } 80} 81 82```」 83 84 85挙動を記録した動画 86https://www.youtube.com/watch?v=BKodO_PNwhQ&feature=youtu.be
回答3件
あなたの回答
tips
プレビュー