child window drawing extends onto dialog

This has got to be something obvious.

I've subclassed a static control on my dialog with a CWnd-derived class, 
call it CMyControl.  Here's how the control is declared in the rc file:

LTEXT  "Static",IDC_STATIC_GRAPH,7,5,240,149

In CMyControl::OnPaint() I do some drawing using CPaintDC::SetPixel(). 
That works fine.  However, if the drawing extends beyond the bounds of 
CMyControl's client rectangle (which sometimes happens -- it's data 
being read from a machine-control device), I would like it to not be 
visible.  Instead, it's being drawn onto the parent dialog's background. 
  Do I need to clip the data to CMyControl's rectangle myself, or is 
there some style I'm missing that will do it for me?  Why, if I'm 
drawing to CMyControl's DC, am I seeing drawing on the dialog?

Much thanks,
JJ
0
menelaus (13)
4/11/2008 5:45:31 PM
vc.mfc 33608 articles. 0 followers. Follow

5 Replies
694 Views

Similar Articles

[PageSpeed] 36

You can specfiy a clip region:

void CMyCtrl::OnPaint()
{
   CPaintDC dc(this);

   CRect rect;
   GetClientRect(&rect);

   CRgn Rgn;
   CRgn *pOldRgn = 
Rgn.CreateRectRgn(rect.left,rect.top,rect.right,rect.bottom);
   dc.SelectClipRgn(&Rgn,RGN_COPY);

   //do drawing here

   dc.SelectObject(pOldRgn);
}


AliR.


"King Menelaus" <menelaus@olympus.net> wrote in message 
news:SZCdnZzO0sUjPmLanZ2dnUVZ_vGinZ2d@scnresearch.com...
> This has got to be something obvious.
>
> I've subclassed a static control on my dialog with a CWnd-derived class, 
> call it CMyControl.  Here's how the control is declared in the rc file:
>
> LTEXT  "Static",IDC_STATIC_GRAPH,7,5,240,149
>
> In CMyControl::OnPaint() I do some drawing using CPaintDC::SetPixel(). 
> That works fine.  However, if the drawing extends beyond the bounds of 
> CMyControl's client rectangle (which sometimes happens -- it's data being 
> read from a machine-control device), I would like it to not be visible. 
> Instead, it's being drawn onto the parent dialog's background. Do I need 
> to clip the data to CMyControl's rectangle myself, or is there some style 
> I'm missing that will do it for me?  Why, if I'm drawing to CMyControl's 
> DC, am I seeing drawing on the dialog?
>
> Much thanks,
> JJ 


0
AliR3470 (3236)
4/11/2008 6:54:12 PM
Works beautifully.  Thanks!

AliR (VC++ MVP) wrote:
> You can specfiy a clip region:
> 
> void CMyCtrl::OnPaint()
> {
>    CPaintDC dc(this);
> 
>    CRect rect;
>    GetClientRect(&rect);
> 
>    CRgn Rgn;
>    CRgn *pOldRgn = 
> Rgn.CreateRectRgn(rect.left,rect.top,rect.right,rect.bottom);
>    dc.SelectClipRgn(&Rgn,RGN_COPY);
> 
>    //do drawing here
> 
>    dc.SelectObject(pOldRgn);
> }
 >
>> This has got to be something obvious.
>>
>> I've subclassed a static control on my dialog with a CWnd-derived class, 
>> call it CMyControl.  Here's how the control is declared in the rc file:
>>
>> LTEXT  "Static",IDC_STATIC_GRAPH,7,5,240,149
>>
>> In CMyControl::OnPaint() I do some drawing using CPaintDC::SetPixel(). 
>> That works fine.  However, if the drawing extends beyond the bounds of 
>> CMyControl's client rectangle (which sometimes happens -- it's data being 
>> read from a machine-control device), I would like it to not be visible. 
>> Instead, it's being drawn onto the parent dialog's background. Do I need 
>> to clip the data to CMyControl's rectangle myself, or is there some style 
>> I'm missing that will do it for me?  Why, if I'm drawing to CMyControl's 
>> DC, am I seeing drawing on the dialog?
0
menelaus1 (17)
4/11/2008 7:12:32 PM
Just an add-on.  The reason this behaves this was was that in Windows 1.0, the controls
were declared with CS_PARENTDC, which meant that the clipping region of the control was
the clipping region of the parent.  Why?  I have no idea; it probably saved two
instructions on the 8088.  I believe this design defect was finally fixed in Vista.  But
the solution given is the one we have to use for < Vista.
					joe

On Fri, 11 Apr 2008 10:45:31 -0700, King Menelaus <menelaus@olympus.net> wrote:

>This has got to be something obvious.
>
>I've subclassed a static control on my dialog with a CWnd-derived class, 
>call it CMyControl.  Here's how the control is declared in the rc file:
>
>LTEXT  "Static",IDC_STATIC_GRAPH,7,5,240,149
>
>In CMyControl::OnPaint() I do some drawing using CPaintDC::SetPixel(). 
>That works fine.  However, if the drawing extends beyond the bounds of 
>CMyControl's client rectangle (which sometimes happens -- it's data 
>being read from a machine-control device), I would like it to not be 
>visible.  Instead, it's being drawn onto the parent dialog's background. 
>  Do I need to clip the data to CMyControl's rectangle myself, or is 
>there some style I'm missing that will do it for me?  Why, if I'm 
>drawing to CMyControl's DC, am I seeing drawing on the dialog?
>
>Much thanks,
>JJ
Joseph M. Newcomer [MVP]
email: newcomer@flounder.com
Web: http://www.flounder.com
MVP Tips: http://www.flounder.com/mvp_tips.htm
0
newcomer (15975)
4/11/2008 7:19:58 PM
"Joseph M. Newcomer" <newcomer@flounder.com> wrote in message 
news:gcevv397mii85ai484f7ess21nq4tpgtf0@4ax.com...
> Just an add-on.  The reason this behaves this was was that in Windows 1.0, 
> the controls
> were declared with CS_PARENTDC, which meant that the clipping region of 
> the control was
> the clipping region of the parent.  Why?  I have no idea; it probably 
> saved two
> instructions on the 8088.  I believe this design defect was finally fixed 
> in Vista.  But
> the solution given is the one we have to use for < Vista.

Isn't setting the CS_CLIPCHILDREN style of the dialog (I believe this can be 
done in the Resource Editor?) also a solution?

-- David 


0
dc2983 (3206)
4/12/2008 3:02:37 PM
No.  That serves a different purpose; it means that the background will be clipped by the
children and they will clip each other, but it doesn't solve the CS_PARENTDC problem at
all.
				joe

On Sat, 12 Apr 2008 15:02:37 GMT, "David Ching" <dc@remove-this.dcsoft.com> wrote:

>"Joseph M. Newcomer" <newcomer@flounder.com> wrote in message 
>news:gcevv397mii85ai484f7ess21nq4tpgtf0@4ax.com...
>> Just an add-on.  The reason this behaves this was was that in Windows 1.0, 
>> the controls
>> were declared with CS_PARENTDC, which meant that the clipping region of 
>> the control was
>> the clipping region of the parent.  Why?  I have no idea; it probably 
>> saved two
>> instructions on the 8088.  I believe this design defect was finally fixed 
>> in Vista.  But
>> the solution given is the one we have to use for < Vista.
>
>Isn't setting the CS_CLIPCHILDREN style of the dialog (I believe this can be 
>done in the Resource Editor?) also a solution?
>
>-- David 
>
Joseph M. Newcomer [MVP]
email: newcomer@flounder.com
Web: http://www.flounder.com
MVP Tips: http://www.flounder.com/mvp_tips.htm
0
newcomer (15975)
4/12/2008 10:11:57 PM
Reply:

Similar Artilces:

Chasing Windows
Would anyone know of a way to keep new pages from stealing the active page upon opening? It is terriably frustrating to have to keep chasing the active page as new pages open. I'm running XP on an ACER and our systems tend to be slow because of our hardware combinations. It is not unsual for me to be working in one docu and decide I need info from another docu or docus or web site, go start those pages opening and go back to my active page, all without loosing my train of thought - until the other pages finally start opening and stealing my active page. After I have chased my...

Windows XP Inbox Delay
Ever since we went to Windows XP Professional we have a problem with new mail notifications in Outlook. It happens with both Office 2000 and Office XP. I takes a long time for new mail to show up in the inbox. As soon as you leave the inbox (i.e. go to contacts) the new mail will show up. Any ideas? >-----Original Message----- >Ever since we went to Windows XP Professional we have a >problem with new mail notifications in Outlook. It happens >with both Office 2000 and Office XP. I takes a long time >for new mail to show up in the inbox. As soon as you leave >the ...

windows live mail
unable to get spelling check to cjeck emails before they are sent. Is the spelling being checked as you type? Alt + T, Options, Spelling, ..... -- Ron Sommer MS MVP-Mail "Paul Baxter" <Paul Baxter@discussions.microsoft.com> wrote in message news:40856CC5-4157-41C7-8FCD-63088A1543C0@microsoft.com... > unable to get spelling check to cjeck emails before they are sent. On Tue, 29 Dec 2009 17:01:01 -0800, Paul Baxter <Paul Baxter@discussions.microsoft.com> wrote: >unable to get spelling check to cjeck emails before they are sent. You don't...

Electrical drawings
How to get a auto jummber while crossing a line in electrical circuitdiagram On Fri, 23 May 2008 04:01:00 -0700, siva <siva@discussions.microsoft.com> wrote: >How to get a auto jummber while crossing a line in electrical circuitdiagram menu File -> Page Setup -> Layout and Routing in the Line Jumps section -- Regards, Paul Herber, Sandrila Ltd. Electrical for Visio http://www.electrical.sandrila.co.uk/ You are not the first to have problems with it. Beware for example that it works only with connectors and not with lines. "siva" wrote: > How to ...

move a primary key to a child
I want to add a child table to my table and using one of the primary key of the table. For example: MyTable is PKey1 PKey2 PKey3 I would like to move PKey3 out and add a child table as following and remove PKey3 from MyTable: ChildTable as folliwng PKey1 PKey2 PKey3 MyTable will be PKey1 PKey2 I just wonder what will impact in the future like reports, forms, queries, data entries, It seems that I need make a lot of changes for the application. Any suggestions that should I continue to do this change? Your information is great appreciated, I'm not...

Changing window size/location for child process w/.Net
I'd like to start a process and then change the window location and size at various times during its life in a .Net (sans user32.dll). I can get the window handle easy enough but I don't know what to do next to replace the GetWindowRect and MoveWindow DllImports. mediaPlayer.FileName = "mplayer"; mediaPlayer.Start(); mediaPlayer.WaitForInputIdle(); IntPtr hWin = mediaPlayer.MainWindowHandle; GetWindowRect(hWin, out rect); // <- what is ..Net equivalent? MoveWindow(hWin, left, top, width, height, true); // <- what is...

hidden window?
Can't find outlook express and can not open it. I think it is already open and is hidden some place. any help would be appreciated. Ken >Can't find outlook express and can not open it. Start>[All] Programs>Outlook Express usually works. The program itself is "C:\Program Files\Outlook Express\msimn.exe" Please ask Outlook Express in a newsgroup targeted to Outlook Express. This one isn't. -- Brian Tillman Smiths Aerospace 3290 Patterson Ave. SE, MS 1B3 Grand Rapids, MI 49512-1991 Brian.Tillman is the name, smiths-aerospace.com is the domain. I don't ...

Windows ME and Pop3 server error
I am using Windows ME on a laptop computer with Office XP Professional and Outlook 2002. I am setting up internet mail on a POP3 isp and whne running the configuration menu and hit test account settings, everything completes successfully. I finish the configuration and open Outlook and get send/receive errors (mail server cannot be contacted). Anyone have any ideas why this occurs? Could you give us the exact text of the error messages? -- Jeff Stephenson Outlook Development This posting is provided "AS IS" with no warranties, and confers no rights "Rick" <...

Windows 7 doesn't report errors as well as 2003!
I tried a simple loop as another way to get the SAM names on Windows 7 (since DSGET didn't seem to work) for /f "tokens=1,2,* delims==," %A in ('dsquery computer dc=company,dc=com) do @echo %B .... on windows 7, nothing happened. .... on windows 2003, I got an error that "company" was not a known command. So in both cases, I used: for /f "tokens=1,2,* delims==," %A in ('dsquery computer dc^=company^,dc^=com) do @echo %B ....and it worked fine on both OS's. Thing that puzzles me is that 2003 at least told me what the problem...

Publisher 2002 Windows Installer Update
"Brian Kvalheim - [MS MVP]" <publisher@mvps.org> wrote in message news:OupmQBwHEHA.2260@TK2MSFTNGP09.phx.gbl... > In news:1079c4f7q07qvb3@corp.supernews.com, > HooDoo <hoodoo67spambuffer@hotmail.com> posted: > Try doing a custom installation of Publisher 2002 and choosing to Run All > From My Computer, leaving all options checked (except for the Office > Assistant, unless you want it). This is assuming that you are seeing a > Publisher 2002 dialog install box. Otherwise, do the same thing using your > Office 2000 cd, by doing a custom install, choosin...

Add windows Common Dialogs
Hello Is there any way to add Windows common dialogs in MFC Dialogs (like add button in Dialogs)? Thanks R.Selvam selvamselvam@hotmail.com Take a look here. http://www.codeguru.com/dialog/index.shtml Scroll down to the middle of the page under the heading Common Dialogs Ali R. "R.Selvam" <selvamselvam@hotmail.com> wrote in message news:07dd01c3c8a9$dea2b820$a601280a@phx.gbl... > Hello > > Is there any way to add Windows common dialogs in MFC > Dialogs (like add button in Dialogs)? > > Thanks > R.Selvam > selvamselvam@hotmail.com > > ...

Windows 7 Icon Issue
First, I can't find ANY Windows 7 newsgroups. Where should I be looking? Anyway, I have some very old (1993) Windows 3.x programs that I installed under Windows 7 [32-bit]. [In fact, they are the ancient "Microsoft Arcade" games ... Battlezone, Missile Command, Pole Position, etc.] And they run ok. BUT .... in the start menu, the icons for the games are blank, or perhaps more correctly stated, generic. And if I right-click and choose "change icon" it tells me that the .exe file has no icon. Now I have these same games installed on this same comp...

How to make printed name badges in Windows?
Trying to make a custom name badge with photo and pic for reunion. Can anyone help? See http://www.gmayor.com/graphics_on_labels.htm and/or http://www.gmayor.com/mail_merge_graphics.htm -- <>>< ><<> ><<> <>>< ><<> <>>< <>><<> Graham Mayor - Word MVP My web site www.gmayor.com Word MVP web site http://word.mvps.org <>>< ><<> ><<> <>>< ><<> <>>< <>><<> "Picesdreamer" <Picesdreamer@...

"Windows Mail can compact the message store"
From past threads, I understand it is advisable to click "ok" when this message pops up. My follow-up question is this: What happens to my emails when the message store is compacted? Will my emails be lost permanently? Thanks. It should not affect your emails at all. Nevertheless, it is always wise to have a backup of your important = emails. --=20 Gary VanderMolen, Microsoft MVP (Mail) http://mvp.support.microsoft.com/default.aspx/profile/vandermolen "Will" <Will@discussions.microsoft.com> wrote in message = news:7C3B694D-60C8-40AA-B554-6ADE39A426...

Can't restore data from Money 2003 lost after installing Windows X
I installed Windows XP on my 89 SE operationg system and when I went to my MOney program all the data from the whole year was lost. How can I restore the data I have backed up on my floppy drive????? Tough to say as from the description you've given us, it's tough to say what happened. Was your backup good? Did you test it before reloading your operating system? Was your backup current? Are your view settings correct? You say you lost data from the whole year. What year? What about the rest of your data? What kind of backup was it? Money backup? File copy? Are you sure you use...

Custom Draw SliderCtrl
Dear all, I'm just trying to implement Slider control as Custom Draw one.In that Selection style is enabled and I just want to fill the color in selected channel and thumbRect( both horizontal and vertical orientation ).Can u tell me How to achieve this Regards, Babu ...

How to bypass certreq renew window in VBS script?
To renew a cert, we use certreq to generate a requst file from an inf file as following: certreq.exe -f -new ./pkcs7.inf ./123.req The cert to be renewed is specifed with its thumbprint in the pkcs7.inf file, so in fact the command will only renew it. But when running the command, a "Certificate List" window will popup with a list cotaining only that cert, and ask user to "Select certificate to be renewed". The window break the running process and require user to do a click action... In our project, we will call the command line in an VBS script and should ru...

Error in windows help and ON_WM_DEVICECHANGE() macro?
Hi there, I just noticed an inconsistency in the Windows SDK help for the ON_WM_DEVICECHANGE() macro. The help declares the function prototype with an void return type. My compiler ( VC 7.1 ) shows an error since it cannot cast the function pointer to a pointer with an return type of BOOL. If I change the return type to BOOL everything is fine. Is that a known error, because I couldn't find that using google. afx_msg void OnDeviceChange( UINT , DWORD ); ---> afx_msg BOOL OnDeviceChange( UINT , DWORD ); Thanks, Christian >Hi there, I just noticed an inconsistency in the Windo...

Combining Two Seperate Companies Window's Infrastructure
My company just did an acquisition and we are in a process of Integrating our networks. For discussion sake lets call Company A & Company B. For now, Company A has windows 2003 environment. It's in native mode. We have one forest for Company A which has an empty root domain. We have two child domains in this forest. One child domain is for corporate office network and other is for Our production network. We do have users and service accounts in both Domains and a two way trust relationship is built between both domains. We have a Exchange server 2003 (with Sp1) in corporate network d...

Start-parameter compose-window
Hi, I'm trying To create a batch file to start only the WLM compose-window in from folder "sendto". I'd like to add an attachment (or more) directly from the Windows directory. I don't want to set WLM as standard. The batchfile should be like this: if %1. == . exit set PARAMS=file:///%1 :loop shift if %1. == . goto send set PARAMS=%PARAMS%,file:///%1 goto loop :send start thunderbird.exe -compose attachment='%PARAMS%' thx Bernd Pietsch ...

show window content while dragging
why does this setting always change by its self xp dim 3000 old machine ie8 it changes to the dotted line. easy enough to fix but I would like to know why? David wrote: > why does this setting always change by its self xp dim 3000 old machine ie8 > it changes to the dotted line. easy enough to fix but I would like to know > why? Sounds like the graphics card and/or drivers are not up to it. Check you have the latest Dell(or card manufactures)drivers installed ...

window views
How do I combine several Excel panes in one window so I have only one Excel icon on my task bar? Tools-->Options-->General Uncheck the 'windows in taskbar' box. "coheri" wrote: > How do I combine several Excel panes in one window so I have only one Excel > icon on my task bar? ...

Dynamic dialogs (from newbie)
Hi all, I'm new to this group and my question could seem basic: I'd like to create in VC++ (6.0) some dynamic dialog boxes, something like "properties pages", with different controls depending on the object selected: is there a way to implement a dynamic definition (for example if an object has 3 properties, then my dialog should contain 3 static text and 3 edit text controls). I searched on the web and on some books but I didn't find much. I know I can design different dialogs in many different ways (even overlapping them on an empty dialog) but it is not what I'm ...

Query won't let me update child record ??
I have two related tables... parent & child I create a query with a couple of fields from each table and run the query Can't update any of the fields ?? If I do the query with just one of the two tables I can update fine. I thonght I had done this before... What am I doing wrong? thanks for any help. Hi Will, See this listing of possibilities: Why is my query read-only? http://allenbrowne.com/ser-61.html Tom Wickerath Microsoft Access MVP https://mvp.support.microsoft.com/profile/Tom http://www.access.qbuilt.com/html/expert_contributors.html ____________________...

set up windows mail
How do I set up Windows Vista mail? Windows Mail: Setting up an account from start to finish http://windows.microsoft.com/en-US/windows-vista/Windows-Mail-setting-up-an-account-from-start-to-finish Contact your ISP or visit their Website for the correct settings. -- Bruce Hagen MS-MVP [Mail] Imperial Beach, CA "Kenia Miller" <roberta3@embarqmail.com> wrote in message news:%23nRrqRfILHA.1868@TK2MSFTNGP05.phx.gbl... > > How do I set up Windows Vista mail? "Kenia Miller" <roberta3@embarqmail.com> wrote in ...