|
I found the following in "winuser.h".
/*
* Move Size
* EVENT_SYSTEM_MOVESIZESTART
* EVENT_SYSTEM_MOVESIZEEND
* Sent when a window enters and leaves move-size dragging mode.
*/
#define EVENT_SYSTEM_MOVESIZESTART 0x000A
#define EVENT_SYSTEM_MOVESIZEEND 0x000B
I would like to know when the movesizeend event occurs. Can you show me some code on how to utilize this? I'm at a loss. 
|
|
|
|
|
In your form, override the WndProc method.
You'll then have to check for message sent, if you need to know the message value, use the Spy++ tool to spy on the messages (and their corresponding message values) that are being sent to your app.
That said, there's probably managed events already raised for you, no need to dig into Win32. What exactly are you trying to accomplish? If you're trying to know when the form or some control has been resized, for example, managed events are already raised for you, and are much easier to implement handlers for.
#include "witty_sig.h"
|
|
|
|
|
That won't work. Those are notification messages sent by the accessibility APIs and require a callback installed by SetWinEventHook .
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
You have to P/Invoke SetWinEventHook (and later unhook it with UnhookWinEvent ) and handle those messages. Here's something I threw together quickly:
using System;
using System.Diagnostics;
using System.Runtime.InteropServices;
using System.Windows.Forms;
public class Test
{
static void Main(string[] args)
{
using (AccessibleForm form = new AccessibleForm())
{
form.MoveSizeStart += new EventHandler(OnMoveSizeStart);
form.MoveSizeEnd += new EventHandler(OnMoveSizeEnd);
Application.Run(form);
}
}
static void OnMoveSizeStart(object sender, EventArgs e)
{
Console.WriteLine("Move/Size has started.");
}
static void OnMoveSizeEnd(object sender, EventArgs e)
{
Console.WriteLine("Move/Size has ended.");
}
private class AccessibleForm : Form
{
private GCHandle cbHandle;
private IntPtr hWinEventHook;
public AccessibleForm()
{
WinEventProcCallback callback =
new WinEventProcCallback(WinEventProc);
cbHandle = GCHandle.Alloc(callback);
hWinEventHook = SetWinEventHook(
new IntPtr(EVENT_SYSTEM_MOVESIZESTART),
new IntPtr(EVENT_SYSTEM_MOVESIZEEND),
IntPtr.Zero,
(IntPtr)cbHandle,
Process.GetCurrentProcess().Id,
0,
new IntPtr(1));
}
public event EventHandler MoveSizeStart;
public event EventHandler MoveSizeEnd;
protected override void Dispose(bool disposing)
{
if (hWinEventHook != IntPtr.Zero)
{
UnhookWinEvent(hWinEventHook);
hWinEventHook = IntPtr.Zero;
}
if (cbHandle.IsAllocated)
cbHandle.Free();
base.Dispose(disposing);
}
protected virtual void OnMoveSizeStart(EventArgs e)
{
if (MoveSizeStart != null)
MoveSizeStart(this, e);
}
protected virtual void OnMoveSizeEnd(EventArgs e)
{
if (MoveSizeEnd != null)
MoveSizeEnd(this, e);
}
private void WinEventProc(
IntPtr hWinEventHook,
uint evt,
IntPtr hwnd,
int idObject,
int idChild,
uint dwEventThread,
uint dwmsEventTime)
{
if (evt == EVENT_SYSTEM_MOVESIZESTART)
OnMoveSizeStart(EventArgs.Empty);
else if (evt == EVENT_SYSTEM_MOVESIZEEND)
OnMoveSizeEnd(EventArgs.Empty);
}
private const uint EVENT_SYSTEM_MOVESIZESTART = 0x000a;
private const uint EVENT_SYSTEM_MOVESIZEEND = 0x000b;
private delegate void WinEventProcCallback(
IntPtr hWinEventHook,
uint evt,
IntPtr hwnd,
int idObject,
int idChild,
uint dwEventThread,
uint dwmsEventTime);
[DllImport("user32.dll")]
private static extern IntPtr SetWinEventHook(
[MarshalAs(UnmanagedType.SysUInt)] IntPtr eventMin,
[MarshalAs(UnmanagedType.SysUInt)] IntPtr eventMax,
IntPtr hmodWinEventProc,
IntPtr lpfnWinEventProc,
[MarshalAs(UnmanagedType.U4)] int idProcess,
[MarshalAs(UnmanagedType.U4)] int idThread,
[MarshalAs(UnmanagedType.SysUInt)] IntPtr dwflags);
[DllImport("user32.dll")]
private static extern bool UnhookWinEvent(IntPtr hWinEventHook);
}
} The problem is that in-context hooks require the callback to be in a native DLL to be mapped into the process. Out-of-context hooks marshal across process boundaries but we're in the same process.
If all you're trying to do is get notification when a user moves a window, handle the LocationChanged event and use a timer (like the Windows Forms Timer component you'll find in the toolbox). The timer is initially stopped. In your LocationChanged event handler, start the timer. With each call to the handler (there will be many), increment the Timer.Interval by 500 ms or so. When the timer's Tick event handler is called, stop the timer and perform the operations you want. Also reset the Interval back down to its default, like 500 (.5 seconds).
Timers are used like this for many different things, including click vs. double-click. There's other ways to do this as well, but this is just one idea.
Also, relying on accessibility (in which those notification messages relate) is probably not a good idea since it's not very portable.
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
Thanks, I think the timer idea will work. I thought about using a timer but I seem to be brain dead this week and couldn't think how to implement it. You are my hero. Thanks again!!!!! 
|
|
|
|
|
Hi,
I want to dynamically allocate datagrids depending on the input. So I declared a datagrid array .But it is not working . Can I do this way?
KArteek
|
|
|
|
|
Hi,
I want to display the tables in a database in a C# form graphically. I want to use a datagrid to fill the schema of each table. Is there any other way to represent graphically a table. Now I want to show foreign key relationships between the tables. How do I show it graphically .
Then I should be able to move the tables and the relations between them also should move..
What controls should I use to get the above thing done and how to use it?
Karteek
|
|
|
|
|
Not in the .NET FCL, no. There might be some custom controls you can use in your software - either free or commercial - on the 'net (I know that some applications have such capabilities, but they're typically stand-alone applications or add-ins specific to a product). Just google. Otherwise, you'll need to create your own implementation.
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
HI,
I did not find any .If u find please tell me. What if I want to create my own one?
Karteek
|
|
|
|
|
This forum is for asking specific questions, not about designing an entire control or application. The place to start is learning about custom graphics, owner-drawn controls, and the like. There are articles about such topics here on CodeProject and the rest of the 'net.
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
hai there
i have a horscroll bar and a vertical on my form. user may clck once or twice or n number of continues time with out releasing the mouse( click and hold);
i need to cancel all click event and i need to take the last click event.
that is if he click and hold the mouse i need to find the last click value and no of click made on that holding process.
how it is possible
Sreejith S S Nair
|
|
|
|
|
Be patient. I already answered your post you made just a short while ago.
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
Hello!
I need some help here. I have this appliaction where i can load textfiles and decrypt/encrypt with DES cryptation. The problem is how i should know what files are already encrypted at load? if they are, you should be prompted for a password to unlock it, else it should just load the file.. both ways works if i know before i load the file if it's encrypted or not (i can set wich loadfunction to be used programmaticlly then). I need to be able to choose another loadfunction if the file is encrypted. So, how do i check if the file is encrypted or not? I had an idea to check for chars not in the asciitable.. but it doesnt seem to work.. anyone with some good ideas?
thanks!
|
|
|
|
|
It's not possible to detect if it has been encrypted. The ASCII-table method does not work if someone wants to encrypt a binary file for example.
Your best bet will be to change the file extension on encryption and detect encrypted files according to the extension. Say you have a file "secrect.doc". On encryption, your application could rename it to "secret.doc.enc". When the user wants to decrypt files, he can be displayed only those files that have the extension .enc.
HTH. Greets,
Daniel
---
SharpPrivacy - A free OpenPGP Implementation in c#
http://sharpprivacy.sf.net
|
|
|
|
|
Good idea (and typical, which I'm sure you already know since you seem to be involved with PGP - cool!), except he did state he is encrypting text files (or "textfiles" as he said). In such a case, you could read the few bytes (since the first 2 bytes could be a byte order mark, or BOM) or take a random sampling (several characters from different locations) and see how many are in the printable ASCII range. For Unicode files, you'd have to take this a step further and use the StringInfo class to get text elements, if possible.
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
Uuups, I overread the text file part. Anyway, I still think that the file extension way is the most practical. He could also use statistical analysis (simply count the number of occurances per byte. the resulting graph will be almost equally spread for encrypted files and will have peaks for other files [will work with most binary filetypes too, but not with compressed files]).
Greets,
Daniel
---
SharpPrivacy - A free OpenPGP Implementation in c#
http://sharpprivacy.sf.net
|
|
|
|
|
Oh, don't get me wrong, I completely agree with you about using different extensions. I use PGP* and X.509 certs a lot myself so I'm definitely stranger to it. I was just offering a slightly different alternative.
* Is your OpenPGP implementation derivative of the crypto classes in System.Security.Cryptography ? I really don't have the time to check it out right now, so I was just wondering.
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
Did not get you wrong . No offence taken, none intended
Ad *:
No it's not. OpenPGP uses a /really/ strange cipher mode for symmetrical ciphers that is not supported by SSC. I took the (open source) implementation from the Mono project and modified it accordingly. The asymmentrical ciphers are also from Mono, for coherancy (spelling?) reasons.
Greets,
Daniel
---
SharpPrivacy - A free OpenPGP Implementation in c#
http://sharpprivacy.sf.net
|
|
|
|
|
While I agree with gek_at (and this is a common approach), another way depends on how you save the encrypted file. Using different extensions is still better, but you could stream the cipher text through a ToBase64Transform and enclose the base64 text in something like what PGP does:
----- BEGIN ENCRYPTED TEXT -----
base64 encoded cipher text
----- END ENCRYPTED TEXT ----- Then you could check that the first and last lines contain this text. Of course, someone could spoof it or mistakenly include those in their file (but what are the chances of that?), but even PGP would complain about such an error. Also, PGP can also parse an entire text file and treat anything not in between these lines (and it can handle multiple blocks of encased cipher text like this) as unencrypted text.
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
Hi!
I have a question concerning inter process communication. My application is written in c# and runs as a windows service. It should be able to provide its services to applications written in many different programming languages (c++, java, ...). Currently it uses .NET remoting, but as I understand it, only .NET applications can use that. What would be a more generic approach? Sockets would probably be the most compatible way, but they are also not very comfortable to use. So is there something in between remoting and sockets for inter process communication?
Thanks in advance,
Daniel
---
SharpPrivacy - A free OpenPGP Implementation in c#
http://sharpprivacy.sf.net
|
|
|
|
|
.NET Remoting can be made to work in other languages, but it's a real b*tch. Since the messages are SOAP (assuming you use a SoapFormatter for the serialization sink), you can always tranform them.
There are many other options available, though. While you may not be comfortable with sockets, it's always good to learn new things! You could define a simple protocol using commands like SMTP, HTTP, and countless others. This would definitely be the most open approach.
Another way would be to host the ASP.NET runtime in your service (a little resource intensive, but not too bad) and host an XML Web Service. The SOAP bindings for these are industry standard, and Java and C++ (with, for example, the SOAP toolkit for C++ from Microsoft) should have no problems handling this.
It's really not that difficult hosting ASP.NET, either. ASP.NET Web Matrix (a free ASP.NET designer from Microsofties at http://www.asp.net[^]) does it, and VS.NET 2005 will do it for ASP.NET Web Application projects as well (so no more dependency on IIS! ). See the documentation for System.Web.Hosting.ApplicationHost in the .NET Framework SDK for more information. This would be just about as open as using a TCP protocol, except that it requires the client understand SOAP (and most languages do through extensions/mods, like Java, C++, Perl, etc.). IMO, it would even be a better approach since it allows you to develop a transport capable of more easily transporting complex objects, rather than having to serialize them to a byte[] array to send over a NetworkStream .
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
Thanks for the input! I think I'll settle for sockets that send and receive XML formated commands. As the server sends the return as XML even now with remoting, I guess that should be the easiest. Hosting a Webservice is a bit of an overkill IMHO . Especially as the service should require as few resources as possible (.NET is such a resource killer anyway .
Thanks again!
Greets,
Daniel
---
SharpPrivacy - A free OpenPGP Implementation in c#
http://sharpprivacy.sf.net
|
|
|
|
|
hi,
I've two questions how do I mashal
BOOL WINAPI Toolhelp32ReadProcessMemory(
DWORD th32ProcessID,
LPCVOID lpBaseAddress,
LPVOID lpBuffer,
DWORD cbRead,
LPDWORD lpNumberOfBytesRead
);
using dll import so that I can use it with a buffer? I think I should use IntPtr, cut when I declare the buffer how should it be declared? need to use unsafe ? I'm trying to use it on a PocketPc, so MarshalAs class is not implemented ( as I've read), need I to make an array of bytes or what else?
thanks
Paolo
|
|
|
|
|
Yes, you do use an IntPtr , and no you don't need an unsafe context. I do a heck of a lot of P/Invoke (it's my forte', some might say) and have never once had to use an unsafe context.
To alloc the buffer (if you need to - in this case you don't since it's an output parameter), you can use several methods on the Marshal class in System.Runtime.InteropServices .
Since this is an output parameter, you can use Marshal.Copy(IntPtr, byte[], int, int) to copy the data to a byte[] array. The latter method is supported by the .NET CF.
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
how can I use the Marshal.Copy if the buffer I need to write into is accessed by the funcion Toolhelp32ReadProcessMemory ? I declared a byte array as you told but I receive
D:\projects\PPC\.cs(28): Argument '3': cannot convert from 'byte[]' to 'System.IntPtr'
I did
<br />
byte[] databuffer= new byte[4096];<br />
uint byteread=0;<br />
Toolhelp32ReadProcessMemory(p.Handle,p.BaseAddress,databuffer,100,(uint)byteread);<br />
thanks again, you always answer me clearly and focusing the point!
Paolo
|
|
|
|
|