diff --git a/FacebookWidget.v11.suo b/FacebookWidget.v11.suo deleted file mode 100644 index 0af4706..0000000 Binary files a/FacebookWidget.v11.suo and /dev/null differ diff --git a/Form1.Designer.cs b/Form1.Designer.cs index c7735ee..c5e8836 100644 --- a/Form1.Designer.cs +++ b/Form1.Designer.cs @@ -38,6 +38,7 @@ private void InitializeComponent() this.label2 = new System.Windows.Forms.Label(); this.timer2 = new System.Windows.Forms.Timer(this.components); this.notifyIcon1 = new System.Windows.Forms.NotifyIcon(this.components); + this.timer3 = new System.Windows.Forms.Timer(this.components); this.tableLayoutPanel1.SuspendLayout(); ((System.ComponentModel.ISupportInitialize)(this.pictureBox1)).BeginInit(); this.tableLayoutPanel2.SuspendLayout(); @@ -145,6 +146,12 @@ private void InitializeComponent() this.notifyIcon1.Text = "FacebookWidget"; this.notifyIcon1.Visible = true; // + // timer3 + // + this.timer3.Enabled = true; + this.timer3.Interval = 50; + this.timer3.Tick += new System.EventHandler(this.timer3_Tick); + // // Form1 // this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 16F); @@ -182,6 +189,7 @@ private void InitializeComponent() private System.Windows.Forms.Label label2; private System.Windows.Forms.Timer timer2; private System.Windows.Forms.NotifyIcon notifyIcon1; + private System.Windows.Forms.Timer timer3; } } diff --git a/Form1.cs b/Form1.cs index e621e54..2ff3ccf 100644 --- a/Form1.cs +++ b/Form1.cs @@ -39,16 +39,34 @@ protected override CreateParams CreateParams private const UInt32 SWP_NOMOVE = 0x0002; private const UInt32 TOPMOST_FLAGS = SWP_NOMOVE | SWP_NOSIZE; - [System.Runtime.InteropServices.DllImport("user32.dll")] + [DllImport("user32.dll")] public static extern int SendMessage(IntPtr hWnd, int Msg, int wParam, int lParam); - [System.Runtime.InteropServices.DllImport("user32.dll")] + [DllImport("user32.dll")] public static extern bool ReleaseCapture(); [DllImport("user32.dll")] [return: MarshalAs(UnmanagedType.Bool)] public static extern bool SetWindowPos(IntPtr hWnd, IntPtr hWndInsertAfter, int X, int Y, int cx, int cy, uint uFlags); + [DllImport("user32.dll")] + private static extern IntPtr GetForegroundWindow(); + + [DllImport("user32.dll")] + private static extern Int32 GetWindowThreadProcessId(IntPtr hWnd, out uint lpdwProcessId); + + [StructLayout(LayoutKind.Sequential)] + public struct RECT + { + public int left; + public int top; + public int right; + public int bottom; + } + + [DllImport("user32.dll", SetLastError = true)] + static extern bool GetWindowRect(IntPtr hWnd, ref RECT Rect); + string id, cookie, position, xOffset, yOffset, response, msgNum = "0"; - int phase = 1; + int phase = 1, boxWidth = 0, boxHeight = 0; bool retrievalError = false; void SystemEvents_DisplaySettingsChanged(object sender, EventArgs e) @@ -293,6 +311,8 @@ private void Form1_Load(object sender, EventArgs e) this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.None; notifyIcon1.ShowBalloonTip(5000); } + boxWidth = this.Size.Width; + boxHeight = this.Size.Height; } private void Form1_MouseDown(object sender, MouseEventArgs e) @@ -401,5 +421,28 @@ private void tableLayoutPanel2_Click(object sender, EventArgs e) { System.Diagnostics.Process.Start("https://www.facebook.com/" + id); } + + private void timer3_Tick(object sender, EventArgs e) + { + IntPtr handle = GetForegroundWindow(); + if (handle != null) + { + RECT Rect = new RECT(); + if (GetWindowRect(handle, ref Rect)) + { + int width = Rect.right - Rect.left, height = Rect.bottom - Rect.top; + if (width == Screen.PrimaryScreen.Bounds.Width && height >= Screen.PrimaryScreen.Bounds.Height - boxHeight) + { + timer2.Enabled = false; + this.Size = new Size(0, 0); + } + else + { + this.Size = new Size(boxWidth, boxHeight); + timer2.Enabled = true; + } + } + } + } } } diff --git a/Form1.resx b/Form1.resx index 3b12525..d229e7d 100644 --- a/Form1.resx +++ b/Form1.resx @@ -222,4 +222,7 @@ AAPAAAAD4AAAB/AAAA/4AAAf/AAAP/8AAP//wAP/ + + 304, 17 + \ No newline at end of file