|
Thanks for the answer.
I tried PostMessage as well. It does not work.
I do not do it in an event handler of a menu.
My goal is to create a more robust editor then TextBox(that’s all there is in the .net CF, no RichTextBox). Therefore I build an extended TextBox with cut,copy,paste and more.
My other problem is that when I try to add text programmatically:
int len = textBoxTerminal.Text.Length;
textBoxTerminal.SelectionStart = len;
textBoxTerminal.SelectionLength = len;
textBoxTerminal.SelectedText = (string)StringToAdd;
the caret always positions itself in the beginning of the TextBox's Text.
I can reposition it to the end and scroll, but this causes the TextBox to flicker. I thought PostMessage will help solving this, but I cannot test it for the Since PostMesage does not work for me.
Hope you have an answer for this...
Thanks.
avivhal
|
|
|
|
|
What is the return code for SendMessage ? Check this against the errors in winerror.h.
You should also set the DllImportAttribute.CharSet field to CharSet.Auto . There is actually no SendMessage function, but SendMessageA (ANSI) and SendMessageW (Wide-char, or Unicode). The Windows .NET CE platform is actually Unicode, so you could P/Invoke SendMessageW and set DllImportAttribute.EntryPoint to "SendMessageW" (since DllImportAttribute.ExactSpelling is not supported for the .NET CF).
This posting is provided "AS IS" with no warranties, and confers no rights.
Software Design Engineer
Developer Division Sustained Engineering
Microsoft
[My Articles] [My Blog]
|
|
|
|
|
Neither DllImportAttribute.CharSet nor SendMessageW worked.
I did get it to work though (somehow)...
I took the declarations I have of SendMessage(I have a few overloads) :
[DllImport("coredll")]
public static extern IntPtr SendMessage(IntPtr hWnd, int msg, int wParam, int lParam);
and wrapped them in a separate class.
Then I called them as this class's static members and it works!
I do not understand why would this solve the problem though...?
Maybe the problem was that they were members of a TextBox (Form) derived class and this caused congestion problems with the Form’s own messages?
I wish I had the OS source code so I could check this;)
avivhal
|
|
|
|
|
How were you doing it before? C# does not support functions - only methods. They would've had to have been members of a class before or else you couldn't have even compiled your source file.
BTW - those last two parameters are process-dependent types and should be IntPtr . If you're needing to pass pointers to structs or char arrays (strings), you can define overloads that would amount to a pointer, such as simply string or ref MyStruct . int is an Int32 in C# and will always be 32 bits. If you ever hope to port this - whether the source or binary - you'll need to change it anyway.
External methods must always be static, too, but you declared them statically before, did you not?
This posting is provided "AS IS" with no warranties, and confers no rights.
Software Design Engineer
Developer Division Sustained Engineering
Microsoft
[My Articles] [My Blog]
|
|
|
|
|
They were static members of the my TextBoxEx class before.
All I did was build a new class and pass the methods to be static members of the new class. then call them as the new class methods.
e.g. if my old class was Aclass and the new Bclass then in Aclass I call:
Bclass.SendMessage(...);
I have a few overloads such as
[DllImport("coredll")]
public static extern IntPtr SendMessage(IntPtr hWnd, int msg, IntPtr wParam, String lParam);
[DllImport("coredll")]
public static extern IntPtr SendMessage(IntPtr hWnd, int msg, IntPtr wParam, byte[] lParam);
that take addresses (pointers). I only use :
[DllImport("coredll")]
public static extern IntPtr SendMessage(IntPtr hWnd, int msg, int wParam, int lParam);
to call with 0 lparam and wparam thus:
Bclass.SendMessage(this.Handle, (int)ClipboardMessage.WM_UNDO, 0, 0);
I probably should use 2 pointers (IntPtr) instead and lock the IntPtr for the GC before calling this method?
Thanks,
Aviv.
avivhal
|
|
|
|
|
On what class they're defined shouldn't matter, but perhaps some of your overloads were conflicting.
With value types - like int - you do not need to pin them (see the GCHandle class, BTW). Reference types may be moved by the GC on the heap, but it depends how the message handler uses the data; you may not need to pin the memory. Strings are reference types but this data is typically used synchronously with SendMessage (PostMessage , on the other hand, is a different story). When passing addresses of reference objects (as IntPtr , or just a GCHandle which works, too, as well as a HandleRef ) you should pin them.
For robust code, never use fixed-size integers for the WPARAM and LPARAM . Always use IntPtr . For 0, just use IntPtr.Zero and to wrap an int or long use new IntPtr(int) or new IntPtr(long) , respectively.
This posting is provided "AS IS" with no warranties, and confers no rights.
Software Design Engineer
Developer Division Sustained Engineering
Microsoft
[My Articles] [My Blog]
|
|
|
|
|
Can anyone tell me how to print text and images within a rich text box?
Thanks,
Sterling
|
|
|
|
|
|
I'm trying to use p/invoke in the .NET CF in order to create copy,paste and other operations.
I use the following code:
[DllImport("coredll.dll")]
internal extern static int SendMessage(IntPtr Hwnd, int Msg, int WParam, int LParam);
SendMessage(this.hwnd, (int)ClipboardMessage.WM_CUT, 0, 0);
I noticed that the desired operation never happens! All other p/invoke I use work fine. Only the SendMessage does not work (I tried many other like WM_CHAR,WM_VSCROLL and more, nothing works)
Thanks.
avivhal
|
|
|
|
|
I have enabled the xp styles for a windows application with Application.EnableVisualStyles() and seted to all the controls that have a FlatStyle property to FlatStyle.System .
The problem apears at a CheckedListBox , the CheckBox 'es that it contains doesn't take the style and it doesn't have a FlatStyle property. I didn't manage to find a property for the items (CheckBox 'es) that it contains, all I've found was a string that represented an item (a string item).
Can anybody help me?
I hope you understand...
By the way... visit http://nehe.gamedev.net[^]
|
|
|
|
|
The CheckedListBox does use the ComboBox control - it draws checkboxes using ControlPaint.DrawCheckBox , which doesn't take advantage of the Theme API.
To accomplish what you want you'll have to extend the CheckedListBox and override OnDrawItem , using the DrawItemEventArgs.Graphics to get an HDC (handle to a device context), draw the checkbox you want using the Theme API, then release the HDC :
public XPCheckedListBox : CheckedListBox
{
protected override void OnDrawItem(DrawItemEventArgs e)
{
IntPtr hdc = e.Graphics.GetHdc();
e.Graphics.ReleaseHdc(hdc);
}
} To draw a themed checkbox you'll need to P/Invoke the Theme APIs, which you can read about at http://msdn.microsoft.com/library/en-us/shellcc/platform/commctls/userex/refentry.asp[^]. For help with P/Invoke signatures, see http://pinvoke.net[^].
Be sure to read about the Theme API because it's not a simple set of APIs.
Also note that in .NET 2.0 themes should be (it's still beta, so nothing's set in stone till release) encapsulates. For documentation about these set of classes in .NET 2.0 Beta1, see http://msdn2.microsoft.com/library/System.Windows.Forms.VisualStyles.aspx[^].
This posting is provided "AS IS" with no warranties, and confers no rights.
Software Design Engineer
Developer Division Sustained Engineering
Microsoft
[My Articles] [My Blog]
|
|
|
|
|
I am trying to write a spellcheck application in C#.NET, that will utilize ASPELL to detect, whether the text entered in a textbox is valid or not. I don't want to use word.dll because that means the user has to have Microsoft word installed in his/her machine. There is one such project over here, but I don't really understand how it works. Is there a simple way to do this? Somebody suggested integrating ASPELL to my code, but I have no idea how to do that. Can somebody help me out?
|
|
|
|
|
I need that Regex won't return match if the string starts with another substring, for example "abc".
In detail, "abcde " shouldn't match, but "abg ", "gbc " and "afcgr " should match.
I know the [^abcde] syntax that works for characters, but I couldn't figure out way for substrings.
It is possible to do this with Regex?
I need it to be done through Regex, not String class methods.
Thanks.
|
|
|
|
|
|
I think you missed the point.
"abc" should not match.
I want to match any combination of three characters, except the above sequence.
I can do it as well with two chars. For example, if i want to match anything except "ab", i can use (?:a[^b])|(?:[^a].) .
But when it comes to three or more characters, i find no way. Maybe I miss something.
Thanks.
|
|
|
|
|
"[^(abcd)]+" seems to be working
a better way would be: "^(?!abcd).+"
(I'm not sure if (?!x) is a valid expression in the C# Regexes)
|
|
|
|
|
sb777 wrote:
Maybe I miss something.
Perhaps
It is infact matched just not returned, well at least not as a named group. Al you have to do is check is Groups["good"].Success . As long as your precedence is correct, you can match and 'eleminate' alot of data at once.
top secret Download xacc-ide 0.0.3 now! See some screenshots
|
|
|
|
|
TyronX,
yous second suggestion did answered my question. thanks a lot. BTW, the first one isn't correct.
leppie,
Your suggestion could also fit in another constraints, but thanks for the new information.
|
|
|
|
|
I'm making a class to manage textures, and i have them stored in a hashtable. Now I have two possible objects I could use as a key, a texturedata object that describes the texture, or a compressed string format dataobject (like a Key or an ID string).
Would a hash table lookup a string quicker than an object?
Cheers guys.
Cata
|
|
|
|
|
|
Ok, that's cool. Now another question.
What would take up more space in memory overall? A class with 5-6 parameters, say a short string, few ints, and enumerations. Or a single string of say 40 charachters?
I'm assuming that i will have a few hundred objects with these values in them, so i'd like to make it efficient for space. If i remember correctly, a string is a value type, so it will take up space for each instance of itself. Now, if 100 objects have this string key, it will be 100x the string value. But if I use an object, they are handled as refference type, and only 1 exists, but many objects would have access to it.
Am I right? Would an object form be less expensive for memory?
On the other hand, some of these objects may only be used once, and therefore could benefit from the smaller space that the string would be.
Of course, I could always go with pointers to strings... but it could be a headache.
what do you think?
Cheers
Cata
|
|
|
|
|
Is this for an embedded system? Otherwise quibbling about the overhead for a few hundred objects seems pretty silly.
Anyway, since you didn't say how long the "short string" is, there's no way to guess.
As far as the value type stuff goes, there can be many references to one string. In fact, many identical string literals in your code will all result in the same string in a "constant pool" that is shared (that is, all the places where it is used in your code will instead have a reference to that one constant string instance).
> Now, if 100 objects have this string key, it will be 100x the string value.
No, that's not correct. Of course, there is an exception and it depends on how the references are created. If you create a hundred of these:
class MemHawg
{
string name;
public MemHawg( string name )
{
this.name = new string( name );
}
}
Then it will take more memory than this would:
class MemMiser
{
string name;
public MemMiser( string name )
{
this.name = name;
}
}
The first one makes a (somewhat useless) copy of the the string passed in, while the second one just has a reference to the one string. So in the second case, you'll have 100 objects that all refer to the same one string.
Of course, the latter implementation makes more sense, since there isn't much sense in duplicating immutable objects.
Matt Gerrans
|
|
|
|
|
Hellos friends ,I need that my printer print my document in mirror,I want manipulate this from c#,anyone help me.
Regards bigmega
|
|
|
|
|
In your even thandler for the PrintDocument.PrintPage event (or override of OnPrintPage if extending PrintDocument , which is usually a good idea for encapsulation) you need to apply a transformation matrix to the Graphics object by assigning the identity matrix to the Graphics.Transform property (the world transform) with either M11 or M22 negated to flip on the y-axis or x-axis, respectively.
For example:
using System;
using System.Drawing;
using System.Drawing.Drawing2D;
using System.Windows.Forms;
class FlipExample : Form
{
static void Main()
{
Application.Run(new FlipExample());
}
RectangleF left;
RectangleF right;
PointF[] triangle;
StringFormat format;
Matrix flipTransform;
FlipExample()
{
Text = "Flip Example";
SetStyle(ControlStyles.AllPaintingInWmPaint |
ControlStyles.DoubleBuffer | ControlStyles.ResizeRedraw |
ControlStyles.UserPaint, true);
format = StringFormat.GenericDefault;
format.Alignment = StringAlignment.Center;
OnResize(EventArgs.Empty);
}
void DrawCaption(Graphics g, RectangleF r, string caption)
{
g.DrawString(caption, Font, SystemBrushes.ControlText,
r, format);
}
void DrawTriangle(Graphics g, RectangleF r, bool flip)
{
if (flip)
{
g.Transform = flipTransform;
g.TranslateTransform(r.X, 0f, MatrixOrder.Append);
}
else
{
g.ResetTransform();
}
g.FillPolygon(SystemBrushes.ControlText, triangle);
}
protected override void OnPaint(PaintEventArgs e)
{
base.OnPaint(e);
Graphics g = e.Graphics;
DrawCaption(g, left, "Normal");
DrawCaption(g, right, "Flipped and Translated");
DrawTriangle(g, left, false);
DrawTriangle(g, right, true);
}
protected override void OnResize(EventArgs e)
{
float halfWidth = Width / 2f;
float halfFont = Font.Height / 2f;
left = new RectangleF(0f, 0f, halfWidth, (float)Height);
right = new RectangleF(halfWidth, 0f, halfWidth, (float)Height);
flipTransform = new Matrix(-1,0,0,1,halfWidth,0);
triangle = new PointF[] {
new PointF(halfWidth, halfFont),
new PointF(halfWidth, (float)Height
- SystemInformation.CaptionHeight - halfFont * 2f),
new PointF(0f, Height / 2f)};
base.OnResize(e);
}
}
This posting is provided "AS IS" with no warranties, and confers no rights.
Software Design Engineer
Developer Division Sustained Engineering
Microsoft
[My Articles] [My Blog]
|
|
|
|
|
I am trying to make windows installer uninstall the old version and install a new version upon a new release. I found a property RemovePreviousVersions and set it to true.
Accorting to documentation UpgradeCode must not change and ProductCode must be difference. After the install, I go to the Add/Remove programs and see both versions on the list. Is there something that I'm missing?
|
|
|
|
|