|
|
|
Thanks a ton!
|
|
|
|
|
Hi all. I got a huge problem while trying to draw a text with MFC. So, i got my custom class which extends CStatic.
In OnPaint:
CPaintDC dc(this);
Gdiplus::Graphics * gfx = Gdiplus::Graphics::FromHDC(dc.GetSafeHdc());
CDC * pDC = CDC::FromHandle(gfx->GetHDC());
pDC->TextOut(0, 0, "my text");
gfx->ReleaseHDC(pDC->GetSafeHdc());
Simple. But every time OnPaint gets called - new text is drawn over old one, so it is getting bolder and bolder. And, it is not like the old one never erased, but it is erased only when there are about 5 same texts drawn over each one.
Another thing, i've tried not to use Gdiplus at all - do everything only with CDC thing - same effect. Have used DrawText - same effect. Only with Gdiplus DrawString text is drawn correctly. But i need to draw it with Gdi32.
Thanks.
011011010110000101100011011010000110100101101110
0110010101110011
|
|
|
|
|
You can try using Graphics object gfx only for drawing. No need to mix GDI and GDI+.
Instead of TextOut(), use Graphics::DrawString()
|
|
|
|
|
The problem is i cannot use Gdiplus for drawing a string because my requirement is to draw the string with exact same font which windows OS uses. Gdiplus produce different font even if you do:
HFONT hFOnt = ::GetStockObject(DEFAULT_GUI_FONT);
and then create Gdiplus::Font from hFont. In theory you should have default font and maybe you do have, but DrawString draws text with a different font, not system default.
011011010110000101100011011010000110100101101110
0110010101110011
|
|
|
|
|
Use TextOut() or DrawText() function of CDC. Clear the earlier text with null string and then use drawing function.
|
|
|
|
|
Ahh, it was all about this MFC thing - sometimes you have to override some methods you got no idea about to make your control draw itself correctly. In this case it was:
OnWindowPosChanged
And just do nothing inside - static draws perfectly.
011011010110000101100011011010000110100101101110
0110010101110011
|
|
|
|
|
Hi, I have an app (MDI,MFC) with some buttons. I want to show information in a dialogo box with Edit control when I press a button, and, in adittion, I want to show in the same dialog other text when I press other button.
I know how to do the first part, but I dont know how to show other text in the same dialog when I press other button.
Could you help me, plz?
The buttons are in the Ribbon
|
|
|
|
|
Please share any relevant code with us, seeing the code might us help understand the problem you are facing. Please specify where in the code you are having problem.
If you wish to change your question use the Improve Question button.
0100000101101110011001000111001011101001
|
|
|
|
|
|
What is wrong with this[^]?
|
|
|
|
|
doooh :
yes, yes indeed.. SetDlgItemText(Dialogbox, IDC_EDITBOX, sString);
|
|
|
|
|
Your question is not very clear; however, if you mean by pressing an alternate button on the main window, then you will need a modeless dialog. If you mean a button in the dialog then your normal data exchange DDX_??? handlers should do it.
|
|
|
|
|
ok...when you press a button show a modeless dialog with a edit control to show text.
Class view:
void Cprueba4View::OnButton2()
{
CEjemplo *dlgDesc;
dlgDesc = new CEjemplo();
dlgDesc->Create( IDD_DIALOG1 ,GetDesktopWindow());
dlgDesc->ShowWindow(1);
}
In class CEjemplo:
void CEjemplo::ShowText(void)
{
CString cadena= _T("Hi, it is a example");
m_Edit.SetWindowTextW(cadena);
}
But I need, to show text from other class in the same dialog, that mean, the text, it will be added in the same windows when I press other button.
Every button are in the ribbon.
|
|
|
|
|
antonio343 wrote: I need, to show text from other class in the same dialog
How about making the ShowText function as public and pass a CString variable ;
void CEjemplo::ShowText(CString strText)
{
m_Edit.SetWindowTextW(strText);
UpdateData(FALSE);
}
call the public function of CEjemplo object as,
void CSomeOtherClass::ShowText()
{
CEjemplo oEjemplo;
CSting strText(_T("Some text from other class"));
oEjemplo.ShowText(strText);
}
|
|
|
|
|
ok, but..
Where I define strText?
And.. to show the text I need the method OnInitDialog in class CEjemplo, but if I add the parameter I need to pass the paramenter to this method and it isn't possible.
BOOL CEjemplo::OnInitDialog()
{
CDialogEx::OnInitDialog();
ShowText();
return TRUE;
}
|
|
|
|
|
So add a function to your dialog that manages the text, then you can call that function as different buttons are pressed. However, I would say that your design is not the best way of doing things in Windows.
|
|
|
|
|
I didnt understand you.
If you know a better way to do, let me know, please.
|
|
|
|
|
As I understand it you are changing the content of the dialog by pressing a button on the main form. This will not be a good experience for your users, as most people like to interact with one window at a time.
For example:
If the user presses a button on the main form and a dialog appears, all user action should now be with that dialog until the dialog is dismissed. If they have to go back to the main form to press a button to change something in the dialog then things get confused.
If my understanding of your system is incorrect I apologise for my confusion.
|
|
|
|
|
The idea is it dialog is used to show dates. The app will be a estadistic program, like SPSS, you will have a several variables and if you choose one of this and press a one button, in the dialog will be show the average, and if you after press other button, it will be added to the dialog the frecuency, for example.
Due to it, I'd like to get show diferent information from diferent class in the same dialog.
Please, help me.
|
|
|
|
|
Your original message states that this is an MDI application, so it would seem the obvious answer is to show your results in one of the MDI windows. Alternatively put all your selector buttons into the dialog and just use the button handlers to get the data from wherever it is held and display it in the dialog.
|
|
|
|
|
No, I cant.
This windows/dialog is only to show the result.
Now, I show each result in one dialog diferent, but I'd like to group all the result in one dialog, and after, I will make a button in this dialog to save the information in a txt for example.
But I must to do at this way
|
|
|
|
|
antonio343 wrote: No, I cant.
I have offered two suggestion which would make life easier for you, I cannot think of a third that would be better.
|
|
|
|
|
You never clarified whether you were using a modal or modeless dialog. I don't think your issue can be addressed until that is made clear.
"One man's wage rise is another man's price increase." - Harold Wilson
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
"Show me a community that obeys the Ten Commandments and I'll show you a less crowded prison system." - Anonymous
|
|
|
|