Today i wanted to check whether user click in with in the context of the panel. Since panel doesnt provide hittest this is how to do it ..
private bool panel_hit_test(Panel panel, POINT point_test)
{
Rectangle rect = panel.RectangleToScreen(panel.ClientRectangle);
if ((point_test.x > rect.X && point_test.x < rect.X + rect.Width) &&
(point_test.y > rect.Y && point_test.y < rect.Y + rect.Height))
{
return true;
}
else
return false;
}
Thursday, May 28, 2009
Tuesday, May 05, 2009
Light-weight Threading ..
Today i wanted to create a light weight UI thread to make a button bliking. here is the sample code.
ThreadPool.QueueUserWorkItem(BlinkChatButton);
private void BlinkChatButton(object state)
{
while (canBlink)
{
Thread.Sleep(1000);
}
}
ThreadPool.QueueUserWorkItem(BlinkChatButton);
private void BlinkChatButton(object state)
{
while (canBlink)
{
Thread.Sleep(1000);
}
}
Windows Media (WM) Screen capturing by window handle
There is a C++ interface MS has provided to do this but in .net C# interop it's not available.
You have to use the IPropertyBag class based on it's GUID
[Guid("55272A00-42CB-11CE-8135-00AA004BB851")]
[InterfaceType(ComInterfaceType.InterfaceIsIUnknown)]
public interface IPropertyBag
{
void Read(String propName, out object ptrVar, int errorLog);
void Write(string propName, ref object ptrVar);
}
and copy and past this code before starting
IPropertyBag ipb = (IPropertyBag)
object value = false;
ipb.Write("Screen", ref value);
ipb.Write("CaptureWindow", ref Int32OfHandler);
Also make sure when you set the handle to set the encoding also to screen capturing
object codecName;
int codec_index = 2;
for (int i = 0; i < Profile.VideoCodecCount; ++i)
{
lVid4cc = Profile.EnumVideoCodec(i, out codecName);
//Compare if the current codec is Windows Media Video 9 Screen
if (codecName.ToString().Equals("Windows Media Video 9 Screen"))
{
codec_index = i; exit for;
}
}
// Set the IWMEncAudienceObj
Audnc.set_VideoCodec(0, codec_index);
You have to use the IPropertyBag class based on it's GUID
[Guid("55272A00-42CB-11CE-8135-00AA004BB851")]
[InterfaceType(ComInterfaceType.InterfaceIsIUnknown)]
public interface IPropertyBag
{
void Read(String propName, out object ptrVar, int errorLog);
void Write(string propName, ref object ptrVar);
}
and copy and past this code before starting
IPropertyBag ipb = (IPropertyBag)
object value = false;
ipb.Write("Screen", ref value);
ipb.Write("CaptureWindow", ref Int32OfHandler);
Also make sure when you set the handle to set the encoding also to screen capturing
object codecName;
int codec_index = 2;
for (int i = 0; i < Profile.VideoCodecCount; ++i)
{
lVid4cc = Profile.EnumVideoCodec(i, out codecName);
//Compare if the current codec is Windows Media Video 9 Screen
if (codecName.ToString().Equals("Windows Media Video 9 Screen"))
{
codec_index = i; exit for;
}
}
// Set the IWMEncAudienceObj
Audnc.set_VideoCodec(0, codec_index);
Subscribe to:
Posts (Atom)