Click here to Skip to main content
15,913,939 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
AnswerRe: embedding applications and music Pin
Rajesh R Subramanian17-Dec-06 18:22
professionalRajesh R Subramanian17-Dec-06 18:22 
QuestionNot Getting Color w/ MFC... Pin
CoffeeAddict1915-Dec-06 8:21
CoffeeAddict1915-Dec-06 8:21 
AnswerRe: Not Getting Color w/ MFC... Pin
Mark Salsbery15-Dec-06 9:12
Mark Salsbery15-Dec-06 9:12 
AnswerRe: Not Getting Color w/ MFC... Pin
Mark Salsbery15-Dec-06 9:26
Mark Salsbery15-Dec-06 9:26 
GeneralRe: Not Getting Color w/ MFC... Pin
CoffeeAddict1915-Dec-06 10:24
CoffeeAddict1915-Dec-06 10:24 
GeneralRe: Not Getting Color w/ MFC... Pin
Mark Salsbery15-Dec-06 10:46
Mark Salsbery15-Dec-06 10:46 
GeneralRe: Not Getting Color w/ MFC... Pin
CoffeeAddict1915-Dec-06 10:51
CoffeeAddict1915-Dec-06 10:51 
GeneralRe: Not Getting Color w/ MFC... [modified] Pin
Mark Salsbery15-Dec-06 12:09
Mark Salsbery15-Dec-06 12:09 
Ok cool. There's an infinite number of ways to do this so any of these suggestions are just
one possible method.

Performance isn't super critical in this case because you can always repaint a window faster
than the user can manipulate it (mouse moves, clicks, keystrokes, resizing, etc.).

1)
To manage the DCs you can just create them when you need them.
To create your mem DCs compatible with the screen (which is compatible with the window) you can
use mem_DC.CreateCompatibleDC(0); That eliminates the need for your "ScreenPtr" variable.

2)
To manage painting you need to be able to paint in response to WM_PAINT as well as WM_MOUSEMOVE
and possibly other messages. The easiest method is to add a method to your class that takes
a CDC & as a parameter, something like:
void RepaintWindow(CDC &dc)
To call from OnPaint() you can pass your PaintDC
CPaintDC Screen(this);
RepaintWindow(Screen);
To call from OnMouseMove() (or any other message handler) you can use a CClientDC
CClientDC Screen;
RepaintWindow(Screen);

To implement the RepaintWindow() method you can do anything, depending on the performance you
want.
The easiest to code but worst performance (lots of flicker) is to redraw everything on every
call - the background, the board, and all the Xs and Os.
The hardest to code but best perfomancewould be to have offscreen bitmaps for the board, for an
"X", and for an "O" (and possibly even a cool background bitmap). Drawing/blting to a memory
DC/bitmap the size of the windows client area (recreated every time size changes) you could draw
the background, the board, all the Xs and Os and then blt the entire thing to the window (screen).
This will be nice and smooth to the user - no flicker. You're already most of the way there in
your code by drawing your bitmaps once ahead of time.
There's a variety of methods in between these two examples, depending on the trade-off of coding
vs. performance.

3)
Another tip - you can keep your offscreen bitmaps selected into the memory DCs. There's no need
to select them in and out every time you draw with them. I saw you are sharing a memory DC for
two bitmaps so you had to swap bitmaps in and out but it's just as easy to have a memory DC for
each.

I'm sure you know you'll have to keep track of where the user has places Xs and Os.


I hope this helps a bit! If it does, I expect a free copy when it's finished Smile | :)










-- modified at 18:20 Friday 15th December, 2006
GeneralRe: Not Getting Color w/ MFC... Pin
Mark Salsbery15-Dec-06 12:38
Mark Salsbery15-Dec-06 12:38 
GeneralRe: Not Getting Color w/ MFC... Pin
CoffeeAddict1915-Dec-06 16:39
CoffeeAddict1915-Dec-06 16:39 
GeneralRe: Not Getting Color w/ MFC... Pin
Mark Salsbery16-Dec-06 8:40
Mark Salsbery16-Dec-06 8:40 
QuestionHow to debug a COM from an ASP.NET client? Pin
almc15-Dec-06 7:22
almc15-Dec-06 7:22 
AnswerRe: How to debug a COM from an ASP.NET client? Pin
Eytukan16-Dec-06 4:57
Eytukan16-Dec-06 4:57 
GeneralRe: How to debug a COM from an ASP.NET client? Pin
almc18-Dec-06 3:50
almc18-Dec-06 3:50 
Questionhow to move from CDatabase to CDoaDatabase? Pin
bitkidoku15-Dec-06 4:17
bitkidoku15-Dec-06 4:17 
AnswerRe: how to move from CDatabase to CDoaDatabase? Pin
Mark Salsbery15-Dec-06 5:10
Mark Salsbery15-Dec-06 5:10 
GeneralRe: how to move from CDatabase to CDoaDatabase? Pin
bitkidoku15-Dec-06 22:03
bitkidoku15-Dec-06 22:03 
QuestionPlaying audio with AVIFile API. Pin
10011000100101101000015-Dec-06 4:17
10011000100101101000015-Dec-06 4:17 
QuestionResume and suspend thread Pin
RockyJames15-Dec-06 4:07
RockyJames15-Dec-06 4:07 
AnswerRe: Resume and suspend thread Pin
Mark Salsbery15-Dec-06 5:20
Mark Salsbery15-Dec-06 5:20 
GeneralRe: Resume and suspend thread Pin
RockyJames15-Dec-06 17:54
RockyJames15-Dec-06 17:54 
GeneralRe: Resume and suspend thread Pin
Mark Salsbery16-Dec-06 10:21
Mark Salsbery16-Dec-06 10:21 
QuestionCString::Format - Debug vs Release Pin
Dustin Henry15-Dec-06 4:04
Dustin Henry15-Dec-06 4:04 
AnswerRe: CString::Format - Debug vs Release Pin
kakan15-Dec-06 4:12
professionalkakan15-Dec-06 4:12 
GeneralRe: CString::Format - Debug vs Release Pin
Dustin Henry15-Dec-06 4:15
Dustin Henry15-Dec-06 4:15 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.