Quick Question!

Hi All, I have a Dialog based MFC app, I want to draw something on the
dialog, so How do I call an OnDraw method here?

TIA


0
nospam7635 (44)
5/13/2004 5:40:01 PM
vc.mfc 33608 articles. 0 followers. Follow

13 Replies
895 Views

Similar Articles

[PageSpeed] 38

Vai2000 wrote:

> Hi All, I have a Dialog based MFC app, I want to draw something on the
> dialog, so How do I call an OnDraw method here?
> 
> TIA
> 
> 

The dialog receives WM_PAINT.  A better and safer way is to put a 
CStatic control (picture control) on your dialog template, then derive a 
class from CStatic.  Create a control member variable (use class wizard) 
of your class in the dialog.  Paint in your CStatic WM_PAINT message 
handler.

-- 
Scott McPhillips [VC++ MVP]

0
scottmcp8856 (490)
5/13/2004 7:50:56 PM
Very simple: you don't. Put a static control on the dialog, create a subclass of CStatic,
and put an OnPaint handler in it (OnDraw applies only to views). Then do your drawing in
the OnPaint handler.
					joe

On Thu, 13 May 2004 13:40:01 -0400, "Vai2000" <nospam@microsoft.com> wrote:

>Hi All, I have a Dialog based MFC app, I want to draw something on the
>dialog, so How do I call an OnDraw method here?
>
>TIA
>

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)
5/14/2004 12:29:55 AM
Scott -

   Why is it better and safer

One reason I can think of for better is then you have a class you can toss around from app to app.  I can't figure out the safer part.  Joe N. and Jeff P. were discussing this in a thread I posted.  I'm still trying to get it straight.  I have had really nice results in a dialog where I painted right on it.  I would check for key strokes in PreTranslateMessage, call Invalidate(FALSE), call UpdateWindow(), and do screen updating in the dialog's OnPaint.  I would also not call the default CDialog::OnPaint.  It seems to work like a charm.  
0
anonymous (74722)
5/14/2004 12:21:04 PM
Well, many reasons. I consider this an abuse of PreTranslateMessage. Calling
Invalidate(FALSE) seems to be overkill; you should invalidate only the area you need to
repaint.

As I pointed out, I've seen a lot of problems with this approach. There seems to be no
compelling argument in its favor, and the number of problems I've seen is fairly large.
				joe

On Fri, 14 May 2004 05:21:04 -0700, "Yasoo" <anonymous@discussions.microsoft.com> wrote:

>Scott - 
>
>   Why is it better and safer?
>
>One reason I can think of for better is then you have a class you can toss around from app to app.  I can't figure out the safer part.  Joe N. and Jeff P. were discussing this in a thread I posted.  I'm still trying to get it straight.  I have had really nice results in a dialog where I painted right on it.  I would check for key strokes in PreTranslateMessage, call Invalidate(FALSE), call UpdateWindow(), and do screen updating in the dialog's OnPaint.  I would also not call the default CDialog::OnPaint.  It seems to work like a charm.  

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)
5/14/2004 4:03:48 PM
"Joseph M. Newcomer" <newcomer@flounder.com> wrote in message
news:pbr9a017n1djv2et75s6l4mdam7db2sht6@4ax.com...
> As I pointed out, I've seen a lot of problems with this approach. There
seems to be no
> compelling argument in its favor, and the number of problems I've seen is
fairly large.

Not sure  how compelling it is, but a window should be expected to render
its background in response to WM_ERASEBKGND. If a dialog renders a custom
background, then it needs to conform to this reasonable expectation. I'd go
so far as to say that a window that does not do this is broken by design.
Once people start exploring dialogs with say bitmap backgrounds, they then
start exploring transparent controls -- the only reliable way I've found to
achieve this is to capture the dialog background into a memory bitmap passed
in a memory dc with a WM_ERASEBKGND to its parent, and then BitBlt your
portion in response to your own WM_ERASEBKGND.

-- 
Jeff Partch [VC++ MVP]


0
jeffp (1711)
5/14/2004 5:07:34 PM
Invalidate(FALSE) - I'm invalidating the entire window because I'm repainting in the entire window (it's a text grid).  So it's not overkill, it's what's called for.  FALSE is used to keep from repainting the background so it won't flash at the user.
0
anonymous (74722)
5/14/2004 7:26:06 PM
I've used this technique before and it works great.  The only difference is I've not responded to WM_ERASEBKGND.  I Invalidate(FALSE) (or InvalidateRect(&r,FALSE)) and call UpdateWindow().  It ignores painting the background and I just BitBlt and/or DrawText to the dc.  It seems to work fine.
0
anonymous (74722)
5/14/2004 7:26:06 PM
Fancy backgrounds and WM_ERASEBKGND are one of the few reasons that drawing should even be
attempted on a dialog. And the number of times I've seen this have problems is
substantial. One client contracted for a "fancy" dialog background bitmap, in 256-colors
of pastels, at 640x480. The design called for a maximized display of the program, so it
filled the entire screen.

The first time they tried it on a 16-color 800x600 laptop (yes, they really existed. I had
one) it was a complete disaster (it was coincidence that I had the exact same model laptop
as their best customer). The colors were unbelievably ugly, and it couldn't be made
full-screen. Well, the dialog went full-screen but the bitmap remained at 640x480 (no
surprise). And when it was (my first attempt was StretchBlt) then it was even worse (not
that I expected StretchBlt to do well, but they wanted to see what it would look like)

But in using StretchBlt, I found that not only was the program painting on the dialog, but
the labels for the controls were part of the bitmap, and the controls had to be placed by
absolute pixel coordinates so they were in the right place! The entire display was riddled
with hardwired coordinates!

Someone had never heard about DBUs, and had not realized that dialogs resize based on
resolution, screen size, and the mood of the driver.

They had a LOT of complaints from customers. I solved the problem by ditching the bitmap
entirely. We used a "pretty" bitmap (their corporate logo, tiled), had a 16-color version,
and I put all the controls up in the usual fashion. No, on a 640x480x256 display it wasn't
as cute as their original one, but it worked on every platform, at every resolution, at
every color depth, with every driver. Somehow, the original author had neglected to take
reality into account.

That was possibly the single worst experience I had with painting directly on the dialog.
It was one of those "if there are two ways to do anything, the right way and the
incredibly wrong way, always choose the latter." It took me a month to redo the interface
and add all the features they wanted (actually, to get all the CONTROLS in for the
features they wanted, never mind the code behind the controls).My mistake was not
scrapping the entire dialog and starting over from scratch. 
				joe

On Fri, 14 May 2004 12:07:34 -0500, "Jeff Partch" <jeffp@mvps.org> wrote:

>"Joseph M. Newcomer" <newcomer@flounder.com> wrote in message
>news:pbr9a017n1djv2et75s6l4mdam7db2sht6@4ax.com...
>> As I pointed out, I've seen a lot of problems with this approach. There
>seems to be no
>> compelling argument in its favor, and the number of problems I've seen is
>fairly large.
>
>Not sure  how compelling it is, but a window should be expected to render
>its background in response to WM_ERASEBKGND. If a dialog renders a custom
>background, then it needs to conform to this reasonable expectation. I'd go
>so far as to say that a window that does not do this is broken by design.
>Once people start exploring dialogs with say bitmap backgrounds, they then
>start exploring transparent controls -- the only reliable way I've found to
>achieve this is to capture the dialog background into a memory bitmap passed
>in a memory dc with a WM_ERASEBKGND to its parent, and then BitBlt your
>portion in response to your own WM_ERASEBKGND.

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)
5/14/2004 7:27:39 PM
Joe -

   I forgot to ask.  Why do you think this is an abuse of PreTranslateMessage?  You mentioned something about this in a previous post.  How else do you capture and respond to keyboard input?  This is the way I see documented a lot.
0
anonymous (74722)
5/14/2004 9:36:08 PM
Generallly by handling WK_KEYDOWN and WM_CHAR messages. 

The abuse of PreTranslateMessage is popular, and indeed it is documented a lot, but it
doesn't mean that it makes sense. It has some very important uses, but substituting for
WM_CHAR and WM_KEYDOWN handlers is not among them.
				joe

On Fri, 14 May 2004 14:36:08 -0700, "Yasoo" <anonymous@discussions.microsoft.com> wrote:

>Joe - 
>
>   I forgot to ask.  Why do you think this is an abuse of PreTranslateMessage?  You mentioned something about this in a previous post.  How else do you capture and respond to keyboard input?  This is the way I see documented a lot.

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)
5/14/2004 10:47:34 PM
Unfortunately, there are LOTS of apps with such hard-wired bitmaps in
dialogs. Since I run my system with large fonts, I see it from the first
launch. It just sucks.

"Joseph M. Newcomer" <newcomer@flounder.com> wrote in message
news:np6aa09gq6ood1165r014u2es0vah74nor@4ax.com...
>
> But in using StretchBlt, I found that not only was the program painting on
the dialog, but
> the labels for the controls were part of the bitmap, and the controls had
to be placed by
> absolute pixel coordinates so they were in the right place! The entire
display was riddled
> with hardwired coordinates!
>
> Someone had never heard about DBUs, and had not realized that dialogs
resize based on
> resolution, screen size, and the mood of the driver.
>
> They had a LOT of complaints from customers. I solved the problem by
ditching the bitmap
> entirely. We used a "pretty" bitmap (their corporate logo, tiled), had a
16-color version,
> and I put all the controls up in the usual fashion. No, on a 640x480x256
display it wasn't
> as cute as their original one, but it worked on every platform, at every
resolution, at
> every color depth, with every driver. Somehow, the original author had
neglected to take
> reality into account.


0
alegr (1131)
5/15/2004 4:45:37 AM
I'm guessing it has something to do with which control has the focus, but I can't seem to trigger OnKeyDown and OnChar for my Dialog.
0
anonymous (74722)
5/15/2004 4:46:02 PM
You need to override OnGetDlgCode in your subclass to return the flag that says you want
keystrokes. Another reason to not try to do this directly in the dialog.
					joe

On Sat, 15 May 2004 09:46:02 -0700, "Yasoo" <anonymous@discussions.microsoft.com> wrote:

>I'm guessing it has something to do with which control has the focus, but I can't seem to trigger OnKeyDown and OnChar for my Dialog.

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)
5/17/2004 3:57:01 AM
Reply:

Similar Artilces:

Another Access Question
Hi Everyone, Is it possible to place the front end (forms) of an Access Databse on a web page, so that users can log on via the net and enter data into the forms. I am guessing that the front end would have to stand alone but not sure ! Any advice would be great Thanks will07 <will07@discussions.microsoft.com> wrote: >Is it possible to place the front end (forms) of an Access Databse on a web >page, so that users can log on via the net and enter data into the forms. I >am guessing that the front end would have to stand alone but not sure ! Can't be done using...

look up question #2
I have a list of people with their system rights in the next column by group. Each person may have more than one type of right in the list as follows John Smith Edit Joe Doe Submit Cathy Dory Edit John Smith Submit As you can see above, John Smith has both edit and submit rights on this list. What I am looking for is a formula where I can look down the list of names and find all instances of John Smith and then it can tell me if John Smith ever has edit rights or ever has submit rights. What I would like it to do is return a 1 if he has edit rights a...

Yet another Lotus macro question
I have for the most part converted to Excel but have a simple macro that on the surface cannot be converted. The Lotus macro used a database, template and list of branch names. The macro itself started with the name of the first branch, copied it to the template, sucked in the data for that branch and then printed the report. Then it went down to next name on the list and repeated the process until it reached the bottom of the list. In Excel it seems to indicate I have to repeat the steps for each and every branch on the list and not loop back through a 8 line macro that refers to the ...

question about spam
How is it that spam sent to one mailbox will end up in another not mentioned in the "to" address. In other words how is it that spammers get mail destined to Bob in Jim's mailbox? In news:y9CIg.1194$Cq4.62@newssvr25.news.prodigy.net, Mostro <ovelozpleasenospammingme@glasnospampleasefloss.com> typed: > How is it that spam sent to one mailbox will end up in another not > mentioned in the "to" address. In other words how is it that > spammers get mail destined to Bob in Jim's mailbox? The BCC field. It can be used for evil as well as good. ...

NMHDR question about hwndFrom
the documentation says that the hwndFrom attribute is the window handle to the control sending a message. I have a toolbar sitting on a property page. the toolbar is sending the message. Am I correct in assuming that the hwndFrom is the property page? I am having a problem obtaining the window handle of the property page. From the toolbar, I am calling CWnd* pOwner = GetOwner(); fh.hwndFrom = pWnd->GetSafeHwnd(); When I run the debugger pOwner correctly has the value CMyNotesPP, which is the parent window. When I step through the next line hwndFrom has a value in it but when I click th...

CDC::GetTextExtent question
Hi, I have a function that is to resize a status bar text pane when setting text dynamically. GetTextExtent() seems to think the text is almost twice as wide as it actually is so it leaves too much white space. How come? This is my func.: BOOL CMainFrame::SetStatusText(UINT nID, LPCTSTR lpszText) { int index = m_wndStatusBar.CommandToIndex(nID); if (index < 0) return FALSE; UINT nIDRet, nStyle; int cxWidth; m_wndStatusBar.GetPaneInfo(index, nIDRet, nStyle, cxWidth); ASSERT( nID == nIDRet ); CSize sz(cxWidth, 0); CDC* pDC = m_wndStatusBar.GetDC(); if (pDC) { sz = pDC->...

Datasheet question
Is it possible to show a Form Header on a Datasheet form ? Thanks Not that I know of, but you could emulate it by creating a new form with a form header (unbound - no rowsource) and place a subform in that form displayed as datasheetview. Maurice "Phil Hunt" wrote: > Is it possible to show a Form Header on a Datasheet form ? > > Thanks > > > No but you can fake it by putting the datasheet form in a subform = control on an unbound main form - Put whatever you'd like on the main = form. --=20 Joan Wild Microsoft Access MVP "Phil Hunt" &l...

newbie question on multi-dimensional array
Hi all, I have a real lame question about multi-dimensional array operation. Suppose I have defined a two-dimensional array "Array(10,10)". If I want to use the Excel function "Average" to compute the average value of Column, say 10, of that 2D array, is there any way to realize it? I tried "Application.Average(Array(:,10))", but apparently the Excel doesn't like that. (You can see I am a Matlab guy, so please don't laugh at me:) ) Any comments are extremely welcome. -- sammus ------------------------------------------------------------------------...

Microsoft Outlook 2003 tasks view question
In Microsoft Outlook 2003, I am able to define a customized view of each column, under the Tasks section. Is it possible to share the same customized view of the Tasks with other users? In other words, when other users open a shared view of a Task, I want them to see the same column structure as I see. If it is possible to propagate or share my defined view of columns, can someone describe the procedure? Thanks kindly. Joseph There is not an easy "copy this to everyone" command but its possible. When you create the view, use the option to share it with everyone. When they vie...

A few small questions
I have an Excel document with many tab (actually it look like a database, before any other thing no I can't move it to Access (corporate reasons). I also have a restriction to avoid using macro!!!! First is there a way for footer or header information to include info from cells in the speadsheet. Second you can define info to repeate at the top, what about at the bottom of the page. Third the sheet that serve for report can have up to 8 pages, can the printing zone be define by a cell value, so that page x of y (the y part be other than 8). I have the database part in a sheet bu...

formula question #7
Is there a formula that can change the color of cells if revenues drop three months in a row and if so what should the formula be? Hi, Assuming that your data is in row 1, columns A,B,C, with C being the latest data, Try using conditional formatting in cell C1 with the "Formula Is" =IF(AND(C1<B1,B1<A1),1,0) HTH >-----Original Message----- >Is there a formula that can change the color of cells if >revenues drop three months in a row and if so what should >the formula be? >. > Formula only needs =AND(D1<C1,C1<B1,B1<A1) you don't need t...

Layout Question Please
Outlook 2003 When I am in the Monthly calendar view I have three small month calendars in the left hand pane which is fine. If I click the folders button on the left, the folders pane shows on the left with the full calendar view on the right which is how I want it. The problem is that in the left pane on top of the folder list it still shows on of those small calendars which takes up room from my folder list and I cannot see all of the folders. How do I configure it so the left pane is all the folder list and does not include the small calendar? Thanks in advance... Bob I don't th...

Question on "Value" function
In trying to use Excel to help solve a mathematical puzzle, I would like to calculate the result of applying the mathematical operator in one cell to the numbers in two other cells. Example: A1 contains 2, B1 contains +, C1 contains 3. In D1, create a formula that will give the result of 2 + 3, i.e. 5. I have tried (among many other attempts) =VALUE(CONCATENATE(A1, B1, C1)), but it gives me a #VALUE! error. What am I missing? Hi this is not possible without using VBA. try the following UDF: Public Function my_calculate(op1 As Range, operand As Range, op2 As Range) my_calculate = Ap...

xml question?
what is the equivalent of this in C# ? foreach (XmlNode xmlConfigNode in xmlConfigDoc["configuration"].ChildNodes) Thansk Sorry I made a mistake here is what I want to convert to C# For Each Node In XmlDocument.Item("configuration").Item("appSettings") "Ray5531" <Ray5531@microsoft.com> wrote in message news:elPIiezOFHA.3408@TK2MSFTNGP14.phx.gbl... > what is the equivalent of this in C# ? > > foreach (XmlNode xmlConfigNode in > xmlConfigDoc["configuration"].ChildNodes) > > > > Thansk > > Hi Ray,...

Back Order Question
Hi, Have a back order question. Normal back orders are working right. In that if you have 10 and the order is for 15. During the lineitem transtaction it will put 5 in the backorder field automatically. What we need is if the customer orders 15 and we have 20, but only ship 10. We want the BO field to automatically fill with 5. Is this possible. Thanks in advance. Dexter Southerland It depends on how you fulfill and if you have cancel and bo enabled in the document types. If you have these enabled and are using Use Separate Fulfillment, you can select 10 to ship and set 5 to BO. T...

Dynamics GP 10 Reporting Question
I heard reporting in GP 10 is upgraded. Does anyone know if it will be anything like Rockton Software Dynamics Report Manager where you can send any report to like Sql reporting services or crystal? ------=_NextPart_0001_70733CB7 Content-Type: text/plain Content-Transfer-Encoding: 7bit I haven't heard anything at all that reporting in 10.0 will be changed. While I guess it's possible, I would assume for now that there won't be any big changes in general. I would expect more MS Office & SQL integration in the next version for sure, but I can't see everything rewrit...

Array range error question
When i try to redim my array i get an out of range error. can someone tel me why? Cells A1..A10 are filled with strings. thanks much Sub Get_names_array() Dim names_array() As Variant 'dynmanic Dim j As Long ReDim names_array(5, 1) j = 0 Range("A1").Select For i = 1 To 10 names_array(j, 0) = ActiveCell.Value names_array(j, 1) = ActiveCell.Address arraylimitFirst = UBound(names_array, 1) 'returns current dimension of 1st array limit, init = 5 If j >= arraylimitFirst Then ReDim Preserve names_array(10, 1) ' << RANGE ERROR ...

Newbie Remote Assistant and Desktop Questions
i Folks: Developing C++ on VS 2008 Pro, XP Pro, Win32. I have a client that recently upgraded from Vista to Windows 7 Ultimate, 32 bit, on his laptop. I recommended he get Ultimate so I could run Remote Desktop over the Internet. This is before I actually tried using Remote Desktop. After getting Remote Desktop up, I see that I really want, to help my client, is Remote Assistant. Both Remote Desktop and Remote Assistant are now running fine with two XP PCs on my LAN, using my Internet address, to connect. I've cobbled together port numbers requiring...

SOP Quick Print
We cannot print more than one copy of the Packing Slip with SOP Quick Print. In Quick Print setup, we have the Destination set to Printer. We want 2 copies of the Order and 2 copies of the Packing Slip. We get the 2 copies of the order but, for some reason, only 1 copy of the Packing Slip prints. We can get multiple copies of every document EXCEPT the packing slip. Even if we print JUST the packcing slip, it still won't print more than one copy. Any ideas? "Elaine" wrote: > We cannot print more than one copy of the Packing Slip with SOP Quick Print. > In Q...

Just a quick question
I want to be able to average a range of cells, some of these cells are 0, and those are the ones I don't to include in on the calculation. Brian, If your data is in "B5:D14"... =SUM(B5:D14)/COUNTIF(B5:D14,">0") Regards, Jim Cone San Francisco, CA "Brian Shafer" <brian.shafer123@insightbb.com> wrote in message news:u5UCb.386665$275.1243012@attbi_s53... > I want to be able to average a range of cells, some of these cells are 0, > and those are the ones I don't to include in on the calculation. > > Brian, If your range actually...

=CELL("filename") function related question
Is there a function in Excel that only picks up the sheet name in a workbook? I realised that =CELL("filename") function provides the full path, workbook & the worksheet information. Thanks in advance for any help & suggestions. Take a look here: http://www.mcgimpsey.com/excel/formulae/cell_function.html In article <1105122023.529944.145500@z14g2000cwz.googlegroups.com>, "wfcpyc" <wfcpyc@yahoo.com.au> wrote: > Is there a function in Excel that only picks up the sheet name in a > workbook? I realised that =CELL("filename") fun...

Licensing Questions
I'm building an iSCSI host for a client of mine, and was wondering what the license requirements would be. Here is he question, If I install my iSCSI host software (in this case StarWind) on a windows 2003 Platform, what kind of license do I need, ie do I only need the OS license or do I also need CLIs. Since no actual "User" will be accessing this Server Directly (they might be using a VMDK stored on the host LUN, but that would be via my VMware servers... basiclly, I'm using the iSCSI host, to host disk space for 2 or 3 VMWare ESXi hosts, hosting 2 or 3 VMs which...

GP Report Modifier Question (version 9.0)
On our invoice report I changed the format of a custom field to a custom format definition (that I named BB2 with 2 decimal places and show the currency symbol). Now our Inventory History Sales Summary Report prints all of the Total Quantities for the item with a currency symbol also, why is that? Is your Inventory History Sales Summary Report modified? Have you opened the field to check and make sure no format has been assigned to it? ...

Can anyone do quick test please?
Is there anyone out there with Outlook 2000 that can tell me if, when they save any received attachment, does the saved file get a modified and created time that is different from your PC's clock time? On two PC's I've tried this (one with Windows XP Pro, one with 98SE), they have the system Date/Time Properties Time Zone set to GMT+08:00, and Outlook 2000's Tools | Options | Preferences | Calendar Options | Time Zone is also set to GMT+8:00. When an attachment is saved, it gets modified and created times 8 hours ahead of the Current System Time (CST). Saving attac...

Disaster Recovery Question!
I'm sort of new at this. I have 1 server running 2003 as DC/DNS/DHCP and I have another server running Exchange 2003. I want to create an off site disaster recover network. I know I can create the connection with a VPN. I know I can do a backup DC and a secondary DNS. My questions is can I create a backup Exchange 2003 Server? Is this possible? I know DC/DNS are small enough that it can easily be updated on the secondary server. How do you guys set up a secondary Exchange 2003 server? I hope you guys can give me an answer. Thanks! Phil If you mean real-time replication ...