Solved

Device Context MFC

Posted on 2009-04-15
10
341 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 31

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 31

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
Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

 

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
 
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 31

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 31

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

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Introduction: Load and Save to file, Document-View interaction inside the SDI. Continuing from the second article about sudoku.   Open the project in visual studio. From the class view select CSudokuDoc and double click to open the header …
Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
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 shows how to use Hyena, from SystemTools Software, to bulk import 100 user accounts from an external text file. View in 1080p for best video quality.

813 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

12 Experts available now in Live!

Get 1:1 Help Now