 |
|
 |
good article, you might want to show some of the code in the article and a screen shot of the messagebox to make it a better article. 
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
 |
I have change your code to make a countdown messagebox. I know change the text to show the countdown : SetWindowText(hWnd, nCountDown); but it change the caption of the messagebox not the real text.
Is someone know how to achive this issue ? Thanks
|
| Sign In·View Thread·PermaLink | 2.00/5 (1 vote) |
|
|
|
 |
|
 |
If two threads calls this MessageBoxEx, would this be thread safe? I am a bit skeptical with the timer event ID being set to a constant 42.
~Kanna
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
 |
Timers belong to an HWND. An HWND belongs to the thread it was created on. The WM_TIMER will be received on the thread the HWND belongs to. So what does it matter what the timer ID is? As long as no one else is using it for a given HWND you're good to go. And since this is a MessageBox its pretty safe no one else is using ID 42.
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
 |
This looks brilliant but I am not sure it will work in PocketPC(2003)
I am getting 9 error messages the first of which is The type or namesapce name MessageBoxoptions could not be found (are you missin etc... The type or namespace nane IWin32Windows etc (eight messages based on this!!
Richard
|
| Sign In·View Thread·PermaLink | 5.00/5 (1 vote) |
|
|
|
 |
|
 |
This will not work on the pocket or compact framework. The implementation uses windows hooks which aren't available of the pocket.
Sorry!
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
|
 |
|
|
 |
|
 |
As compact framework does not have this User32.dll then how can we implement this functionality. List of functions impoted not in coredll.dll 1.SendMessage 2.SetWindowsHookEx 3.GetWindowTextLength 4.GetWindowText
Can somebody help me out, my mail id is yuvrajaa@integramicro.com/yuvraj_1981@walla.com
Yuvraj
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
 |
Most functions should come from coredll.dll. However, some bad news. Windows CE doesn't support windows hooks. So you're SOL, sorry.
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
 |
Anyone had any luck getting it to work with MessageBoxOptions.ServiceNotification? We have a service that does some checks, makes system changes if necessary, and then tells the user they need to reboot. Hoping to put up a message box with a countdown to an auto-reboot. Works great, until I put the MessageBoxOptions.ServiceNotification option on. Nuts.
|
| Sign In·View Thread·PermaLink | 2.00/5 (3 votes) |
|
|
|
 |
|
 |
[quote]http://www.gipsysoft.com/messagebox. You'll find a C++ implementation[/quote]
Why not use the MessageBoxTimeOut API function instead of having a whole freaking class?
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
 |
Very interesting.
1) I had no idea there was such a function. 2) It's undocumented, it's generally not a good idea to use undocumented functions. Still, I would think you could try to use the undocumented version and if it's not there you could use this code. 3) Looking at another article on this site it appears that MessageBoxTimeOut is only available on WinXP. People do still write code for Win9X, WinNT, etc... 4) This technique for making a MessageBox with a timeout allows you do change the text of the buttons or move them around or do whatever else you need to do with MessageBox. The C++ code at gipsysoft does all of these things and more. I only needed the timeout so that's all I ported to C#.
|
| Sign In·View Thread·PermaLink | 1.50/5 (2 votes) |
|
|
|
 |
|
 |
Hello, I like your MessageBoxEx with timer solution. I recently upgraded to Visual Studio 2005 beta 1 and get the following warning: Warning 2 'System.AppDomain.GetCurrentThreadId()' is obsolete: 'AppDomain.GetCurrentThreadId has been deprecated because it does not provide a stable Id when managed threads are running on fibers (aka lightweight threads). To get a stable identifier for a managed thread, use the Thread object returned from Thread.CurrentThread.'
I cannot find a working substitute. Any ideas would be appreciated.
Thanks, Dana Hall
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
 |
That is interesting but I wouldn't worry about fibers much. They were intended to make the porting of Unix applications easier. I don't imagine they are used much in Windows apps.
SetWindowsHookEx is a windows API after all. Perhaps in the new version of the .NET framework there is an managed alternative to SetWindowsHookEx. If you want to get rid of the warning use P/Invoke to get the current thread id.
Regards, Rodger
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
 |
Rodger, Thanks for the help. This is what I did and it worked. I added this P/Invoke signature.
[DllImport("kernel32.dll")] static extern int GetCurrentThreadId();
Then modified this line: hHook = SetWindowsHookEx(WH_CALLWNDPROCRET, hookProc, IntPtr.Zero, AppDomain.GetCurrentThreadId());
To this line: hHook = SetWindowsHookEx(WH_CALLWNDPROCRET, hookProc, IntPtr.Zero, GetCurrentThreadId());
I am new to .NET, so this was a fun learning experiment.
Thanks again, Dana Hall
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
 |
This is off the top of my head, and I don't know if it will work in 2005, but try this instead...
System.Threading.Thread.CurrentThread.GetDomainID() Or
System.Threading.Thread.CurrentThread.CurrentContext.ContextID()
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
 |
Threading.Thread.CurrentThread.GetHashCode
GetHashCode on the thread object returns the thread ID. From MS Docs
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
 |
I haven't tried this suggestion yet, but I have spent two days researching this problem on the NET to no avail until I stumbled across this message. Thanks very much. Maybe Microsoft should seriously think about a free brain transplant for some of its employees - who in their right minds would go looking for the thread ID under GetHashCode?
John Whattam
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
 |
(int)AppDomain.GetCurrentThreadId()
change to:
System.Threading.Thread.CurrentThread.ManagedThreadId
|
| Sign In·View Thread·PermaLink | 5.00/5 (1 vote) |
|
|
|
 |
|
 |
This class is exactly what I was looking for. Very helpful and so easy - just one extra parameter.
Thanks again, I'll get a lot of use out of this.
Anne
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
|
 |
|
|
 |
|
 |
I started a test project and included your MessageBoxEx.cs file, when I try to build I get the following errors:
E:\VBNet Projects\TestMessageboxEx\MessageBoxEx\MessageBoxEx.cs(12): The type or namespace name 'DialogResult' could not be found (are you missing a using directive or an assembly reference?)
E:\VBNet Projects\TestMessageboxEx\MessageBoxEx\MessageBoxEx.cs(24): The type or namespace name 'MessageBoxButtons' could not be found (are you missing a using directive or an assembly reference?)
E:\VBNet Projects\TestMessageboxEx\MessageBoxEx\MessageBoxEx.cs(48): The type or namespace name 'IWin32Window' could not be found (are you missing a using directive or an assembly reference?)
I would like to compile this to a .dll if possible then use it in some of my VB apps.
These errors are in a C# project.
Thanks for any help you can provide. Frank
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
 |
Sorry,
In my instructions, I assumed the assembly you were developing already had a reference to System.Windows.Forms and were using MessageBox.Show. Add that assembly reference and you should be good to go. MessageBoxEx is in the System.Windows.Forms namespace just like MessageBox.
Regards, Rodger
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |