how to draw static text in a dialog

I creat a dilog and want to display some lines in the static text of
the dialog .
this is code:
CWnd *pWnd = (CWnd*)GetDlgItem(IDC_mystatictext);
CDC* pDC= CWnd::GetDC();
pDC->MoveTo(0, 0);
pDC->LineTo(600, 400);
but it just display in the dialog and cannot display in the static
text!

I just a newer one to study vc,thanks for yous help.

0
liuerbin2000
4/20/2006 1:29:17 PM
vc.mfc 33608 articles. 0 followers. Follow

10 Replies
1281 Views

Similar Articles

[PageSpeed] 32

You dont have to draw anything. Simply call SetWindowText on it:

 CWnd *pWnd = GetDlgItem(IDC_mystatictext);
ASSERT_VALID(pWnd);
pWnd->SetWindowText(_T("SomeText"));

---
Ajay

0
ajaykalra (6842)
4/20/2006 1:33:54 PM
liuerbin2000@163.com wrote:

> I creat a dilog and want to display some lines in the static text of
> the dialog .
> this is code:
> CWnd *pWnd = (CWnd*)GetDlgItem(IDC_mystatictext);
> CDC* pDC= CWnd::GetDC();
> pDC->MoveTo(0, 0);
> pDC->LineTo(600, 400);
> but it just display in the dialog and cannot display in the static
> text!
> 
> I just a newer one to study vc,thanks for yous help.
> 

liuerbin:

You did not use your pWnd! Try

CDC* pDC = pWnd->GetDC();

David Wilkinson

0
no-reply8010 (1791)
4/20/2006 1:37:18 PM
I think I read your post incorrectly. Looks like David has already
answered. I would all this in OnPaint of the static control.


---
Ajay

0
ajaykalra (6842)
4/20/2006 1:46:34 PM
I can swear that I read this same post yesterday.

You can't draw the lines in the static control from within the dialog.  It
will be erased the next time the static control gets a paint message.

You have to do this in the static controls paint message.

class CMyDialog : public CDialog
{
protected:
    CStaticWithLines m_StaticWithLines;
}

void CMyDialog::DoDataExchange(CDataExchange *pDX)
{
    DDX_Control(pDX,IDC_STATIC_WITH_LINES,m_StaticWithLines);
}


class CStaticWithLines : public CStatic
{
protected:
    afx_msg void OnPaint();
}

BEGIN_MESSAGE_MAP(CStaticWithLines, CStatic)
    ON_WM_PAINT()
END_MESSAGE_MAP()

void CStaticWithLines::OnPaint()
{
    CPaintDC dc(this);
    dc.MoveTo(...);
    dc.LineTo(...);
}

AliR.

<liuerbin2000@163.com> wrote in message
news:1145539757.923786.224350@t31g2000cwb.googlegroups.com...
> I creat a dilog and want to display some lines in the static text of
> the dialog .
> this is code:
> CWnd *pWnd = (CWnd*)GetDlgItem(IDC_mystatictext);
> CDC* pDC= CWnd::GetDC();
> pDC->MoveTo(0, 0);
> pDC->LineTo(600, 400);
> but it just display in the dialog and cannot display in the static
> text!
>
> I just a newer one to study vc,thanks for yous help.
>


0
AliR3470 (3236)
4/20/2006 5:14:49 PM
Thank you very much .
I get it ,and rewrite code like this :

             CPaintDC dc(this); // device context for painting

	//TODO: Add your message handler code here

	CStatic* pWnd = (CStatic*)GetDlgItem(IDC_my_static );
	CDC* pDC = pWnd->GetDC();

	CRect rc;
	pWnd->GetClientRect(&rc);
	CBrush brush;
	brush.CreateSolidBrush(RGB(255,255,255));
	pDC->FillRect(&rc,&brush);

	CRgn rgn;
	rgn.CreateRectRgn(rc.left,rc.top,rc.right,rc.bottom);
	pDC->SelectClipRgn(&rgn);

	CPen pen,*pOldPen;
	pen.CreatePen(PS_SOLID, 2, RGB(255,0,0));
	pOldPen =pDC->SelectObject(&pen);

	pDC->MoveTo(0,0);//
	pDC->LineTo(10,10);//

	pDC->SelectObject(pOldPen);
	pWnd->ReleaseDC(pDC);
		
so that ,I can draw line in the static text on the dialog .

0
liuerbin2000
4/21/2006 4:33:10 AM
And I have to say sorry to everyone ,my title "how to draw static text
in a dialog" should be "draw line(or other ) in the static text on the
dialog "

0
liuerbin2000
4/21/2006 4:39:15 AM
First, lose the GetDlgItem.  Create a control member variable to handle ti.

Lose the GetDC (I don't see its corresponding ReleaseDC anyway).  Use
	CClientDC dc(wnd);
if you need a dc.  In this case, however, you do NOT want to do ANY of this, because you
should not be drawing in a control except in that control's OnPaint handler.  Subclass
CStatic and do all your work in the OnPaint handler of the CStatic subclass, and scrap all
this code.  In this case, the OnPaint will already do a CPaintDC dc(this) and you will use
that CDC object.  

Since all of the code below is wrong, there's no reason to explain why it produces bad
results.  Bottom line: if you want to draw in a control, the OnPaint handler of the
control (with very few exceptions, of which this is not one) is the *only* place to do
drawing.  For owner-draw controls, the special DrawItem handler, which is morally
equivalent to OnPaint, will be called, but that's not one of the exceptions I mentioned
(doing rubber-band lines *is* one of the exceptions)
					joe

The MoveTo/LineTo are inappropriate and should be dumped
On 20 Apr 2006 06:29:17 -0700, "liuerbin2000@163.com" <liuerbin2000@163.com> wrote:

>I creat a dilog and want to display some lines in the static text of
>the dialog .
>this is code:
>CWnd *pWnd = (CWnd*)GetDlgItem(IDC_mystatictext);
>CDC* pDC= CWnd::GetDC();
>pDC->MoveTo(0, 0);
>pDC->LineTo(600, 400);
>but it just display in the dialog and cannot display in the static
>text!
>
>I just a newer one to study vc,thanks for yous help.
Joseph M. Newcomer [MVP]
email: newcomer@flounder.com
Web: http://www.flounder.com
MVP Tips: http://www.flounder.com/mvp_tips.htm
-- 
NewsGuy.Com 30Gb $9.95 Carry Forward and On Demand Bandwidth
0
newcomer (15975)
4/21/2006 5:20:07 AM
Wrong.  This code would be in your CStatic subclass, and therefore the GetDlgItem is
meaningless because it is trying to retrieve a CWnd * of a child window of the CStatic,
which makes no sense.  Get rid of a lot of the lines below...
On 20 Apr 2006 21:33:10 -0700, "liuerbin2000@163.com" <liuerbin2000@163.com> wrote:

>Thank you very much .
>I get it ,and rewrite code like this :
>
>             CPaintDC dc(this); // device context for painting
>
>	//TODO: Add your message handler code here
>
>	CStatic* pWnd = (CStatic*)GetDlgItem(IDC_my_static );
>	CDC* pDC = pWnd->GetDC();
****
These lines are nonsense.  Get rid of them.  You don't need a GetDC, you already HAVE a
DC, the CPaintDC
****
>
>	CRect rc;
>	pWnd->GetClientRect(&rc);
****
This code MUST be in the CStatic subclass, so get rid of the pwnd-> in all cases
*****
>	CBrush brush;
>	brush.CreateSolidBrush(RGB(255,255,255));
>	pDC->FillRect(&rc,&brush);
*****
Thise should be dc.FillRect.  And you can use FillSolidRect and eliminate the need to
create a brush
*****
>
>	CRgn rgn;
>	rgn.CreateRectRgn(rc.left,rc.top,rc.right,rc.bottom);
>	pDC->SelectClipRgn(&rgn);
****
You may need to set a clipping region, but unless your drawing is going to exceed the
possible CRect, this is unnecessary 
****
>
>	CPen pen,*pOldPen;
>	pen.CreatePen(PS_SOLID, 2, RGB(255,0,0));
>	pOldPen =pDC->SelectObject(&pen);
>
>	pDC->MoveTo(0,0);//
>	pDC->LineTo(10,10);//
>
>	pDC->SelectObject(pOldPen);
*****
Using SaveDC and RestoreDC will eliminate the need to keep selecting old pens back, see my
essay on this
****
>	pWnd->ReleaseDC(pDC);
****
Unnecessary.  The CPaintDC has a destructor, and you never needed to get the DC.  I think
you are still confused: This drawing code goes in the CStatic subclass, NOT the CDialog
subclass!  You don't care if the dialog surface needs to be redrawn; you only care if the
static control needs to be redrawn, and you can only handle this if you put this in the
OnPaint handler of your CStatic!
*****
>		
>so that ,I can draw line in the static text on the dialog .
Joseph M. Newcomer [MVP]
email: newcomer@flounder.com
Web: http://www.flounder.com
MVP Tips: http://www.flounder.com/mvp_tips.htm
-- 
NewsGuy.Com 30Gb $9.95 Carry Forward and On Demand Bandwidth
0
newcomer (15975)
4/21/2006 11:55:05 AM
See my previous answer.  If you are drawing a CStatic, you must do the drawing in the
CStatic!
				joe

On 20 Apr 2006 21:39:15 -0700, "liuerbin2000@163.com" <liuerbin2000@163.com> wrote:

>And I have to say sorry to everyone ,my title "how to draw static text
>in a dialog" should be "draw line(or other ) in the static text on the
>dialog "
Joseph M. Newcomer [MVP]
email: newcomer@flounder.com
Web: http://www.flounder.com
MVP Tips: http://www.flounder.com/mvp_tips.htm
-- 
NewsGuy.Com 30Gb $9.95 Carry Forward and On Demand Bandwidth
0
newcomer (15975)
4/21/2006 11:55:43 AM
Dont worry about it, although I was confused. As already pointed out,
you need to all painting in your static's OnPaint.

---
Ajay

0
ajaykalra (6842)
4/21/2006 1:59:15 PM
Reply:

Similar Artilces:

Shrinking Text
Hi everybody, in our Office (Word) 2007 application, WTS 2008x64, the following happens (for some - not all- users): A text is written and formatted normally and without any problems. The document shall be printed. After the printjob is executed, the chracters of the text lines are compressed to only a few millimeters in width. The font height remains normal. Nothing is legible. This now ocurs on the printed doc as well as on the screen. After the doc is saved and opened in a different session, everything is OK and works well... What can I do? As always, every help and ...

Finding characters within a text
Hi How to check, using single formula, that a text within a certain cell contains one of certain characters? For instance, how to check if there is a 'R', 'L' or 'Ps' character within cell A1 that reads 'W-RII'. Thanks in advance Hmm..not very elegant, but maybe =NOT(AND(ISERROR(FIND("R",A1)),ISERROR(FIND("L",A1)),ISERROR(FIND("P",A1)))) Returns TRUE if the text in A1 contains 'R', 'L' or 'Ps' . FIND is case-sensitive, use SEARCH if you also want to find lower-case characters. Cheers, Joerg Mochiku...

Text to columns
Once I use the Text to columns feature in Excel, it seems there is no way to turn it off. Anyone know if there is a way to reset this so that newly pasted text will not continue to get broken up (for example by the space delimiter) Presently the only way is to exit Excel and restart Excel - then pasted text all goes into one cell regardless of spaces. Hope I explained that well enough Al I may have been to hasty in making this assumption, it appears that the problem I described below is only happening on one workstation - this may indicate that the Excel Registry keys are in need of...

Text Effects Scrolling or Blinking text
How do apply the scroll or blinking feature to text that you want to emphasize in a word document. Prior to MS2007 there was a feature on the fonts tab that allowed a user to apply the following features to text "marching ants, blinking text, scrolling marquee, etc. I cannot find the any of these features anywhere in Word 2007. "HELP" There is no direct access to them, but they are still available by macro I posted the following macro recently, for use in Word 2007 Sub AnimateFont() Dim sAnimation As String If Len(Selection.Range) = 0 Then MsgBox "...

How can I clear the last Data->Text to columns to formatting
I've noticed in Excel 2000 that if I paste text into various worksheets within a workbook each paste will assume the Text->Column formatting that I applied in the previous. How can I prevent it from happening ? Thanks Steve Just run another data|Text to columns against a dummy cell. Specify delimited, but remove all the check marks from all the possible delimiters. (alternatively, you can close excel and reopen it.) svaardt wrote: > > I've noticed in Excel 2000 that if I paste text into various worksheets > within a workbook each paste will assume the Text->Col...

What is 'Align Text to Base Line Guide'?
Trying to make sure all lines have the same amount of space between them I selected paragraph from the format menu and under the line adjustments there is a box 'align text to base line guides' Ok I did that, now there are lines at the margines of my newsletter. What are these? Also selecting this pushed my text down from the top edge of the text box. What is this? The baseline guide measurements are in the Arrange, Layout Guides, Baseline tab. There is help in the Help menu. -- Mary Sauer http://msauer.mvps.org/ "Go_Girl3647" <GoGirl3647@discussions.microsoft.com...

How do text capture tools work?
Here are two examples of this technology. http://www.textcapture.com/en/default.html http://www.deskperience.com/textcapture/ Sounds like they will have to involve OCR, which works fine for standard fonts but probably won't work with fancy fonts. Key here is to test them try a static control with a TextOut and change the fonts and see what happens. joe On Wed, 31 Oct 2007 15:02:04 -0500, "Peter Olcott" <NoSpam@SeeScreen.com> wrote: >Here are two examples of this technology. > > http://www.textcapture.com/en/default.html > http://www.deskp...

Ordering by number and text
I use a report to print out checklists that in the detail section have item number to delineate each checklist item. The item numbers as an example are 1-1, 1-2, 1-2a, 1-2b, or 2-1, 2-2, 2-3, 2-3a, 2-3b and so on. The report is grouped by checklist section and the grouping works perfectly but when the report is printed the item numbers are ordered in this order 1-1, 1-10, 1-11, 1-2, 1-3, 1-3a, 1-3b, 1-4, 1-5, 1-6, 1-7, 1-9. Obviously I want the the order to be in proper numerical sequence where 1-10 comes after 1-9. but even replacing the '-' with a decimal point doesn't ...

New Static IP
SBS2003R2 We'll be moving our office this coming weekend. We will be getting a new static IP from our ISP (I tried to get them to let us keep our existing one but they said that would take "an act of God"). Our mail is delivered to our server after being filtered for spam by McAfee. Our server is configured to only allow mail from McAfee's range of IP address and an internal IP for a "scan to email" device. In an effort to make this move as smooth as possible I'll be calling McAfee in advance of this move and setting up a "ticket number"...

Spiral text
Does anyone know how to create spiral text? In a draw program for sure. You probably can get close in Publisher, but it will not look as good as a draw program can do. Serif has a free program you can try. DrawPlus http://www.freeserifsoftware.com/ -- Mary Sauer MSFT MVP http://office.microsoft.com/ http://msauer.mvps.org/ news://msnews.microsoft.com "jaykay" <jaykay@discussions.microsoft.com> wrote in message news:71954A65-C46F-4005-9553-B324EFEE7500@microsoft.com... > Does anyone know how to create spiral text? I've downloaded the program, but can't figur...

Email Text Dissappears when Save
When we save email messages (as a draft) the text dissappears, even when th I use my administrator account. Anybody have any idea what that is happening. ...

obtaining data in text form from a table
Hi all, I like to be able to obtain the dates in a text format from the table below. ie Test2 8-Feb Test5 4-Feb,8-Feb Test6 4-Feb,5-Feb, 9-Feb Do I need to do this by macros and if so, any help would be appreciated. Table Care Recipient Surname 4-Feb 5-Feb 8-Feb 9-Feb Test1 Test2 8-Feb Test3 Test4 Test5 4-Feb 8-Feb Test6 4-Feb 5-Feb 9-Feb Vlookup should do what you want, as in: =vlookup(a2,Table,2,false) Adjust the ranges t...

drawing on the desktop
Hi, When you drag the Visual Studio property window , it will draw on the screen a rectangle with the mouse showing the new position of the property window if you drop it right now. I want to know how this is implemented? Do I need to get the DC of the desktop to do the drawing?? Thank you, wk ...

Count the text in a column
I would like to count the text in a column then for it to add a figure in another cell if it meets the text criteria Thanks! Do you mean count the characters? If so =SUM(NOT(ISNUMBER(A1:A20))*LEN(A1:A20)) as an array formula (committed with Ctrl-Shift-Enter) -- HTH RP (remove nothere from the email address if mailing direct) "Peter Curtis" <PeterCurtis@discussions.microsoft.com> wrote in message news:94C093C4-38DC-4989-846A-9352F3298B7C@microsoft.com... > I would like to count the text in a column then for it to add a figure in > another cell if it meets the t...

Converting number to text
Is it possible to convert, say 1234 to one thousand two hundred and thirty four Thanks There is no direct functions to convert this. For a VBA solution check out the below links http://www.ozgrid.com/VBA/ValueToWords.htm http://support.microsoft.com/kb/213360 http://www.xldynamic.com/source/xld.xlFAQ0004.html -- Jacob (MVP - Excel) "booshi" wrote: > Is it possible to convert, say 1234 to one thousand two hundred and thirty > four > > > Thanks > > > . > ...

Printing drawings
Visio 2007 Professsional ... Have succesfully reverse engineered a SQL Server DB selecting tables. Select tables and PK, however drawing created has all columns included. Is there a way to suppress the columns so only the tables are revealed? Thanks, Jim Yes with Visio for enterprise architect version "Jim Peterson" <JimPeterson@discussions.microsoft.com> a écrit dans le message de news:1232D9FA-E60A-4BD1-AF91-A6EA688A1819@microsoft.com... > Visio 2007 Professsional ... > > Have succesfully reverse engineered a SQL Server DB selecting tables. > Select t...

Setting Text in a ComboBox
Hi, Does anybody know why I cannot set the text in the edit control of a CBS_DROPDOWN style CombBox control using SetWindowText()? I was able to change the text in the edit control part of the ComboBox manually. Thanks, Vincent. I don't know why can't you? Post some code. You should be able to m_MyCombo.SetWindowText("The Text"); Ali R. "Vincent Yu" <anonymous@discussions.microsoft.com> wrote in message news:5e2b01c3ad48$5309d630$a601280a@phx.gbl... > Hi, Does anybody know why I cannot set the text in the > edit control of a CBS_DROPDOWN style ...

Learning MFC
Hi Trying to learn MFC with VC++ 6.0 and I want to draw a simple game board. All I want is a 9 by 9 grid for the Suduko game. Each grid element should be able to hold a few characters. Would appreciate some ideas on how to create the grid using the dialogue creation parts of Visual Studio. Or, do I have to draw it at run time in which case, again, how do I do it? After drawing the grid will need to be able to do operations such as: ** write {text} to cell at {column} and {row} ** user has entered {digit} at {column} and {row} Have spent some time reading the MS VS help pages but I have not ...

anchor picture to text box
(Publisher 2003) I have a newsletter with a Kudos box. In the corners of the box I have a happy face. I'd like the happy faces to be anchored to their corners so when I enlarge or shorten the box, the faces move along with the text box. Why not create a rectangle, insert the happy faces, group. The problem as I see it would be if you resize, the happy faces could be distorted if you widen or shrink the group. You would always have to re-size proportionally. -- Mary Sauer http://msauer.mvps.org/ "Helen" <Helen@discussions.microsoft.com> wrote in message news:193...

Creating Dialog Pointer with new, causes Exception
Hello all, I've written an MFC app, which has a tabbed interface. When it starts up, it checks my registry key, to determine how many tabs it needs, it then creates each tab, and puts a custom non modal, child dialog on each tab. The problem is, in release mode, it can only create the first dialog, the second one causes a memory exception. It *looks* like MFC doesnt like me trying to initialize a pointer like so, when that pointer is NULL. m_pDialogs[i] = new CMyDialog; Thing is, isn't that the whole point of the new operator? And malloc for that matter? The only difference, th...

Text Ticker
Hello Experts i was asked to do a simple project 1-want do a text ticker can be scroll left to right and right to left 2-transparent 3-no flicker 4-has a background image please where can i start and how to do it thank you BitBlt background to offscreen bitmap TextOut to the bitmap with appropriate offset and clipping region BitBlt offscreen bitmap to client area of screen Use a subclassed CStatic joe On 18 Aug 2006 20:59:22 -0700, "Prafulla T" <prafulla.tekawade@gmail.com> wrote: >Hello Experts > >i was asked to do a simple project >1-want do a text tic...

text box email publication
I am a publisher novice. I am trying to develop an e-mail newletter. The templates in publisher have a text box under each article with what appears to be a hyperlink with "more details". I assume this will enable the reader of the email to expand the text box and see the full details of the article. I like this feature as it means that readers only get to see the title and abstract and then can select the articles they want to read in full. Unfortunately I can not work out how to use this function and as usual help is no help. Tim no such feature in Publisher. "kiwi ti...

Transform fixed length text to xml
can i transform fixed length text to xml using XSL do i have to first load the text to xml and do the transformation? is there any other way to do it? ...

Finding text within text
Hello again, I've gotten the formula for finding occurrences of a word in one column based on whether it's in another column; now what I need is to find out whether a word in column A (for instance) appears in a string of text in column B. As in, a SKU in A, and a description in B, with the descriptions having several SKUs in each one. I need to be able to delete from a sheet any description that doesn't have the SKUs I'm looking for, and it would be really nice to color the corresponding cells the same, but even having the row number in the third row would be nice. Say I...

Blocking e-mail based on message text.
Hi! I've got a question concerning e-mail blocking. I'm using Exchange 2003 and TrendMicro MailScan for antivirus. Antivirus removes infected attachment, but lets the letter pass through. There's no "remove e-mail function", so the users have been complaining about those particular letters, saying "Your account has been blocked". Is there a way to configure Exchange to delete e-mail based on the subject (e-mail text)? I know that you can block it in outlook, but that's the last resort. Thank you. "Igors Belijs" <IgorsBelijs@discussions.mi...