|
You can find all this information in the Platform SDK, both in the documentation and in the C/C++ header files, like winuser.h and commctrl.h (most common defs). You should also check on http://pinvoke.net[^] for the managed signatures for unmanaged functions.
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
well done
i found it : #define EM_SETPARAFORMAT (WM_USER + 71)
but what is tha value of WM_USER in my use?
thanx so much stewart
|
|
|
|
|
That's also a pre-prof def you'll find in winuser.h. I'd recommend indexing your various include folders to make them easier to find, or use a good text editor like VIM[^] along with ctags[^] to easily find tokens such as this while typing code in the text editor.
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
ifound that :
#define WM_USER 0x0400
i use send message like below :
..........
public const int EM_SETPARAFORMAT = 1095;
[DllImport("user32.dll")]
private static extern int SendMessage(IntPtr hWnd, [MarshalAs(UnmanagedType.U4)] int msg,
int wParam, ref PARAFORMAT2 format);
[StructLayout(LayoutKind.Sequential)]
public struct PARAFORMAT2
{
public UInt16 cbSize;
public UInt64 dwMask;
public double wNumbering;
public double wEffects;
public long dxStartIndent;
public long dxRightIndent;
public long dxOffset;
public double wAlignment;
public short cTabCount;
public long[] rgxTabs;
public long dySpaceBefore;
public long dySpaceAfter;
public long dyLineSpacing;
public short sStyle;
public Byte bLineSpacingRule;
public Byte bOutlineLevel;
public double wShadingWeight;
public double wShadingStyle;
public double wNumberingStart;
public double wNumberingStyle;
public double wNumberingTab;
public double wBorderSpace;
public double wBorderWidth;
public double wBorders;
};
PARAFORMAT2 Format = new PARAFORMAT2();
Format.dwMask = 0x0008;
Format.wAlignment = 0x0004;
Format.wNumbering = 0;
Format.cbSize = (UInt16)Marshal.SizeOf(Format);
Format.wEffects = 0x00400000;
Format.rgxTabs = new long[]{0};
Format.cTabCount = 1;
Format.bOutlineLevel= 0;
SendMessage(PickControl.SelectedControl.Handle,EM_SETPARAFORMAT,0,ref Format);
...........
but it's execution takes no effect to my richtextbox!
and sendmessage returns zero value!
what is my problem?
|
|
|
|
|
Do you know anything about native and managed data types? Your structure is completely wrong, thus it's not being marshalled correctly which explains why you're not seeing anything change. A LONG in C is not a Int64 (or long alias, which is recommended for readibility) but instead a Int32 (or int ).
The structure should be defined like this:
[StructLayout(LayoutKind.Sequential)]
public struct ParaFormat2
{
[MarshalAs(UnmanagedType.SysUInt)] public IntPtr cbSize;
[MarshalAs(UnmanagedType.U4)] public int dwMask;
[MarshalAs(UnmanagedType.U2)] public short wNumbering;
[MarshalAs(UnmanagedType.U2)] public short wEffects;
public int dxStartIndent;
public int dxRightIndent;
public int dxOffset;
[MarshalAs(UnmanagedType.U2)] public short wAlignment;
public short cTagCount;
[MarshalAs(UnmanagedType.ByValArray, SizeConst=32)] public int[] rgxTabs;
public int dySpaceBefore;
public int dySpaceAfter;
public int dylineSpacing;
public short sStyle;
public byte blineSpacingRule;
public byte bOutlineLevel;
[MarshalAs(UnmanagedType.U2)] public short wShadingWeight;
[MarshalAs(UnmanagedType.U2)] public short wShadingStyle;
[MarshalAs(UnmanagedType.U2)] public short wNumberingStart;
[MarshalAs(UnmanagedType.U2)] public short wNumberingStyle;
[MarshalAs(UnmanagedType.U2)] public short wNumberingTab;
[MarshalAs(UnmanagedType.U2)] public short wBorderSpace;
[MarshalAs(UnmanagedType.U2)] public short wBorderWidth;
[MarshalAs(UnmanagedType.U2)] public short wBorders;
} The cbSize is defined as an IntPtr and marshalled as UnmanagedType.SysUInt because a UINT is defined as an unsigned int , where int is a platform-specific type. For 32-bit OSes, it's 32 bits. For 64-bit OSes, it's 64 bits. The OS, of course, is dependent on the bit-width of the processor.
To create the struct you need, do something like this:
ParaFormat2 format = new ParaFormat2();
format = new IntPtr(Marshal.SizeOf(typeof(ParaFormat2)));
format.dwMask = 8;
format.wAlignment = 4;
SendMessage(richTextBox1.Handle, 1095, 0, ref format);
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
thanks stewart
it worked nice!
but i have another problem :
my language is right to left when
i send message to justify text align
the richtextbox RightToLeft property becomes
to RightToLeft.NO but it's first value was RightToLeft.Yes!
and setting that again to RightToLeft.Yes does not affect the text!
it only works properly when RightToLeft property value is RightToLeft.No!
what can i do?
how can i have deep study on native and managed data types and marshalling?
do i need special resources to do this study?
best wishes
|
|
|
|
|
Study the Platform SDK and the .NET Framework SDK. Get some experience writing native C/C++ applications which use Windows messaging, perhaps even extending the common controls.
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
Thanks for the Justify module.
Have you ever found the solution to the RightToLeft problem?
This problem also appears when using RightToLeft fonts.
Cheers!
|
|
|
|
|
hi my dear
if there is any free rtf parser component please
notify me about that or help me to find right ways to
writing complete rtf parser
thanks alot
hassan azizi
|
|
|
|
|
The RichTextBox both parses and displays RTF. If you don't need to display it (which brings-up the question, why bother parsing it unless you plan on converting and saving it?), you can use a Windows Rich Edit control, but that requires a lot of re-declaring COM interfaces and P/Invoking native methods. If you're not advanced in the ways of interoperability in .NET, you're probably better off finding a third-party solution, which you most likely won't find for free. It's a lot of work to correctly support all that is contained in the RTF spec. What do you expect?
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
i have wrote a simple rtf parser that parses rtf text of a richtextbox control
it parse paragraphs,text styles,alighn,color,links,languages,charsets and so on... .but i want to extend it to support most of RTF specification scripts !
and it seems to be so hard!
i want someone to join me for this work
thanks alot
hassan azizi
|
|
|
|
|
i have wrote a simple rtf parser that parses rtf text of a richtextbox control
but i want to extend it to support most of RTF specification scripts !
and it seems to be so hard!
i want someone to join me for this work
thanks alot
hassan azizi
|
|
|
|
|
private void resetPage()
{
foreach (Control c in Page.Controls)
if (c is TextBox)
((TextBox)c).Text = "";
}
on my web page it will not reset the text to ""
|
|
|
|
|
Are the TextBoxes in another container (a group box or panel)?
<br />
private void resetPage(){<br />
resetPage(Page);<br />
}<br />
<br />
private void resetPage(Control container){<br />
foreach (Control c in container.Controls) <br />
if (c is TextBox) ((TextBox)c).Text = "";<br />
else resetPage(c);<br />
}<br />
|
|
|
|
|
|
do apologise i should have tried your code first it worked a treat.
|
|
|
|
|
how can i create a new bitmap file?
i can not find the constructor,all the constructor is for the existing file?!
|
|
|
|
|
Bitmap b = new Bitmap ( width, heoght );
b.Save ( filename );
Q:What does the derived class in C# tell to it's parent?
A:All your base are belong to us!
|
|
|
|
|
Thank you very much
i think i got it
|
|
|
|
|
And if you want to paint on it:
Bitmap bmp = new Bitmap(width, height);
Graphics g = Graphics.FromImage(bmp);
g.FillRectangle(Brushes.Red, new Rectangle(0, 0, bmp.Width, bmp.Height));
g.Dispose();
bmp.Save("C:\\Image.png", ImageFormat.Png);
bmp.Dispose();
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
Ive been programming in C# for a while now, but there are a few technical performance issues I don't know yet.
There are a couple of things I use a lot (and I am growing used to using them), like ArrayLists.
I want to know which of these really easy to use things, like foreach loops, ArrayLists etc has a big performace hit.
And if they do, what should I use when performance is a great issue?
|
|
|
|
|
I myself, always try to use for loop which is much faster than foreach loop . On the other hand, if I have a class named Class1 , I'd prefer to store it in an Array of its own type instead of ArrayList , getting rid of type casting issues.
Don't forget, that's Persian Gulf not Arabian gulf!
Murphy: Click Here![^] I'm thirsty like sun, more landless than wind...
|
|
|
|
|
Type-casting isn't so much of an issue with reference types. It results in only 1 to 2 extra IL instructions. When casting value types, however, the value type must be unboxed (it's boxed in the ArrayList since it stores object s) and that is a serious performance hit. That's when a typed array (like int[] ) is definitely better.
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
 Boxing is very expensive, and I always avoid it, but even casting can introduce more performance drain than you may think. Try running this code on your setup to see what I mean.
<br />
long startTime, endTime;<br />
int loopCount = 10000000;<br />
<br />
Guid guid = Guid.NewGuid();<br />
Guid guid2 = guid;<br />
object o = guid;<br />
object[] objectArray = {guid};<br />
Guid[] guidArray = {guid};<br />
<br />
startTime = DateTime.Now.Ticks;<br />
for(int x = 0; x < loopCount; x++) {<br />
guid = (Guid)objectArray[0];<br />
guid = (Guid)objectArray[0];<br />
guid = (Guid)objectArray[0];<br />
}<br />
endTime = DateTime.Now.Ticks;<br />
Console.WriteLine(((endTime - startTime) / 10) + " microseconds total (accessing array of objects)");<br />
<br />
startTime = DateTime.Now.Ticks;<br />
for(int x = 0; x < loopCount; x++) {<br />
guid = guidArray[0];<br />
guid = guidArray[0];<br />
guid = guidArray[0];<br />
}<br />
endTime = DateTime.Now.Ticks;<br />
Console.WriteLine(((endTime - startTime) / 10) + " microseconds total (accessing array of Guids)");<br />
<br />
startTime = DateTime.Now.Ticks;<br />
for(int x = 0; x < loopCount; x++) {<br />
guid = (Guid)o;<br />
guid = (Guid)o;<br />
guid = (Guid)o;<br />
}<br />
endTime = DateTime.Now.Ticks;<br />
Console.WriteLine(((endTime - startTime) / 10) + " microseconds total (assigning Guid from object w/ cast)");<br />
<br />
startTime = DateTime.Now.Ticks;<br />
for(int x = 0; x < loopCount; x++) {<br />
guid = guid2;<br />
guid = guid2;<br />
guid = guid2;<br />
}<br />
endTime = DateTime.Now.Ticks;<br />
Console.WriteLine(((endTime - startTime) / 10) + " microseconds total (assigning Guid from Guid)");<br />
<br />
Environment.Exit(0);<br />
<br />
This gave the following output on my setup, a dual P4 Xeon workstation running VS.NET 2003 in Debug mode:
468750 microseconds total (accessing array of objects)
421875 microseconds total (accessing array of Guids)
484375 microseconds total (assigning Guid from object w/ cast)
375000 microseconds total (assigning Guid from Guid)
Casting overhead is actually one of the major performance drains when using generic collections, after things like method-call overhead and synchronization. I'm not saying that nobody should use collections, but it's good to know how you're spending cycles. I agree with maysam; there's no reason to cast unnecessarily, and good reasons to avoid it.
Regards,
Jeff Varszegi
EEEP!
|
|
|
|
|
A Guid is a value type, so there is boxing/unboxing involed with casting.
Microsoft MVP, Visual C#
My Articles
|
|
|
|