Solved

Device Context MFC

Posted on 2009-04-15
10
321 Views
Last Modified: 2013-11-20
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
0
Comment
Question by:IssacJones
  • 4
  • 4
  • 2
10 Comments
 
LVL 30

Expert Comment

by:Zoppo
ID: 24146833
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
 

Author Comment

by:IssacJones
ID: 24146842
I'm using OnPaint, which supplies a device context.

John
0
 
LVL 30

Expert Comment

by:Zoppo
ID: 24146892
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
 

Author Comment

by:IssacJones
ID: 24146970
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
 

Author Comment

by:IssacJones
ID: 24147042
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
IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 
LVL 19

Assisted Solution

by:alb66
alb66 earned 100 total points
ID: 24147056
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
 
LVL 30

Accepted Solution

by:
Zoppo earned 150 total points
ID: 24147071
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
 
LVL 19

Expert Comment

by:alb66
ID: 24147106
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
 

Author Closing Comment

by:IssacJones
ID: 31570364
thanks guys, I've split the points as you both helped.
0
 
LVL 30

Expert Comment

by:Zoppo
ID: 24147310
> 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

Featured Post

What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

Join & Write a Comment

Here is how to use MFC's automatic Radio Button handling in your dialog boxes and forms.  Beginner programmers usually start with a OnClick handler for each radio button and that's just not the right way to go.  MFC has a very cool system for handli…
Introduction: Database storage, where is the exe actually on the disc? Playing a game selected randomly (how to generate random numbers).  Error trapping with try..catch to help the code run even if something goes wrong. Continuing from the seve…
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
This video demonstrates how to create an example email signature rule for a department in a company using CodeTwo Exchange Rules. The signature will be inserted beneath users' latest emails in conversations and will be displayed in users' Sent Items…

706 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now