|
Blake, that code uses a variable called m_nCharHeight that is not defined in the code. How is the value of this variable computed?
|
|
|
|
|
It's just a cached copy of the tmHeight height value from the TEXTMETRIC for the currently selected font. Here's the relevent bit out of the middle of an EnumFontFamilies callback:
HDC hdc = GetDC(NULL)
LOGFONT lf = pelf->elfLogFont;
lf.lfHeight = -MulDiv(pParam->pCon->m_nPointSize,
GetDeviceCaps(hdc, LOGPIXELSY), 72),
lf.lfWidth = 0;
HFONT hf = CreateFontIndirect(&lf);
TEXTMETRIC tm;
HFONT hfOld = (HFONT)SelectObject(hdc, hf);
GetTextMetrics(hdc, &tm);
SelectObject(hdc, hfOld);
ReleaseDC(NULL, hdc);
SendMessage(pParam->pCon->m_hOutput, WM_SETFONT, WPARAM(hf), 0);
SendMessage(pParam->pCon->m_hInput, WM_SETFONT, WPARAM(hf), 0);
DeleteObject(hf);
pParam->pCon->m_nCharWidth = tm.tmAveCharWidth;
pParam->pCon->m_nCharHeight = tm.tmHeight;
--
-Blake (com/bcdev/blake)
|
|
|
|
|
What is the equivalent quantity in managed .NET (perhaps accessible through the Font class)?
|
|
|
|
|
Ah. Well, thanks, I took a look. I don't know the Win API but it appears that the idea in the blog is to compute the difference between the vertical extents of the window and the client area, and use the difference to adjust the size of the window so that the client area comes out to be an integral number of text lines.
In the example I gave, getting the client area to be a desired size is not the problem. The desired vertical size of the client area is 110 pixels, and that is what the area is as measured with a screen dump. It appears that setting the ClientSize property of the rich text box to use a height of 110 does in fact set the client area to 110.
So I think the blog might be solving a different problem than what's needed here.
One problem I did notice is that the font's Font.Height value is given as 22 pixels, but the baseline-to-baseline spacing in the rich text box is 24 pixels. Does anyone know why this might be? It's certainly necessary to account for this in order to get an integral number of text lines. Maybe there is some Font or RichTextBox property that needs to be used besides Font.Height.
|
|
|
|
|
I need to wait on a native handle to be signaled from within a managed application. I am trying to pinvoke to WaitForSingleObject but keep getting a missing method exception.
I successfully pinvoked into SetEvent and CreateEvent. But when I try to call WaitForSingleObject, the exception "missingmethodexception" is thrown, so something is probably wrong with my managed WaitForSingleObject definition and the marshaler is complaining. My managed definitions are:
[DllImport("coredll.dll")]
private static extern int CreateEvent(
IntPtr lpEventAttributes, //?? set as NULL
bool bManualReset,
bool bInitialState,
string lpName
);
[DllImport("coredll.dll")]
private static extern bool SetEvent(
int hEvent
);
[DllImport("coredll.dll")]
private static extern uint WaitForSingleObject(
int hHandle,
uint dwMilliseconds
);
What's wrong with my WaitForSingleObject definition that would cause the exception? I am developing on windows ce.net and the api says WaitForSingleObject exists in coredll.dll.
Any help will be extremely appreciated.
|
|
|
|
|
WaitHandle wh = new WaitHandle();
wh.Handle = myNativeEventHandle;
wh.WaitOne();
--
-Blake (com/bcdev/blake)
|
|
|
|
|
I assume you mean ManualResetEvent since WaitHandle is abstract and you can't have an instance of it?
|
|
|
|
|
Yes - sloppy on my part. The important point was, don't P/Invoke at all, let the framework do it for you. You can wrap native sync objects in WaitHandle derived classes easily enough.
--
-Blake (com/bcdev/blake)
|
|
|
|
|
I am writing a C# application that will send canned email messages to specified email addresses. The spec for this project is pretty simple. I want to pass a string to my object in the form of "LastName, FirstName" and I want to be able to verify that this is a valid name in the global address book from Outlook. I have so far been unable to access the global address book? After I find the name in the GAB I want to send a canned message to that person's email address. I am also not sure of how to get their email adress once I verify their name in the GAB. I plan on using MAPI to send the messages which I am also not very familiar with. I am a newbie with C# and I would really appreciate any help anyone has to offer. Thanks for your time and happy coding!
Frank
|
|
|
|
|
I can't get what you mean by canned mail... anyway, MAPI is no longer our darling... to send an email... follow following steps...
Add reference of System.Web into your project... and do following in code...
<br />
using System.Web.Mail;<br />
.......<br />
.......<br />
.......<br />
.......<br />
.......<br />
MailMessage mail = New MailMessage()<br />
<br />
mail.To = ToMail;<br />
mail.From = FromMail;<br />
mail.Subject = Subject;<br />
mail.Body = Msg;<br />
<br />
SmtpMail.SmtpServer = "localhost";<br />
<br />
try<br />
{<br />
SmtpMail.Send(mail)<br />
Return true;<br />
<br />
} Catch ex As Exception<br />
{<br />
Return false;<br />
}<br />
Explore more... you can send attachments and blah blah with it too..
Good Day; <wish me="" one="" too="" coz="" need="" today="" ="">
mE
---------------------
A gasp of breath,
A sudden death:
The tale begun.
A rustled page
Passes an age:
The tale is done.
|
|
|
|
|
Does .NET framework have the facility to write objects to the underlying steams (as in Java)?
|
|
|
|
|
Yes, it does. Take a look at the System.Runtime.Serialization namespace.
"Blessed are the peacemakers, for they shall be called sons of God." - Jesus
"You must be the change you wish to see in the world." - Mahatma Gandhi
|
|
|
|
|
.NET serialization is excellent. What I don't know about is reading the old MFC objects, but this probably can be done.
"Blessed are the peacemakers, for they shall be called sons of God." - Jesus
"You must be the change you wish to see in the world." - Mahatma Gandhi
|
|
|
|
|
I have a form that contains a bunch of controls that are bound to a dataset. The form includes a tab control which contains several other pages of control which are all bound to the same dataset. Okay, but here's the problem, I have a button which is supposed to take the data on the form and do something with it, the trouble is the controls on the tab pages which are initally hidden when the form first appears don't get bound. They end up being null. But, if the user clicks to display the hidden pages before clicking the button (even if he hides them again first), they have been properly bound and contain the values they are supposed to contain. So how do I avoid this problem since I obviously can't ask the user to click every tab page before they click the button!!
Thanks
|
|
|
|
|
This kind of solves the problem, I run this code when the button that needs all the controls to have been bound is called:
<br />
int CurTab = myTabControl.SelectedIndex;<br />
<br />
for (int i=0; i!=myTabControl.TabCount; i++)<br />
{<br />
myTabControl.SelectedIndex = i;<br />
}<br />
myTabControl.SelectedIndex = CurTab;<br />
This at least insures that none of the bound controls on any of the tab pages end up being null. The problem is that it does make the tab control flicker (as it brings each tab control forward for just a fraction of a second) and I seriously can't believe there isn't a better way to do this! Any suggestions please?
|
|
|
|
|
Hi,
I have a windows form which is used to config my application settings. It contains a couple of text boxes that are supposed to contain file paths to some other applications which are used by my application. What I would like to do is when the user clicks the okay button (to accept the changes they've made to the settings) I like the form to validate both text boxes to check that they are okay (a simple test to see if the files actually exist). The problem is that I've tried using the validating event on the text boxes but that gets fired when the textbox losses focus (which I don't want), but doesn't get fired when I click the okay button (which I want to have happen). I tried using the validate event on the form itself, but that never seems to get fired. What's the right way to do this? I know I can just validate the boxes in the OnClick event of the okay button, but I'll probably be adding more controls to the form and I don't want to lump all the validation in one place when it seems to make more sense to have the controls deal with their own validation.
Cheers
|
|
|
|
|
Hi to all,
I have a requirement to call methods of an unmanaged ActiveX control (MFC ActiveX 6.0) from C#. The solution is straightforward if my application is GUI based, but my application has no GUI.
Can anyone give me an idea of how to go about this.
Thanks,
Coding is injurious to health!!
|
|
|
|
|
Hi
I have created a windows form and added a number of datasets from the toolbox. Now, the datasets appears next to menues etc. in the bottom of the form's designview.
Is there a way to access these datasets from the code as a collection - i.e. in the same way as it is possible to access the controls of the form using "this.controls"??
In other words: What I'm looking for is something like "this.datasets" or similiar.
Thanks for your help,
Mads
|
|
|
|
|
Not aware of a 'this.datasets'-like collection in C#. Multiple data adapters within a data set may be accessed in fashion similar to a collection. You probably already knew this. If not though, any way to organize the data within a single set?
>>>-----> MikeO
|
|
|
|
|
Unfortunately there is no way to organize the data within a single set. We have several hundred forms in the app. and each form can contain a number of dataobjects.
The dataobjects are about 30 datasets and each dataset contains one special type of table. Since we need to be able to combine the dataobjects in different ways on each form, it's not possible to organize the data within a single set.
Mads
|
|
|
|
|
When developing gui applications with MFC it is customary to create a worker and a Gui thread. Both of these threads will communicate with each other through a message pump. This kind of architecture will provide a more responsive Gui.
Is there a .Net way of accomplishing the same thing. Basically a Gui thread and a Worker thread no more no less.
|
|
|
|
|
Take a look at Control.Invoke().
|
|
|
|
|
Thank you for your response.
I would like to ellaborate some more in regards to my question. I do not really want to replicate the MFC behavior in .net. Before I do that I would like to know if there is a .net technology that will basicall y accomplish the same thing. For example: Remoting, MessageQueue, web services, etc.
|
|
|
|
|
I have many datagrid-like line item cotrols in a winform form, after user comfirm changes, I need to remove those controls and reload them on the form. The user interface now showing the whole process of removing ctls and reloading. I do want user to have a wait cursor and the form freeze for a while until the process is done, any idears on how to accomplish it?
|
|
|
|
|
Use the form's SuspendLayout() and ResumeLayout() methods.
Cheers, Julian
Program Manager, C#
This posting is provided "AS IS" with no warranties, and confers no rights.
|
|
|
|