|
A simpler way is to add an IMessageFilter using Application.AddMessageFilter and doesn't require P/Invoking anything or using low-level hooks. It simply gives your implementation a chance to filter messages before they're dispatched to their target windows (controls).
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
Hmmm... Didn't know that. I'll look into that for future reference. Thanks Heath!
RageInTheMachine9532
|
|
|
|
|
A much easier way and more efficient way (without having to P/Invoke native APIs) is to simply add a IMessageFilter to pre-filter any messages sent to ONLY your application (as opposed to using a system-wide, low-level keyboard hook).
using System;
using System.Drawing;
using System.Windows.Forms;
public class Test : Form, IMessageFilter
{
static void Main(string[] args)
{
Test t = new Test();
Application.AddMessageFilter(t);
Application.Run(t);
Application.RemoveMessageFilter(t);
}
public Test()
{
TextBox tb = new TextBox();
tb.Location = new Point(8, 8);
this.Controls.Add(tb);
tb = new TextBox();
tb.Location = new Point(8, 30);
this.Controls.Add(tb);
}
private const int WM_KEYDOWN = 0x0100;
private const int WM_LBUTTONDOWN = 0x0201;
private const int WM_RBUTTONDOWN = 0x0204;
private const int WM_XBUTTONDOWN = 0x020b;
public bool PreFilterMessage(ref Message m)
{
if (m.Msg == WM_KEYDOWN ||
m.Msg == WM_LBUTTONDOWN ||
m.Msg == WM_RBUTTONDOWN ||
m.Msg == WM_XBUTTONDOWN)
return true;
return false;
}
} Pay attention to the PreFilterMessage method, which is the implementation for IMessageFilter.PreFilterMessage . You could filter other application messages this way as well. Anything that goes through the application message pump can be filtered.
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
I really was informed by these information, Thank you Heath.
But how can one get the constant values for messages like WM_KEYDOWN...etc.
Medhat Ramses
|
|
|
|
|
They are defined in the header files, take a look at windows.h for example.
- Nick Parker My Blog
|
|
|
|
|
how do i put a scroll on a picture box or just how do i create a image where i can scroll
can somebody give me code examples
chad
|
|
|
|
|
Place your PictureBox control onto another panel. Whenever you set the bitmap of the PictureBox control, set the size of the PictureBox control to be the size of the bitmap. A Windows scrollbar will appear allowing you to scroll.
Additionally, you can write your own control to do this, but that's probably a little more work.
---------------------------
He who knows that enough is enough will always have enough.
-Lao Tsu
|
|
|
|
|
|
I think it is not possible with the PictureBox. But you can do a workaround.
Add a panel which is small in size than the PictureBox and set the AutoScroll property of Panel to True.
And also make the PictureBox's SizeMode property to AutoSize so that it will be big enough to have the Image without any sterching and you can see the full image when you scroll the panel.
I think for doing this, there is no need for sample code. It is very straight forward.
|
|
|
|
|
Wasn't entirely sure where to post this deployment question... sticking with the language the component was written in.
Is it possible to use the Application Updater Component with a Linux Apache server? I've set up a very basic test app but it is not working. No error messages and an empty log file. I know the app is connecting because I can see it in my firewall and webserver logs. I've verified that directory browsing is enabled, so I'm thinking that the problem could be that I'm not using IIS. I'd really prefer to not have to set up my own IIS server since I'm already paying another company to host a webpage for me and I'd like to just use a separate directory there. Any help would be appreciated!
-b
|
|
|
|
|
It's been a while since I read the corresponding documentation for the AUC, but IIRC it only needs to get a manifest/version file that points to the update files, so what web server you use shouldn't matter. I'd say install IIS on your development machine (comes in handy many times anyway) and get it to work on that. Then move all the support files as-is to Apache, update the update URL in your .config file (or wherever it's stored), and try again.
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
Thanks for the response. Yeah, I guess having IIS setup would probably make life a bit easier for me anyway. I'll take that advice. Thanks again.
-b
|
|
|
|
|
Hi, everyone
I don't have much knowledge about component or dll these kind of stuff. When I add a dll to my .Net project using add reference, some of them ok, some of them no. So what kind of dll or exe etc. can be added into .Net project by Add reference? And what's difference between the '.Net' tab and 'com' tab?
Thanks in advance.
|
|
|
|
|
The .NET tab lists .NET Assemblies. When you click the Browse... button, you must pick a .NET assembly which uses the same extension. These contain a different PE/COFF header bit and different executable segments. If you want a shell extension that visual identifies .NET Assemblies (only .dlls, though, but those are all you can reference using VS.NET) by using an overlay icon, download and install my Shell Extensions for .NET Assemblies[^].
The COM tab lists COM controls (ActiveX controls) and COM typelibs (design-time discovery information, which VB6 and below uses as well). When you click the Browse... button, you must pick a DLL or OCX that contains COM information.
The Projects tab lists other projects in your solution. Use this when developing a multi-project solution to keep assembly references in sync with the current build configuration.
You should read some books on .NET development. These concepts are necessary to understand if you want to start writing anything other than "Hello, world" applications.
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
How can you go about developing a download manager in C# that would act as an accelerator (like Download Accelerator Plus) by segmenting the file into multiple fragments and downloading each simultaneously?
Sammy
"A good friend, is like a good book: the inside is better than the cover..."
|
|
|
|
|
See the HttpWebRequest.AddRange method documentation in the .NET Framework SDK, which includes an example. The HTTP Range header specifies which byte range you want to get. See RFC 2616, Section 14, Subsection 35[^] for more information on the Range header.
This is assuming that the HTTP daemon supports it. This is only supported in HTTP/1.1. Be sure to catch exceptions when it's not supported, though the server will most likely just hand you the entire file without complaining on a single request.
For multi-threading, I recommend asynchronous calls (see HttpWebRequest.BeginGetResponse ) as opposed to handling threads yourself. You can implement a ProgressBar by using HttpWebResponse.GetResponseStream and reading and writing the bytes to a file (in that loop is where you'd increment your progress bar).
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
Quoting from MSDN:
Don't control the execution of worker threads from your main program (using events, for example). Instead, design your program so that worker threads are responsible for waiting until work is available, executing it, and notifying other parts of your program when finished. If your worker threads do not block, consider using thread pool threads. Monitor.PulseAll is useful in situations where worker threads block.
What does that mean? Specifically, what does it mean to say that a thread blocks or does not block?
Thank you.
Sammy
"A good friend, is like a good book: the inside is better than the cover..."
|
|
|
|
|
It means that you have the worker threads query for information, or jobs to complete. They wait (block) on a wait handle that is signaled when work is available. They get the work, perform their operations, then block again waiting for the wait handle to be signaled.
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
To be placed in the GAC, an assembly must have a strong name. I know both strong-named assemblies and shared assemblies can be placed in GAC.
So what's the use of shared assemblies? How can they be in GAC without strong name?
I'm
Promise only what you can do. And then deliver more than what you promised. This signature was created by "Code Project Quoter".
|
|
|
|
|
You're confusing .NET assemblies with Win32 assemblies. An assembly is just a file containing other information and a manifest of that information (like a Java jar file). .NET assemblies contain embedded resources, modules containing IL, and metadata. Win32 assemblies are still native executables that have a manifest file associated with them and are installed in the %WINDIR%\WinSxS directory in Windows XP and above. They are not installed into the global assembly cache for .NET.
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
I was talking about this:
Shared Assemblies
Assemblies shared by multiple applications should be installed in a centralized repository called the global assembly cache. .NET clients can access the same copy of the interop assembly, which is signed and installed in the global assembly cache.
Link...[^]
Promise only what you can do. And then deliver more than what you promised. This signature was created by "Code Project Quoter".
|
|
|
|
|
Then apparently there's no different regarding .NET assemblies. I apologize, but I've never heard them referred to as "shared" assemblies. The terminology makes sense, though. By installing assemblies into the GAC they are shared, but they must still be signed. Assemblies should be signed anyway for any production code. It's not like it's hard. Just run "sn.exe -k KeyFile.snk" to generate a key. Refer to that for all your assemblies for either a product or your organization. Consider it a satefy mechanism to safe-gaurd against spoofying attacks (replacing your assemblies with malicious assemblies - unless they replaced them all).
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
I am having an issue loading an assembly. Two days ago, this exact same code was working. Today, I cannot, for the life of me, get the module to load. Here is the relevant code:
public ArrayList FindModules(string path,Type type)
{
ArrayList modulesFound = new ArrayList();
foreach(string file in Directory.GetFiles(path))
{
FileInfo fileInfo = new FileInfo(file);
if (fileInfo.Extension == ".dll")
{
Assembly assembly = Assembly.LoadFrom(file);
foreach(Type t in assembly.GetTypes())
{
if(modulesFound.Contains(file))
break;
foreach(Type iFace in t.GetInterface())
{
if(iFace.Equals(IModule))
{
modulesFound.Add(file);
break;
}
}
}
}
}
return modulesFound;
}
The problem is with the if(iFace.Equals(type)) line. It doesn't recognize that iFace is the same as IModule. If the line is changed to iFace.Name == "IModule" , the it loads the module, but returns a null instance.
Any Ideas????
Thanks,
Craig Wilson
|
|
|
|
|
Use iFace.Equals(typeof(IModule)) instead.
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
Thank you for your response. I must apologize because I typed my code in incorrectly. I am doing just what you said and it still does not work. See the bottom of my original post. That is what confuses me. The names of each type are the same, but the types are not...
Thanks,
Craig Wilson
|
|
|
|