hi guys! is it posible for me to shake my windows form so that it will have high posibility to be noticed by my user.
Printable View
hi guys! is it posible for me to shake my windows form so that it will have high posibility to be noticed by my user.
You can do that but the standard way to get the user's attention is to use the FlashWindowEx API. You've no doubt seem windows that flash their Taskbar icon and title bar. The FlasWindow or, more usually, FlashWindowEx API is how you do that.
If you really want to make your window shake then you'd use a Random object to generate random numbers in a range and then use those random numbers to set the form's Location using a Timer. I'd get the current Location first, so that you can restore it when you're done, and then make the range +/- 10 pixels in each direction. You'd then start a Timer and have it run for a specified period of time or a specified number of Ticks.
Do you have any links to a tutorial or article about FlashWindowEx? because i've do quick search from google but the result didn't explain it well and some of them are for VB6.
Sounds like you are trying to simulate a Nudge like in MSN IM?
Here is my VB 6 version of it.
http://vbforums.com/showpost.php?p=2580922&postcount=13
This was the first result returned by Googling flashwindowex "c#".
I've tried the example from that link you give me Jm but it has some error and I cant figure it out. Help please...
the error happens in this line of code under FlashWindowEX method. Im just wondering why it has a '==' in the return, does that give any sense?
Code:return (FlashWindowEx(ref fInfo) == 0);
My COde:
Error #1:Code:using System;
using System.Collections.Generic;
using System.Text;
using System.Windows.Forms;
using System.Drawing;
using System.Media;
using System.IO;
using System.Net;
using System.Net.NetworkInformation;
using System.Runtime.InteropServices;
namespace RefNumGen
{
class Utility
{
[System.Runtime.InteropServices.DllImport("user32.dll")]
static extern Int16 FlashWindowEX(ref FLASHWINFO pwfi);
public struct FLASHWINFO
{
public UInt16 cbSize;
public IntPtr hwnd;
public UInt32 dwFlags;
public UInt16 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;
public static bool FlashWindowEx(IntPtr hWnd)
{
FLASHWINFO fInfo = new FLASHWINFO();
fInfo.cbSize = (ushort)Marshal.SizeOf(fInfo);
fInfo.hwnd = hWnd;
fInfo.dwFlags = FLASHW_ALL;
fInfo.uCount = UInt16.MaxValue;
fInfo.dwTimeout = 0;
return (FlashWindowEx(ref fInfo) == 0);
}
public static void show_Alarm_notification(string ArgEvntTitle, string ArgEvntDate, string ArgEvntLocation, string ArgSoundFile)
{
try
{
int notification_y_coor;
Rectangle workingArea = Screen.PrimaryScreen.WorkingArea;
SoundPlayer sndAlarm = new SoundPlayer();
Notification Notification_frm = new Notification();
Model EventData = new Model();
EventData.EventTitle = ArgEvntTitle;
EventData.EvenDate = ArgEvntDate;
EventData.EventLocation = ArgEvntLocation;
Notification_frm.GetEventData(EventData);
Notification_frm.TopMost = true;
Notification_frm.StartPosition = FormStartPosition.Manual;
notification_y_coor = workingArea.Height;
Notification_frm.Show();
for (int x = 0; x <= Notification_frm.Height; x++)
{
Notification_frm.Location = new Point(workingArea.Width - Notification_frm.Width, (-Notification_frm.Height + x));
}
if (!FlashWindowEx(Notification_frm.Handle))
{
}
if (File.Exists(ArgSoundFile))
{
sndAlarm.SoundLocation = ArgSoundFile;
}
else
{
sndAlarm.Stream = Properties.Resources.WARNING;
}
sndAlarm.Play();
}
catch (Exception ex)
{
Utility.show_error_message("show_Alarm_notification", ex.Message, ex.InnerException.ToString());
}
}
}
}
Error #2Quote:
Error 1 The best overloaded method match for 'RefNumGen.Utility.FlashWindowEx(System.IntPtr)' has some invalid arguments C:\Documents and Settings\daimous\My Documents\Visual Studio 2005\Projects\BCMD\WindowsApplication1\Utility.cs 53 21 RefNumGen
Quote:
Error 2 Argument '1': cannot convert from 'ref RefNumGen.Utility.FLASHWINFO' to 'System.IntPtr' C:\Documents and Settings\daimous\My Documents\Visual Studio 2005\Projects\BCMD\WindowsApplication1\Utility.cs 53 39 RefNumGen
You've declared the external function as "FlashWindowEX" and another function as "FlashWindowEx". On the line that produces the error you're calling FlashWindowEx, which is the wrong method. That's exactly what the error message is telling you. C# is case-sensitive so two names with the same spelling but different casing are not the same name.
As for the syntax of line, it is correct. It's comparing the return value of the function to zero to get a boolean value and then returning that.
Thanks for that..but i still it have an error in this line of code
error:Code:return (FlashWindowEX(ref fInfo) == 0);
Am i missing something?Quote:
System.EntryPointNotFoundException was unhandled
Message="Unable to find an entry point named 'FlashWindowEX' in DLL 'user32.dll'."
Source="RefNumGen"
TypeName=""
StackTrace:
at RefNumGen.Utility.FlashWindowEX(FLASHWINFO& pwfi)
at RefNumGen.Utility.FlashWindowEx(IntPtr hWnd) in C:\Documents and Settings\daimous\My Documents\Visual Studio 2005\Projects\BCMD\WindowsApplication1\Utility.cs:line 53
at RefNumGen.Utility.show_Alarm_notification(String ArgEvntTitle, String ArgEvntDate, String ArgEvntLocation, String ArgSoundFile) in C:\Documents and Settings\daimous\My Documents\Visual Studio 2005\Projects\BCMD\WindowsApplication1\Utility.cs:line 131
at RefNumGen.frmindex.button1_Click(Object sender, EventArgs e) in C:\Documents and Settings\daimous\My Documents\Visual Studio 2005\Projects\BCMD\WindowsApplication1\frmindex.cs:line 1026
at System.Windows.Forms.Control.OnClick(EventArgs e)
at System.Windows.Forms.Button.OnClick(EventArgs e)
at System.Windows.Forms.Button.OnMouseUp(MouseEventArgs mevent)
at System.Windows.Forms.Control.WmMouseUp(Message& m, MouseButtons button, Int32 clicks)
at System.Windows.Forms.Control.WndProc(Message& m)
at System.Windows.Forms.ButtonBase.WndProc(Message& m)
at System.Windows.Forms.Button.WndProc(Message& m)
at System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m)
at System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)
at System.Windows.Forms.NativeWindow.DebuggableCallback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
at System.Windows.Forms.UnsafeNativeMethods.DispatchMessageW(MSG& msg)
at System.Windows.Forms.Application.ComponentManager.System.Windows.Forms.UnsafeNativeMethods.IMsoCompo nentManager.FPushMessageLoop(Int32 dwComponentID, Int32 reason, Int32 pvLoopData)
at System.Windows.Forms.Application.ThreadContext.RunMessageLoopInner(Int32 reason, ApplicationContext context)
at System.Windows.Forms.Application.ThreadContext.RunMessageLoop(Int32 reason, ApplicationContext context)
at System.Windows.Forms.Application.Run(Form mainForm)
at RefNumGen.Program.Main() in C:\Documents and Settings\daimous\My Documents\Visual Studio 2005\Projects\BCMD\WindowsApplication1\Program.cs:line 25
at System.AppDomain.nExecuteAssembly(Assembly assembly, String[] args)
at System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence assemblySecurity, String[] args)
at Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()
at System.Threading.ThreadHelper.ThreadStart_Context(Object state)
at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
at System.Threading.ThreadHelper.ThreadStart()
The proper name of the function is FlashWindowEx, not FlashWindowEX. You were supposed to change the name of the declared function, not the way you were calling it. If you don't use the actual name of the function as it's declared in the Windows API then you have to specify that it's an alias and provide the actual name as well. Otherwise how is it supposed to find the right function?
It is working now...Thanks a bunch JM....