How to disable mouse clicks in C# - c#

Trying To achieve
I'm trying to block input from mouse for certain time
I want to use the code like this: -
BlockMouse(true);
// My code starts here
...
// My code ends here
BlockMouse(false);
I Tried
BlockInput(true) but it requires elevated permissions

Use this code and implement IMessageFilter aswell
Rectangle BoundRect;
Rectangle OldRect = Rectangle.Empty;
private void EnableMouse()
{
Cursor.Clip = OldRect;
Cursor.Show();
Application.RemoveMessageFilter(this);
}
public bool PreFilterMessage(ref Message m)
{
if (m.Msg == 0x201 || m.Msg == 0x202 || m.Msg == 0x203) return true;
if (m.Msg == 0x204 || m.Msg == 0x205 || m.Msg == 0x206) return true;
return false;
}
private void DisableMouse()
{
OldRect = Cursor.Clip;
// Arbitrary location.
BoundRect = new Rectangle(50, 50, 1, 1);
Cursor.Clip = BoundRect;
Cursor.Hide();
Application.AddMessageFilter(this);
}

I think it is more elegant to set all your controls (like button) to disabled for the time your code is running and then enable them again
To give the user an optical feedback set the cursor to busy with Application.UseWaitCursor = true; and then Application.UseWaitCursor = false;
of course this solution only blocks the mouse clicks on your application and does not disable the mouse clicks completely

I don't think it is good to block mouse click because most of the inputs are by mouse click, it is better if you rewrite protected override void OnMouseDown(MouseEventArgs e)

Related

How to prevent immediate firing of MouseUp event in Winforms Listview when the mouse is still down?

Basically if you have a standard Listview that has multi-selection turned on, the mouse up and down events work fine.
But if you turn off multi-selection and click and hold your mouse button on the Listview, it immediately fires down and then up event while the mouse button is still down.
Is there a way to prevent this? I only want the mouse up event to trigger when I release the mouse button.
ListView mouse event processing in WndProc is a bit complicated. This is what I could do by overriding OnMouseUp and WndProc to stop raisng the unnecessary MouseUp:
using System.Collections.Specialized;
using System.Reflection;
using System.Windows.Forms;
public class MyListView : ListView
{
const int WM_LBUTTONUP = 0x0202, WM_RBUTTONUP = 0x0205, WM_MBUTTONUP = 0x0208;
const int LISTVIEWSTATE_mouseUpFired = 0x00080000;
FieldInfo listViewStateField;
public MyListView()
{
listViewStateField = (typeof(ListView)).GetField("listViewState",
BindingFlags.NonPublic | BindingFlags.Instance);
}
protected override void WndProc(ref Message m)
{
if (m.Msg == WM_LBUTTONUP || m.Msg == WM_MBUTTONUP || m.Msg == WM_RBUTTONUP) {
var value = (BitVector32)listViewStateField.GetValue(this);
value[LISTVIEWSTATE_mouseUpFired] = true;
listViewStateField.SetValue(this, value);
var x = (m.LParam.ToInt32() & 0xffff);
var y = (m.LParam.ToInt32() >> 16) & 0xffff;
var e = new MouseEventArgs(
m.Msg == WM_LBUTTONUP ? MouseButtons.Left :
m.Msg == WM_MBUTTONUP ? MouseButtons.Middle :
MouseButtons.Right, 1, x, y, 0);
OnMouseUp(e);
}
base.WndProc(ref m);
}
protected override void OnMouseUp(MouseEventArgs e)
{
if (Control.MouseButtons == MouseButtons.None)
base.OnMouseUp(e);
}
}

How to intercept unminizing? [duplicate]

Is there an event that is fired when you maximize a Form or un-maximize it?
Before you say Resize or SizeChanged: Those get only fired if the Size actually changes. If your window happens to be equal in size to the maximized window, they do not fire. Location looks like the next best bet, but that again feels like gambling on a coincidence.
Suprising that no one mentioned the inbuilt .NET method.
This way you don't need to override the Window Message Processing handler.
It even captures maximize/restore events caused by double-clicking the window titlebar, which the WndProc method does not.
Copy this in and link it to the "Resize" event handler on the form.
FormWindowState LastWindowState = FormWindowState.Minimized;
private void Form1_Resize(object sender, EventArgs e) {
// When window state changes
if (WindowState != LastWindowState) {
LastWindowState = WindowState;
if (WindowState == FormWindowState.Maximized) {
// Maximized!
}
if (WindowState == FormWindowState.Normal) {
// Restored!
}
}
}
You can do this by overriding WndProc:
protected override void WndProc( ref Message m )
{
if( m.Msg == 0x0112 ) // WM_SYSCOMMAND
{
// Check your window state here
if (m.WParam == new IntPtr( 0xF030 ) ) // Maximize event - SC_MAXIMIZE from Winuser.h
{
// THe window is being maximized
}
}
base.WndProc(ref m);
}
This should handle the event on any window. SC_RESTORE is 0xF120, and SC_MINIMIZE is 0XF020, if you need those constants, too.
Another little addition in order to check for the restore to the original dimension and position after the maximization:
protected override void WndProc(ref Message m)
{
base.WndProc(ref m);
// WM_SYSCOMMAND
if (m.Msg == 0x0112)
{
if (m.WParam == new IntPtr(0xF030) // Maximize event - SC_MAXIMIZE from Winuser.h
|| m.WParam == new IntPtr(0xF120)) // Restore event - SC_RESTORE from Winuser.h
{
UpdateYourUI();
}
}
}
Hope this help.
I believe the code is even simpler than that. You don't need to save the lastState because the WindowState is checked anytime when the event is fired.
private void MainForm_Resize(object sender, EventArgs e)
{
if (WindowState == FormWindowState.Maximized)
{
spContainer.SplitterDistance = 1000;
}
if (WindowState == FormWindowState.Normal)
spContainer.SplitterDistance = 500;
}
I had the same problem, and I could solve it without overriding.
Because I have a PictureBox in dock mode "Fill" I could use it's SizeChanged event, which fired also on maximizing the window.
I hope this part of code will be useful.
if (m.Msg == User32.WM_WINDOWPOSCHANGING && IsHandleCreated)
{
User32.WINDOWPLACEMENT wp = new User32.WINDOWPLACEMENT();
wp.length = Marshal.SizeOf(typeof(User32.WINDOWPLACEMENT));
User32.GetWindowPlacement(Handle, ref wp);
switch (wp.showCmd)
{
case User32.SW_RESTORE:
case User32.SW_NORMAL:
case User32.SW_SHOW:
case User32.SW_SHOWNA:
case User32.SW_SHOWNOACTIVATE:
_windState = FormWindowState.Normal;
if (wp.showCmd == User32.SW_RESTORE)
Update();
break;
case User32.SW_SHOWMAXIMIZED:
_windState = FormWindowState.Maximized;
SetMaximumSize();
break;
case User32.SW_SHOWMINIMIZED:
case User32.SW_MINIMIZE:
case User32.SW_SHOWMINNOACTIVE:
_windState = FormWindowState.Minimized;
break;
}
}
private void SetMaximumSize()
{
Screen screen = Screen.FromControl(this);
if (screen != null && !screen.WorkingArea.IsEmpty)
{
int sizeDiff = this.Size.Width - this.ClientSize.Width;
var maxSize = new Size(screen.WorkingArea.Width + sizeDiff, screen.WorkingArea.Height + sizeDiff);
this.MaximumSize = maxSize;
}
}
#region Window State
public const int SW_NORMAL = 1,
SW_SHOWMINIMIZED = 2,
SW_SHOWMAXIMIZED = 3,
SW_SHOWNOACTIVATE = 4,
SW_SHOW = 5,
SW_MINIMIZE = 6,
SW_SHOWMINNOACTIVE = 7,
SW_SHOWNA = 8,
SW_RESTORE = 9;
#endregion Window State
If there's no obvious event to listen for, you're probably going to need to hook into the Windows API and catch the appropriate message (Google turns up that you'll want to intercept the WM_SYSCOMMAND message: http://www.codeguru.com/forum/archive/index.php/t-234554.html).
I'm a newbie here so comments not allowed, but this IS a comment to the clean answer by GeoTarget:
The first line OUGHT to be slightly changed to nullable, to catch if the form is started Minimized:
FormWindowState? LastWindowState = null;
And a banal suggestion: Move the assignment of LastWindowState to after the "if"s, so the user can easily check not only what you go to, but also what it came from:
FormWindowState? LastWindowState = null;
private void Form1_Resize(object sender, EventArgs e) {
// When window state changes
if (WindowState != LastWindowState) {
if (WindowState == FormWindowState.Maximized) {
// Maximized!
}
if (WindowState == FormWindowState.Normal) {
// Restored!
}
LastWindowState = WindowState;
}
}
A complete solution with maximize, minimize, restore and correct remove of the lower bits which are used for internal purposes only.
protected override void WndProc(ref Message m)
{
const int WM_SYSCOMMAND = 0x0112;
const int SC_MAXIMIZE = 0xF030;
const int SC_MINIMIZE = 0xF020;
const int SC_RESTORE = 0xF120;
// Call beofre - don't use when "call after" is used
// dependig on the needs may be called before, after or even never (see below)
// base.WndProc(ref m);
if (m.Msg == WM_SYSCOMMAND)
{
/// <see cref="https://learn.microsoft.com/en-us/windows/win32/menurc/wm-syscommand"/>
/// Quote:
/// In WM_SYSCOMMAND messages, the four low - order bits of the wParam parameter
/// are used internally by the system.To obtain the correct result when testing
/// the value of wParam, an application must combine the value 0xFFF0 with the
/// wParam value by using the bitwise AND operator.
int wParam = (m.WParam.ToInt32() & 0xFFF0);
Debug.WriteLine($"Received param: { Convert.ToString(wParam, 16) } ");
if (wParam == SC_MAXIMIZE)
{
}
if (wParam == SC_MINIMIZE)
{
}
if (wParam == SC_RESTORE)
{
}
}
// Call after - don't use when "call before" is used
base.WndProc(ref m);
}
' Great tip. So if it helps to VisualBasic In Code
Private Const WM_SYSCOMMAND As Integer = &H112
Private Const SC_MAXIMIZE As Integer = &HF030
' # WndProcess 루프함수
Protected Overrides Sub WndProc(ByRef m As Message)
If m.Msg.Equals(WM_SYSCOMMAND) Then
If (m.WParam.ToInt32.Equals(SC_MAXIMIZE)) Then
Me.p_FullScreen()
Return
End If
End If
MyBase.WndProc(m)
End Sub

Moving a borderless form results in weird side effects

I am fairly new to C#.
In order to get a modern design application, I decided to make my form borderless. I then found a code snippet for making it possible to move my borderless form, which works perfectly fine.
private const int WM_NCHITTEST = 0x84;
private const int HT_CAPTION = 0x2;
protected override void WndProc(ref Message m)
{
base.WndProc(ref m);
switch (m.Msg) {
case WM_NCHITTEST:
m.Result = (IntPtr)(HT_CAPTION);
break;
}
}
I also need to fetch the form maximize event, and found another code snippet, which again, works perfectly. At least if I use them independently.
case WM_SYSCOMMAND:
if (IsMaximized == false)
{
IsMaximized = true;
Btn_Ribbon_MaximizeMinimize.Image = Properties.Resources.Img_MinimizeForm;
this.WindowState = FormWindowState.Maximized;
}
else if (IsMaximized == true)
{
IsMaximized = false;
Btn_Ribbon_MaximizeMinimize.Image = Properties.Resources.Img_MaximizeForm;
this.WindowState = FormWindowState.Normal;
}
break;
Now here comes the weird part. If I use them both together...
#region Move borderless Form
private const int WM_NCHITTEST = 0x84;
private const int HT_CLIENT = 0x1;
private const int HT_CAPTION = 0x2;
private const int WM_SYSCOMMAND = 0x0112;
protected override void WndProc(ref Message m)
{
base.WndProc(ref m);
switch (m.Msg) {
case WM_NCHITTEST:
m.Result = (IntPtr)(HT_CAPTION);
break;
case WM_SYSCOMMAND:
if (IsMaximized == false)
{
IsMaximized = true;
Btn_Ribbon_MaximizeMinimize.Image = Properties.Resources.Img_MinimizeForm;
this.WindowState = FormWindowState.Maximized;
}
else if (IsMaximized == true)
{
IsMaximized = false;
Btn_Ribbon_MaximizeMinimize.Image = Properties.Resources.Img_MaximizeForm;
this.WindowState = FormWindowState.Normal;
}
break;
}
}
#endregion
...I get all kind of weird side effects:
A single click on my form is enought for it to maximize itself
After minimizing my application, clicking its icon in the windows taskbar again, does not result in it normalizing, but maximizing
How can I get rid of those side effects, or even better than a workaround, is there a better way to make this work?
The WM_SYSCOMMAND message can contain information about more than just the maximize event. When you handle the WM_NCHITTEST and tell the OS that the caption bar was clicked, it also causes a WM_SYSCOMMAND when you release the mouse button.
You should inspect the m.WParam value to determine what action was performed.
The documentation mentions SC_MAXIMIZE (0xF030) but on my machine the value is actually SC_MAXIMIZE2 (0xF032). I can't find any documentation about that value, but this answer also mentions it.

Flickering ListView in virtual mode

I found a not so funny bug in the default ListView (not owner drawed!). It flickers heavily when items are added constantly into it (by using Timer to example) and user is trying to see items slightly away from selected item (scrolled either up or down).
Am I doing something wrong here?
Here is some code to reproduce it:
Create WindowsFormsApplication1;
set form WindowState to Maximized;
put on form timer1, set Enabled to true;
put on form listView1:
this.listView1.Dock = System.Windows.Forms.DockStyle.Fill;
this.listView1.View = System.Windows.Forms.View.Details;
this.listView1.VirtualMode = true;
add one column;
add event
this.listView1.RetrieveVirtualItem += new System.Windows.Forms.RetrieveVirtualItemEventHandler(this.listView1_RetrieveVirtualItem);
and finally
private void listView1_RetrieveVirtualItem(object sender, RetrieveVirtualItemEventArgs e)
{
e.Item = new ListViewItem(e.ItemIndex.ToString());
}
private void timer1_Tick(object sender, EventArgs e)
{
listView1.VirtualListSize++;
}
Now run it and wait until scrollbar on listview will appears (as timer will add enough items), then:
Select one of the first items in the listview (with mouse or keys), then scroll down by using scrollbar or mouse wheel, so that selected item will go outside of current view (up). The more you scroll down, the heavier flickering will become! And look at what scrollbar is doing ?!?!?
Similar effect appears if scrolling selected item down.
Question
How do I deal with it? Idea is to have sort of constantly updating log window with possibility to stop auto-scrolling and go up/down to investigate events in close proximity. But with that kek-effect it is just not possible!
It looks like problem is related to Selected / Focused combo (perhaps someone from Microsoft can confirm).
Here is a possible workaround (it's dirty and I liek it!):
private void timer1_Tick(object sender, EventArgs e)
{
// before adding
if (listView1.SelectedIndices.Count > 0)
{
if (!listView1.Items[listView1.SelectedIndices[0]].Bounds.IntersectsWith(listView1.ClientRectangle))
listView1.TopItem.Focused = true;
else
listView1.Items[listView1.SelectedIndices[0]].Focused = true;
}
// add item
listView1.VirtualListSize++;
}
Trick is to check before adding new item whenever currently selected item is away (here is the topic of how to check). And if item is away, then set focus to the current TopItem temporarily (until user scroll back, so that selected item will be again "visible" and this is when it gets focus back).
After some finding for a work-around, I realized that you can't prevent flicker once you select an item. I've tried using some ListView messages but fail. If you want to research more on this, I think you should pay some attention at LVM_SETITEMSTATE and maybe some other messages. After all, I thought of this idea, we have to prevent the user from selecting an item. So to fake a selected item, we have to do some custom drawing and faking like this:
public class CustomListView : ListView
{
public CustomListView(){
SelectedIndices = new List<int>();
OwnerDraw = true;
DoubleBuffered = true;
}
public new List<int> SelectedIndices {get;set;}
public int SelectedIndex { get; set; }
protected override void WndProc(ref Message m)
{
if (m.Msg == 0x1000 + 43) return;//LVM_SETITEMSTATE
else if (m.Msg == 0x201 || m.Msg == 0x202)//WM_LBUTTONDOWN and WM_LBUTTONUP
{
int x = m.LParam.ToInt32() & 0x00ff;
int y = m.LParam.ToInt32() >> 16;
ListViewItem item = GetItemAt(x, y);
if (item != null)
{
if (ModifierKeys == Keys.Control)
{
if (!SelectedIndices.Contains(item.Index)) SelectedIndices.Add(item.Index);
}
else if (ModifierKeys == Keys.Shift)
{
for (int i = Math.Min(SelectedIndex, item.Index); i <= Math.Max(SelectedIndex, item.Index); i++)
{
if (!SelectedIndices.Contains(i)) SelectedIndices.Add(i);
}
}
else
{
SelectedIndices.Clear();
SelectedIndices.Add(item.Index);
}
SelectedIndex = item.Index;
return;
}
}
else if (m.Msg == 0x100)//WM_KEYDOWN
{
Keys key = ((Keys)m.WParam.ToInt32() & Keys.KeyCode);
if (key == Keys.Down || key == Keys.Right)
{
SelectedIndex++;
SelectedIndices.Clear();
SelectedIndices.Add(SelectedIndex);
}
else if (key == Keys.Up || key == Keys.Left)
{
SelectedIndex--;
SelectedIndices.Clear();
SelectedIndices.Add(SelectedIndex);
}
if (SelectedIndex == VirtualListSize) SelectedIndex = VirtualListSize - 1;
if (SelectedIndex < 0) SelectedIndex = 0;
return;
}
base.WndProc(ref m);
}
protected override void OnDrawColumnHeader(DrawListViewColumnHeaderEventArgs e)
{
e.DrawDefault = true;
base.OnDrawColumnHeader(e);
}
protected override void OnDrawItem(DrawListViewItemEventArgs e)
{
i = 0;
base.OnDrawItem(e);
}
int i;
protected override void OnDrawSubItem(DrawListViewSubItemEventArgs e)
{
if (!SelectedIndices.Contains(e.ItemIndex)) e.DrawDefault = true;
else
{
bool isItem = i == 0;
Rectangle iBound = FullRowSelect ? e.Bounds : isItem ? e.Item.GetBounds(ItemBoundsPortion.ItemOnly) : e.SubItem.Bounds;
Color iColor = FullRowSelect || isItem ? SystemColors.HighlightText : e.SubItem.ForeColor;
Rectangle focusBound = FullRowSelect ? e.Item.GetBounds(ItemBoundsPortion.Entire) : iBound;
if(FullRowSelect || isItem) e.Graphics.FillRectangle(SystemBrushes.Highlight, iBound);
TextRenderer.DrawText(e.Graphics, isItem ? e.Item.Text : e.SubItem.Text,
isItem ? e.Item.Font : e.SubItem.Font, iBound, iColor,
TextFormatFlags.LeftAndRightPadding | TextFormatFlags.VerticalCenter);
if(FullRowSelect || isItem)
ControlPaint.DrawFocusRectangle(e.Graphics, focusBound);
}
i++;
base.OnDrawSubItem(e);
}
}
NOTE: This code above will disable MouseDown, MouseUp (for Left button) and KeyDown event (for arrow keys), if you want to handle these events outside of your CustomListView, you may want to raise these events yourself. (By default, these events are raised by some code in or after base.WndProc).
There is still one case in which the user can select the item by holding mouse down and drag to select. To disable this, I think we have to catch the message WM_NCHITTEST but we have to catch and filter it on right condition. I've tried dealing with this but no luck. I hope you can do it. This is just a demo. However as I said, we seem unable to go another way. I think your problem is some kind of BUG in the ListView control.
UPDATE
In fact I thought of Focused and Selected before but that's when I've tried accessing the SelectedItem with ListView.SelectedItems (That's wrong). So I didn't trying that approach. However after finding out that we can access the SelectedItem of a ListView in virtual mode via the ListView.SelectedIndices and ListView.Items, I think this solution is the most efficient and simple one:
int selected = -1;
bool suppressSelectedIndexChanged;
private void timer1_Tick(object sender, EventArgs e)
{
listView1.SuspendLayout();
if (selected > -1){
ListViewItem item = listView1.Items[selected];
Rectangle rect = listView1.GetItemRect(item.Index);
suppressSelectedIndexChanged = true;
item.Selected = item.Focused = !(rect.Top <= 2 || rect.Bottom >= listView1.ClientSize.Height-2);
suppressSelectedIndexChanged = false;
}
listView1.VirtualListSize++;
listView1.ResumeLayout(true);
}
private void listView1_SelectedIndexChanged(object sender, EventArgs e){
if (suppressSelectedIndexChanged) return;
selected = listView1.SelectedIndices.Count > 0 ? listView1.SelectedIndices[0] : -1;
}
NOTE: The code is just a demo for the case user selects just 1 item, you can add more code to deal with the case user selects more than 1 item.
I had the same problem and the code of #Sinatr almost works perfect, however when the selected item is right on the top border of the listview, it starts jumping between the selected and the next item on each update.
I had to include the height of the column headers to the visibility test which solved the problem for me:
if (lstLogMessages.SelectedIndices.Count > 0)
{
Rectangle selectedItemArea = lstLogMessages.Items[lstLogMessages.SelectedIndices[0]].Bounds;
Rectangle listviewClientArea = lstLogMessages.ClientRectangle;
int headerHeight = lstLogMessages.TopItem.Bounds.Top;
if (selectedItemArea.Y + selectedItemArea.Height > headerHeight && selectedItemArea.Y + selectedItemArea.Height < listviewClientArea.Height) // if the selected item is in the visible region
{
lstLogMessages.Items[lstLogMessages.SelectedIndices[0]].Focused = true;
}
else
{
lstLogMessages.TopItem.Focused = true;
}
}
lstLogMessages.VirtualListSize = currentView.MessageCount;
i know this is old post and [King King] has already given a double buffer example but still posting a simple code if it helps some one & this also removes flickering even if you have a item selected, but you need to Inherit ListView to use this cause SetStyle is not accessible from outside
C# Code
public class ListViewEX : ListView
{
public ListViewEX()
{
SetStyle(ControlStyles.AllPaintingInWmPaint | ControlStyles.OptimizedDoubleBuffer, true);
}
}
VB.NET
Public Class ListViewEX
Inherits ListView
Public Sub New()
SetStyle(ControlStyles.AllPaintingInWmPaint Or ControlStyles.OptimizedDoubleBuffer, True)
End Sub
End Class

Setting FlashVars of AxShockwaveFlash

a program of mine uses AxShockwaveFlash component used as stream player.
The problem is that my code works with most stream-providers (livestream, ustream, own3d.tv) but Justin.TV's player is somewhat problematic.
Before moving on the actual problem let me summarize my code;
Inherited FlashControl - this allows me to override the flashplayer's built-in menu:
public class FlashPlayer : AxShockwaveFlashObjects.AxShockwaveFlash // Customized Flash Player.
{
private const int WM_MOUSEMOVE = 0x0200;
private const int WM_MOUSEWHEEL = 0x020A;
private const int WM_LBUTTONDOWN = 0x0201;
private const int WM_LBUTTONUP = 0x0202;
private const int WM_LBUTTONDBLCLK = 0x0203;
private const int WM_RBUTTONDOWN = 0x0204;
private const int WM_RBUTTONUP = 0x0205;
public new event MouseEventHandler DoubleClick;
public new event MouseEventHandler MouseDown;
public new event MouseEventHandler MouseUp;
public new event MouseEventHandler MouseMove;
public FlashPlayer():base()
{
this.HandleCreated += FlashPlayer_HandleCreated;
}
void FlashPlayer_HandleCreated(object sender, EventArgs e)
{
this.AllowFullScreen = "true";
this.AllowNetworking = "all";
this.AllowScriptAccess = "always";
}
protected override void WndProc(ref Message m) // Override's the WndProc and disables Flash activex's default right-click menu and if exists shows the attached ContextMenuStrip.
{
if (m.Msg == WM_LBUTTONDOWN)
{
if (this.MouseDown != null) this.MouseDown(this, new MouseEventArgs(System.Windows.Forms.MouseButtons.Left, 1, Cursor.Position.X, Cursor.Position.Y, 0));
}
else if (m.Msg == WM_LBUTTONUP)
{
if (this.MouseUp != null) this.MouseUp(this, new MouseEventArgs(System.Windows.Forms.MouseButtons.None, 0, Cursor.Position.X, Cursor.Position.Y, 0));
}
else if (m.Msg == WM_MOUSEMOVE)
{
if (this.MouseMove != null) this.MouseMove(this, new MouseEventArgs(System.Windows.Forms.MouseButtons.None, 0, Cursor.Position.X, Cursor.Position.Y, 0));
}
else if (m.Msg == WM_RBUTTONDOWN)
{
if (this.ContextMenuStrip != null) this.ContextMenuStrip.Show(Cursor.Position.X, Cursor.Position.Y);
m.Result = IntPtr.Zero;
return;
}
else if (m.Msg == WM_LBUTTONDBLCLK)
{
if (this.DoubleClick != null) this.DoubleClick(this, new MouseEventArgs(System.Windows.Forms.MouseButtons.Left, 2, Cursor.Position.X, Cursor.Position.Y, 0));
m.Result = IntPtr.Zero;
return;
}
base.WndProc(ref m);
}
}
Player window code: (Player is an instance of FlashPlayer)
private void Player_Load(object sender, EventArgs e)
{
try
{
this.Text = string.Format("Stream: {0}", this._stream.Name); // set the window title.
this.Player.LoadMovie(0, this._stream.Movie); // load the movie.
if (this._stream.ChatAvailable && Settings.Instance.AutomaticallyOpenChat) this.OpenChatWindow();
}
catch (Exception exc)
{
// log stuff.
}
}
So this works great for livestream.com, ustream.com, own3d.tv but when it come's to justin.tv's player i'm getting a 1337 error (invalid embed code). So i tried to ask them for support but could't get a valid answer.
_stream.movie variable actually holds a valid URL for the stream source like;
http://cdn.livestream.com/grid/LSPlayer.swf?channel=%slug%&autoPlay=true (livestream sample)
or
http://www.justin.tv/widgets/live_embed_player.swf?channel=%slug%&auto_play=true&start_volume=100 (justin.tv sample)
Tried to urlencode the 'channel=%slug%&auto_play=true&start_volume=100' part for justin.tv but that did not work also.
So i started trying some work-arounds which at first place i thought setting flashVars variable of the control.
But i've a strange problem there, whenever i try to set flashVars variable it never get's set. I found a sample screenshot on the issue;
So if i was able to set the flashVariables may be i could work-around the justin.tv player's error. Btw, i also tried setting variables using Player.SetVariable(key,value) - that didn't work also.
Notes:
I'm running on .net 4.0 client profile.
Using the Flash10l.ocx.
Have generated the AxShockwaveFlashObjects.dll, ShockwaveFlashObjects.dll wrappers using "aximp.exe –source "C:\WINDOWS\system32\Macromed\Flash\Flash10l.ocx"
I recently had an issue with making justin.tv work, but in the end it was as simple as
axShockwaveFlash1.FlashVars = "auto_play=true&channel=adventuretimed&start_volume=25";
axShockwaveFlash1.Movie = "http://www.justin.tv/widgets/live_embed_player.swf";
and it works perfectly

Categories