|
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
|
|
|
|
|
Most functions should come from coredll.dll. However, some bad news. Windows CE doesn't support windows hooks. So you're SOL, sorry.
|
|
|
|
|
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.
|
|
|
|
|
[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?
|
|
|
|
|
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#.
|
|
|
|
|
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
|
|
|
|
|
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
|
|
|
|
|
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
|
|
|
|
|
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()
|
|
|
|
|
Threading.Thread.CurrentThread.GetHashCode
GetHashCode on the thread object returns the thread ID. From MS Docs
|
|
|
|
|
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
|
|
|
|
|
(int)AppDomain.GetCurrentThreadId()
change to:
System.Threading.Thread.CurrentThread.ManagedThreadId
|
|
|
|
|
I use VS 2010 with .NET 4 and i replaced
Int32 mainThreadId = AppDomain.GetCurrentThreadId();
with
Int32 mainThreadId = Process.GetCurrentProcess().Threads[0].Id;
It's not ideal but it works for my personal use and is not deprecated (for the moment).
|
|
|
|
|
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
|
|
|
|
|
please put a picture to your article
|
|
|
|
|
What would you like to see a picture of?
|
|
|
|
|
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
|
|
|
|
|
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
|
|
|
|
|
ok, that worked was able to build it to a dll, but I still cannot use it as a referenced dll in a VB app, it will break the Form class by giving an error to everything in the System.Windows.Forms Class. thanks anyway I will see if i can implement it another way.
Frank
|
|
|
|
|
I was gonna try to write this yesterday, but I got distracted by real work and didn't get to it.
Instead, I'll take your nice class and convert it to VB.
Thanks! I gave this a 5 for code cleanliness, readability and utility.
-Kevin Buchan
|
|
|
|
|
I try to convert in VB but I have problem convertin this line:
executingPage.Unload += new EventHandler( ExecutingPage_Unload );
To VB.
Could you help me?
Thanks in advance!
Manolo Herrera
|
|
|
|
|
There's a couple of ways you can add a handler in vb.net, you can use the AddHandler function.
AddHandler executingPage.Unload AddressOf ExecutingPage_Unload
or on the declaration line of ExecutingPage_Unload make it like this.
Public Sub ExecutingPage_Unload(...) Handles executingPage.Unload
the handles part specifies which events the method is associated with.
Hope this helps
|
|
|
|
|
Thanks, Man It works very well. I was confusing with that line. I did not know what c# was telling me but with you help, I get it!. Now I undertand what we need to do. Thanks a lot!. and I was doing for asp.net messagbox but Now I see that this messagebox is for Windows application. However you answer my question with a not exactly related question...Realiy thanks to you! and thanks for all writers in codeproject and with this cool site!.
Manolo Herrera.
|
|
|
|