Solved

Device Context MFC

Posted on 2009-04-15
10
369 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
[Live Webinar] The Cloud Skills Gap

As Cloud technologies come of age, business leaders grapple with the impact it has on their team's skills and the gap associated with the use of a cloud platform.

Join experts from 451 Research and Concerto Cloud Services on July 27th where we will examine fact and fiction.

 

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

Moving data to the cloud? Find out if you’re ready

Before moving to the cloud, it is important to carefully define your db needs, plan for the migration & understand prod. environment. This wp explains how to define what you need from a cloud provider, plan for the migration & what putting a cloud solution into practice entails.

Question has a verified solution.

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

This is to be the first in a series of articles demonstrating the development of a complete windows based application using the MFC classes.  I’ll try to keep each article focused on one (or a couple) of the tasks that one may meet.   Introductio…
Introduction: Displaying information on the statusbar.   Continuing from the third article about sudoku.   Open the project in visual studio. Status bar – let’s display the timestamp there.  We need to get the timestamp from the document s…
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 is my first video review of Microsoft Bookings, I will be doing a part two with a bit more information, but wanted to get this out to you folks.

622 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