Thursday, September 27, 2007

Flash/Blinking Window in C#

[DllImport("user32.dll")]
static extern Int32 FlashWindowEx(ref FLASHWINFO pwfi);

[StructLayout(LayoutKind.Sequential)]
public struct FLASHWINFO
{
public UInt32 cbSize;
public IntPtr hwnd;
public UInt32 dwFlags;
public UInt32 uCount;
public UInt32 dwTimeout;
}

//Stop flashing. The system restores the window to its original state.
public const UInt32 FLASHW_STOP = 0;
//Flash the window caption.
public const UInt32 FLASHW_CAPTION = 1;
//Flash the taskbar button.
public const UInt32 FLASHW_TRAY = 2;
//Flash both the window caption and taskbar button.
//This is equivalent to setting the FLASHW_CAPTION | FLASHW_TRAY flags.
public const UInt32 FLASHW_ALL = 3;
//Flash continuously, until the FLASHW_STOP flag is set.
public const UInt32 FLASHW_TIMER = 4;
//Flash continuously until the window comes to the foreground.
public const UInt32 FLASHW_TIMERNOFG = 12;



///
/// Flashes a window until the window comes to the foreground
/// Receives the form that will flash
///

/// The handle to the window to flash
/// whether or not the window needed flashing
public static bool FlashWindowEx(Form frm)
{
IntPtr hWnd = frm.Handle;
FLASHWINFO fInfo = new FLASHWINFO();

fInfo.cbSize = Convert.ToUInt32(Marshal.SizeOf(fInfo));
fInfo.hwnd = hWnd;
fInfo.dwFlags = FLASHW_ALL | FLASHW_TIMERNOFG;
fInfo.uCount = UInt32.MaxValue;
fInfo.dwTimeout = 0;

return (FlashWindowEx(ref fInfo) == 0);
}

Tuesday, September 11, 2007

"The search key was not found in any record." in dBase ?

i came up with this error "The search key was not found in any record." while reading a dbf file some time back. i was going thu microsoft support site and and they ask you to install some kind of patch that will never work. finally i found the solution

TEPS TO RESOLVE ISSUE:

========================

1. To Resolve that issue, In the Registry Editor, browse to the following
Registry key:



\HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Jet\4.0\Eng ines\Xbase


2. On the Right Pane, Click on Deleted.


3. Right-Click on the Deleted and click on Modify.


4. Change the entry from



0000 01



to



0000 00



4. Click OK.


5. Close the Registry and then open Access and the file imports fine.

special thanks to Amy Vargo.

Monday, September 03, 2007

convert an object in to byte array or byte array to object

I was looking for a sample code snippet to convert an object in to byte array. finally i had to do it on my own.


public byte[] objectToByte(Object obj )
{
MemoryStream fs = new MemoryStream();
BinaryFormatter formatter = new BinaryFormatter();
try
{
formatter.Serialize(fs, obj);
return fs.ToArray() ;
}
catch (SerializationException e )
{
return null;
}
finally
{
fs.Close();
}
}




public object ByteArrayToObject(Byte[] Buffer )
{
BinaryFormatter formatter = new BinaryFormatter();
MemoryStream stream = new MemoryStream(Buffer);
try
{
return formatter.Deserialize(stream);
}
catch
{
return null;
}
}