Device Context MFC

Hiya

I have a dialog in which I am trying to display a bitmap. The code I am using works in one MFC application but not in anothe i.e. the bitmap is not in the same position on the dialog in both applications and the bitmap is of different size and colour.

I am wondering if the problem is because both applications may be using different mapping modes. in order to test this theory I used the following code:

      int map_mode = dc.GetMapMode();
      switch ( map_mode ){
            case MM_TWIPS:
                  break;
            case MM_HIMETRIC:
                  break;
            case MM_LOMETRIC:
                  break;
            case MM_HIENGLISH:
                  break;
            case MM_LOENGLISH:
                  break;
            case MM_TEXT:
                  break;
            case MM_ISOTROPIC:
                  break;
            case MM_ANISOTROPIC:
                  break;
            default:
                  break;
      }

to find the map mode in the new application. The application map_mode has the value 1 in the debugger but none of the cases are jumped to.

How can I find what the mapping mode in the dialog?

John
IssacJonesAsked:
Who is Participating?
 
ZoppoCommented:
Hi,

hard to say why the debugger has problems - at least I know that VS 2008 C++ debugger seems to have lot of bugs. I had cases where stepping into a function did continue execution as if I had selected 'Continue'. Further even I had cases where the debugger displayed different values in the watch/auto-window as the values were in fact (I saw an int shown in the watch window i.e. with value '1', but using TRACE to output the same value in the line above wrote another value, i.e. '0').

So, to be sure the debugger doesn't show  you should use some TRACEs to verify them.

Attached you can find the values defined for the mapping modes (from 'WinGDI.h'):

ZOPPO
/* Mapping Modes */
#define MM_TEXT             1
#define MM_LOMETRIC         2
#define MM_HIMETRIC         3
#define MM_LOENGLISH        4
#define MM_HIENGLISH        5
#define MM_TWIPS            6
#define MM_ISOTROPIC        7
#define MM_ANISOTROPIC      8

Open in new window

0
 
ZoppoCommented:
Hi IssacJones,

a window (so even a dialog) doesn't have a mapping mode - only DCs have mapping modes.

Where does the used DC come from? Could you post some code which you use to paint the image?

You could try to just instantiate a new DC using i.e. CClientDC and use this even as base for the memory DC.

ZOPPO
0
 
IssacJonesAuthor Commented:
I'm using OnPaint, which supplies a device context.

John
0
Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
ZoppoCommented:
Hi,

ok - how do you draw the dialog itself there? Maybe the DC is somehow modified with dialog's drawing functionality. If so you could save/restore the DC settings before/after the dialog's drawing using SaveDC/RestoreDC.

If this doesn't help please post some code.

BTW, maybe instead of implement the drawing of the bitmap in the dialog it might be a good idea to implement a control (i.e. derived from CStatic) which implements that drawing - this would eliminate the need of re-implementing the drawing in every window you need it, just implement it once in the control and use it where you need it.


ZOPPO
0
 
IssacJonesAuthor Commented:
Hi zoppo

thanks for your help. can you tell me why my switch statement doesn't give me the mapping mode? Indeed, do you know which integers the mapping modes map to? For example, what is MM_TWIPS as an integer?

John
0
 
IssacJonesAuthor Commented:
Hiya again

I have found that the problem was the mapping mode i.e. if I temporarily change the mapping mode to MM_TEXT in the new application before the drawing is done everything works fine.

However, I still can't see why my switch statement code does not work.

Any ideas or, alternatively, a way for me to determine what the mapping mode is in a given device contect?

John
0
 
alb66Commented:
From wingdi.h:

/* Mapping Modes */
#define MM_TEXT             1
#define MM_LOMETRIC         2
#define MM_HIMETRIC         3
#define MM_LOENGLISH        4
#define MM_HIENGLISH        5
#define MM_TWIPS            6
#define MM_ISOTROPIC        7
#define MM_ANISOTROPIC      8


Since you have no code in the switch, may be you have some optimazion on.
Try to  add a messagebox in each case statement.
0
 
alb66Commented:
I have had some problems with VS 2008 C++ SP1 debugger too.
I never had problems before the installation of SP1.
All the problems were fixed installing silverlight tools.
0
 
IssacJonesAuthor Commented:
thanks guys, I've split the points as you both helped.
0
 
ZoppoCommented:
> All the problems were fixed installing silverlight tools.
@alb66: Thanks for that hint, I'll try this soon since it's really annoying to work with a debugger which is such buggy ...
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.