mirror of
https://github.com/chylex/TweetDuck.git
synced 2025-05-12 23:34:08 +02:00
Improve player UI handling (cursor, position, setting owner handle)
This commit is contained in:
parent
410ead66f8
commit
f231256402
video/TweetDuck.Video
1
video/TweetDuck.Video/FormPlayer.Designer.cs
generated
1
video/TweetDuck.Video/FormPlayer.Designer.cs
generated
@ -56,7 +56,6 @@ private void InitializeComponent() {
|
||||
this.ShowInTaskbar = false;
|
||||
this.StartPosition = System.Windows.Forms.FormStartPosition.Manual;
|
||||
this.Text = "TweetDuck Video";
|
||||
this.TopMost = true;
|
||||
this.Load += new System.EventHandler(this.FormPlayer_Load);
|
||||
((System.ComponentModel.ISupportInitialize)(this.player)).EndInit();
|
||||
this.ResumeLayout(false);
|
||||
|
@ -17,6 +17,7 @@ public FormPlayer(IntPtr handle, string url){
|
||||
|
||||
player.Ocx.enableContextMenu = false;
|
||||
player.Ocx.uiMode = "none";
|
||||
player.Ocx.settings.setMode("loop", true);
|
||||
|
||||
player.Ocx.MediaChange += player_MediaChange;
|
||||
player.Ocx.MediaError += player_MediaError;
|
||||
@ -33,7 +34,7 @@ private void timer_Tick(object sender, EventArgs e){
|
||||
IWMPMedia media = player.Ocx.currentMedia;
|
||||
|
||||
ClientSize = new Size(Math.Min(media.imageSourceWidth, width*3/4), Math.Min(media.imageSourceHeight, height*3/4));
|
||||
Location = new Point(rect.Left+(width-ClientSize.Width)/2, rect.Top+(height-ClientSize.Height)/2);
|
||||
Location = new Point(rect.Left+(width-ClientSize.Width)/2, rect.Top+(height-ClientSize.Height+SystemInformation.CaptionHeight)/2);
|
||||
}
|
||||
else{
|
||||
Environment.Exit(Program.CODE_OWNER_GONE);
|
||||
@ -42,6 +43,8 @@ private void timer_Tick(object sender, EventArgs e){
|
||||
|
||||
private void player_MediaChange(object item){
|
||||
timer.Start();
|
||||
Cursor.Current = Cursors.Hand;
|
||||
NativeMethods.SetWindowOwner(Handle, ownerHandle);
|
||||
Marshal.ReleaseComObject(item);
|
||||
}
|
||||
|
||||
|
@ -3,10 +3,15 @@
|
||||
|
||||
namespace TweetDuck.Video{
|
||||
static class NativeMethods{
|
||||
private const int GWL_HWNDPARENT = -8;
|
||||
|
||||
[DllImport("user32.dll")]
|
||||
[return: MarshalAs(UnmanagedType.Bool)]
|
||||
public static extern bool GetWindowRect(IntPtr hWnd, out RECT lpRect);
|
||||
|
||||
[DllImport("user32.dll")]
|
||||
private static extern int SetWindowLong(IntPtr hWnd, int nIndex, IntPtr dwNewLong);
|
||||
|
||||
[StructLayout(LayoutKind.Sequential)]
|
||||
public struct RECT{
|
||||
public int Left;
|
||||
@ -14,5 +19,17 @@ public struct RECT{
|
||||
public int Right;
|
||||
public int Bottom;
|
||||
}
|
||||
|
||||
public static void SetWindowOwner(IntPtr child, IntPtr owner){
|
||||
SetWindowLong(child, GWL_HWNDPARENT, owner);
|
||||
/*
|
||||
* "You must not call SetWindowLong with the GWL_HWNDPARENT index to change the parent of a child window"
|
||||
*
|
||||
* ...which I'm not sure they're saying because this is completely unsupported and causes demons to come out of sewers
|
||||
* ...or because GWL_HWNDPARENT actually changes the OWNER and is therefore NOT changing the parent of a child window
|
||||
*
|
||||
* ...so technically, this is following the documentation to the word.
|
||||
*/
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -26,12 +26,13 @@ private static int Main(string[] args){
|
||||
|
||||
try{
|
||||
Application.Run(new FormPlayer(ownerHandle, videoUrl));
|
||||
return 0;
|
||||
}catch(Exception e){
|
||||
// TODO
|
||||
Console.Out.WriteLine(e.Message);
|
||||
return CODE_LAUNCH_FAIL;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user