|
azusakt wrote:
can I directly create a cFont from LOGFONT in C++?
CreateFontIndirect would be the method for that, its a member of CFont.
azusakt wrote:
How can I convert C# Font to LOGFONT ? I know we can use Font.ToLogFont(), but I don't know how to use this function.
There could be other ways, but you can declare a structure similar to the LOGFONT in c# and then fill in this structure with the values from Font object and pass this structure to your C++ library. You need to go through P/Invoke to achieve this.
Your LOGFONT structure in C# would look like this,
[StructLayout(LayoutKind.Sequential, CharSet=CharSet.Auto)]
public class LOGFONT
{
public int lfHeight;
public int lfWidth;
public int lfEscapement;
public int lfOrientation;
public int lfWeight;
public byte lfItalic;
public byte lfUnderline;
public byte lfStrikeOut;
public byte lfCharSet;
public byte lfOutPrecision;
public byte lfClipPrecision;
public byte lfQuality;
public byte lfPitchAndFamily;
[MarshalAs(UnmanagedType.ByValTStr, SizeConst=32)]
public string lfFaceName;
}
Update :
You'd need to create an object of tihs type and then call ToLogFont function.
Hope this helps.
|
|
|
|
|
Actually, you don't even need to create the structure - only alloc enough memory to hold the LOGFONT information (remember that C/C++ has no such CTS like .NET), taking into account those last 32 characters, which could either be 32 bytes or 64 bytes depending on the current platform. Either way, it doesn't matter.
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
Thanks for all of your suggestions.
I just got an idea to create some variables for storing up the fonts status only, like bold, Italic etc..
Because I can't sure all variables in LOGFONT are useful, since Fonts(c#) does not contains lfEscapement, IfOrientation, lfOutPrecision, IfClipPrecision etc.
So I concern it may not able to output a correct text with the font I set in C# Fonts. I don't know what if I select some Asian, France, or Symbol for outputing.
so, what is the best way to do??
|
|
|
|
|
As the other person mentioned, you just call Font.ToLogFont - it takes care of everything. You don't need to fill the struct (or memory block) yourself. The LOGFONT does include all the parameters necessary to display your text using the Font you specify. To make sure that other fields are filled in, also pass an instance of the Graphics object for your operation, which you would get either from the PaintEventArgs (if in a Paint event handler) or from a call to CreateGraphics (don't forget to dispose the Graphics object in the latter case - do not dispose of it in the Paint event handler since the calling code will do it).
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
One More problem is the IfFaceName is TChar, how can I make it possible to store unicode FontName, like Chinese Font Name / Korean Font Name?
|
|
|
|
|
I'm sorry, I just got one problem can't solve yesterday....
If the font name I selected in C# is a Chinese name or Korea name, it can't fill correctly in C++. C++ just got one character.
I think it is the Unicode problem. When I select the font with Chinese name or Korea name, it can't copied to IfFaceName(in C++), because IfFaceName is TChar.
So I tried to set the project to use Unicode CharSet, then all chars become WChar; should I re-define the Size of IfFaceName, as it only allows max 32 chars. And also I can't use strcpy to copy WChar to Char ??
How can I prevent this problem ??
Thanks for help
|
|
|
|
|
Hi gurus,
In C#, I am writting a small program that sends text over a network (lan/web) using the sockets.
I can connect a client to a server, but I how can I see if a client disconnect from a server after being connected and how a client can see if the server is disconnected after being connected?
Thanks.
There is no spoon.
|
|
|
|
|
Try communicating in a set interval (a "ping" as it's commonly called). If they aren't connected for any reason, and exception would be thrown so be sure to handle it. There really is not other sure way of doing. Sure, you could implement some mechanism in your protocol where the client tells the server it's disconnecting, but that would assume that the connection wasn't interrupted. You could still implement such a protocol (it's common, like in SMTP, FTP, DICT, etc.), but don't rely on that as the only way for the reason I mentioned previously.
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
I am using quartz.dll in a thread to play some background music. I have made the sound named mc and i call mc.Run() inside a thread that i ahve named backgroundsound.
In any case when i close the application It still shows up in the processes as running. I can't seem to figure out how to complete dispose of all mc objects or threads if you will.
In my dispose i call backgroundsound.abort() to abort my thread and i call mc.stop() to stop the playing of my sound. Nothing seems to work any suggestions would be great.
Win32newb
"Programming is like sex, make one mistake and you have to support it for a long time"
|
|
|
|
|
Aborting your thread is not a good idea. You should terminate it gracefully when possible, whether that's through some static field you poll or some other mechanism.
The solution is more simple, though. When you create your thread, set Thread.IsBackground to true before you call Start . This won't prevent the thread from executing like a foreground thread, which instance of the Thread class are by default.
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
Hi everyone,
I am experimenting with ASP.NET charting. I have a bitmap of a given length and width and what I want to do is draw a string in the center of it. Is there a way to calculate the string parameters according to the specified font etc., so that I can know where exactly to draw it so that it will fall in the center.
Thanks,
Pankaj
Without struggle, there is no progress
|
|
|
|
|
You can try the MeasureString function, it gives you the size occupied by the string for the specified Font object.
|
|
|
|
|
Thanks Kannan!
I was using font.Size methods and all and wondering why it was not working.
Sincerely,
Pankaj
Without struggle, there is no progress
|
|
|
|
|
How to get the time when the program executing
Mr Duc Linh Nguyen
|
|
|
|
|
Do you mean DateTime.Now ?
Mazy
"One who dives deep gets the pearls,the burning desire for realization brings the goal nearer." - Babuji
|
|
|
|
|
I mean. I got a function and i execute it, then i want to know how long does function execute.
Mr Duc Linh Nguyen
|
|
|
|
|
Just record the time when the application/method begins execution and diff the time when it stops.
DateTime start = DateTime.Now;
TimeSpan duration = DateTime.Now - start;
Console.WriteLine("Ran for {0} milliseconds.", duration.Milliseconds); This is basically what Christian's source that someone mentioned is doing. I mean, how else would you do it?
If you want a more thorough solution, I recommend a CLR profile like this free one[^] from Microsoft.
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
Dear all,
i try to popup a dialog when i change item in a drop down list. i use javascript:
SelectDropDownList1.Attributes.Add("SelectedIndexChanged","Javascript: return confirm('sure?');");
the dialog won't display.
if i use:
SelectDropDownList1.Attributes.Add("onchange","Javascript: return myconfirm();");
confirm dialog will display, but it won't fire my function in code behind of SelectDropDownList1_SelectedIndexChanged.
would anyone give me some advice on this hassle? thank you.
David
|
|
|
|
|
Is AutoPostBack set to true on the control ?
Try not! Do or do not, there is no try. - Master Yoda
|
|
|
|
|
First of all, it's "javascript:return myconfirm();" (notice the colon), but you shouldn't use the "javascript" declaration. This scheme is only necessary when you use it in an attribute that accepts a URL, such as the A.href attribute.
If you change the the handler for the onchange event of your element, auto-post back won't occur since events only work with a single handler. You can, however, call __doPostBack (with the necessary params) in your myconfirm function. The work-around for this problem is just what I mentioned: since you can only have a single handler for an event, have that handler call other functions. Of course, you should call __doPostBack last since it will create a new request (thus resulting in round trip to the server).
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
Heath,
i try to work it out follow your way. here is the code i wrote:
in test.aspx.cs
private void Page_Load(object sender, System.EventArgs e)
{
// b1 is a invisible button will save change to database
string sCmd = Page.GetPostBackClientHyperlink(b1,"");
string script1 = "javacript: return myconfirm(" + sCmd + ")";
if (!Page.IsPostBack)
{
DropDownList1.Attributes.Add("onchange",script1);
}
}
in test.aspx
function myconfirm(cmd)
{
var agree = confirm("sure?");
if (agree)
eval(cmd);
}
but the browser always said the javascript code had errors. is there any error in string script1.
thanks.
david
|
|
|
|
|
As I mentioned before, don't include "javascript:" before your script. You only do this in URL attributes, like <a href="javascript:doSomething();">Do something</a> . In event attributes, you don't include this because they only work with script.
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
Hi Heath,
yes, i got the result i want finally. thank you.
and i have a similar question: how are radiobuttonlist? i can not use the same way to raise a popup dialog.(e.g. radiobuttonlist1.attributes.add( ... ))
david
|
|
|
|
|
Look at the rendered output when the AutoPostBack is set to true. There should be an attribute there that you could "override" in such a way.
Another way in both cases is to let ASP.NET do it's job and post back to the server, then use RegisterStartupSCript to include inline javascript toward the end of the page (before the single server-side form's closing tag) that pops up a window. When you start overriding event attributes, you take a big risk at breaking the ASP.NET pipeline (which is why - as I mentioned before - you must make sure you call __doPostBack with the right params in your javascript function).
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
Hi guyz,
Does any of you know how to pop up a save file dialog box for a web application? For example, if we want to save files (image, windows media files,mp3s) from the web to the user-end pc.
Thanks in advance guyz.
Rico
|
|
|
|