Solved

Some APIs do not work with Metafile DC

Posted on 2001-07-12
27
419 Views
Last Modified: 2013-11-20
Hi,
Do you have any clue why the following functions do not work and gives assertion failure with decive context pointing to a metafile?
1) GetWindowOrg
2) GetTextMetrics
3) GetTextExt
All the above functions are member of CDC.
The functions return value in logical units and not in device units. So it should have worked. Funnily SetWindowOrg works but not GetWindowOrg.
Is there any way to make those functions work with metafile dc without resorting to any other method of calculating those values? I tried changing the mapping mode to MM_ISOTROPIC and MM_ANISOTROPIC too. But does not work.

Or if there is no way to make those APIs work, is there any other good alternative to get those values, especially an alternative to GetWindowOrg for metafile dc?

Regards
Dipak
0
Comment
Question by:dipak_kr_ghosh
  • 15
  • 7
  • 5
27 Comments
 
LVL 6

Expert Comment

by:MichaelS
ID: 6276880
>metafile dc

what is that?????

can you show your code, somehow it's hard to catch what exactly doesn't works and how it fails.

BTW, did you tried the same code with "not metafile dc"?
0
 

Author Comment

by:dipak_kr_ghosh
ID: 6276929
Hi,
dc stands for device context.

The problem description is simpel.

When trying to execute the following line
CPoint oldOrigin = pdc->GetWindowOrg();
it fails if the pdc is obtained by
HDC hdcMeta = CreateMetaFile(NULL);
CDC* pdc = CDC::FromHandle(hdcMeta);

For other types of device context like window and printer
it works
Regards
Dipak

0
 
LVL 12

Expert Comment

by:migel
ID: 6276943
Hi!
It is correct!
some functions doesn`t work with metafile DC since that DC ican`t provide several params for caller
see MSDN article:
Windows-Format Metafiles

and here is list of methods that works with metafile:
AnimatePalette
Arc
BitBlt
Chord
CreateBrushIndirect
CreateDIBPatternBrush
CreateFontIndirect
CreatePalette
CreatePatternBrush
CreatePenIndirect
DeleteObject
Ellipse
Escape
ExcludeClipRect
ExtFloodFill
ExtTextOut
FillRgn
FloodFill
FrameRgn
IntersectClipRect
InvertRgn
LineTo
MoveToEx
OffsetClipRgn
OffsetViewportOrgEx
OffsetWindowOrgEx
PaintRgn
PatBlt
Pie
Polygon
Polyline
PolyPolygon
RealizePalette
Rectangle
ResizePalette
RestoreDC
RoundRect
SaveDC
ScaleViewportExtEx
ScaleWindowExtEx
SelectClipRgn
SelectObject
SelectPalette
SetBkColor
SetBkMode
SetDIBitsToDevice
SetMapMode
SetMapperFlags
SetPaletteEntries
SetPixel
SetPolyFillMode
SetROP2
SetStretchBltMode
SetTextAlign
SetTextCharacterExtra
SetTextColor
SetTextJustification
SetViewportOrgEx
SetWindowExtEx
SetWindowOrgEx
StretchBlt
StretchDIBits
TextOut
0
 

Author Comment

by:dipak_kr_ghosh
ID: 6276988
Hi,
dc stands for device context.

The problem description is simpel.

When trying to execute the following line
CPoint oldOrigin = pdc->GetWindowOrg();
it fails if the pdc is obtained by
HDC hdcMeta = CreateMetaFile(NULL);
CDC* pdc = CDC::FromHandle(hdcMeta);

For other types of device context like window and printer
it works
Regards
Dipak

0
 
LVL 6

Accepted Solution

by:
MichaelS earned 100 total points
ID: 6277008
From MSDN about CreateMetaFile() function

The device context created by this function can be used to record GDI output functions in a Windows-format metafile. It cannot be used with GDI query functions such as GetTextColor

and BTW,

This function is provided only for compatibility with earlier 16-bit versions of Windows. Win32-based applications should use the CreateEnhMetaFile function.
0
 

Author Comment

by:dipak_kr_ghosh
ID: 6277032
Hi,
dc stands for device context.

The problem description is simpel.

When trying to execute the following line
CPoint oldOrigin = pdc->GetWindowOrg();
it fails if the pdc is obtained by
HDC hdcMeta = CreateMetaFile(NULL);
CDC* pdc = CDC::FromHandle(hdcMeta);

For other types of device context like window and printer
it works
Regards
Dipak

0
 

Author Comment

by:dipak_kr_ghosh
ID: 6277080
Hi MichaelS,
Can you suggest any alternative to getting those values/attribute from metafile dc. I need to know the height of character etc after selecting a font and things like this. Does not window provide any mechanism for such requirement.
Regards
Dipak
0
 
LVL 6

Expert Comment

by:MichaelS
ID: 6277127
Why normal DC's not good for you? May be you can describe what are you want to do and than we can think how to do it?
0
 

Author Comment

by:dipak_kr_ghosh
ID: 6277139
Hi MichaelS,
Can you suggest any alternative to getting those values/attribute from metafile dc. I need to know the height of character etc after selecting a font and things like this. Does not window provide any mechanism for such requirement.
Regards
Dipak
0
 
LVL 12

Expert Comment

by:migel
ID: 6277141
Hi!
There are no simple solution to retrieve this info from metafileDC -
Probably solution will be in the Metafile Objects enumeration and catch last occured select statement to retrieve needed info.
0
 

Author Comment

by:dipak_kr_ghosh
ID: 6277155
The reason is simple. I need to save my drawing as wmf or emf file in disk. also I need to copy the picture on to the clipboard and I want to do it in metafile format not in bitmap format. So there are more than one functional requirement for which I must resolve these issues.
Regards
Dipak
0
 

Author Comment

by:dipak_kr_ghosh
ID: 6277162
Hi migel,
<<Probably solution will be in the Metafile Objects enumeration and catch last occured select statement
to retrieve needed info.>>

Can you let me know how to go about it?
Regards
Dipak
0
 
LVL 6

Expert Comment

by:MichaelS
ID: 6277191
Well, than I don't understand what is the reason to use GetWindowOrg function cas in "metafile dc" you don't have any window???

from MSDN:
GetWindowOrg() retrieves the x- and y-coordinates of the origin of the window associated with the device context
0
Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

 

Author Comment

by:dipak_kr_ghosh
ID: 6277197
Hi migel,
<<Probably solution will be in the Metafile Objects enumeration and catch last occured select statement
to retrieve needed info.>>

Can you let me know how to go about it?
Regards
Dipak
0
 
LVL 12

Expert Comment

by:migel
ID: 6277234
You need to call API:
BOOL EnumMetaFile(
HDC hdc, // handle to DC HMETAFILE hmf, // handle to Windows-format metafile MFENUMPROC lpMetaFunc, // callback function LPARAM lParam // optional data );

and provide your callbac function:
int CALLBACK MyEnumMetaFileProc(
  HDC hDC,                // handle to DC
  HANDLETABLE *lpHTable,  // metafile handle table
  METARECORD *lpMFR,      // metafile record
  int nObj,               // count of objects
  LPARAM lpClientData     // optional data
)

for details See MSDN for this API.
But I`m not sure that this method will work for newly created metafiles (you nee HMETAFILE but you can`t get it unless CloseMetafile will be called)
0
 

Author Comment

by:dipak_kr_ghosh
ID: 6277236
Hi MichaelS,
Window Origin does not mean origin of Window we get to see on monitor. Basically it means the origin of logical co-ordinate system. And The logical co-ordinate system bears a relation with device co-ordinate system. All the GDI API calls ultimate boil down to device co-ordinate system before doing anything onto the associated dc. Actually you just change the origin of logical co-ordinate system bt using SetWindowOrg. You can use these APIs with printer dc
as you can use them with Window dc. Even You can use the SetWindowOrg API with metafile dc. And it is absolutely fine.
Regards
Dipak
0
 

Author Comment

by:dipak_kr_ghosh
ID: 6277245
Hi MichaelS,
Window Origin does not mean origin of Window we get to see on monitor. Basically it means the origin of logical co-ordinate system. And The logical co-ordinate system bears a relation with device co-ordinate system. All the GDI API calls ultimate boil down to device co-ordinate system before doing anything onto the associated dc. Actually you just change the origin of logical co-ordinate system bt using SetWindowOrg. You can use these APIs with printer dc
as you can use them with Window dc. Even You can use the SetWindowOrg API with metafile dc. And it is absolutely fine.
Regards
Dipak
0
 
LVL 12

Expert Comment

by:migel
ID: 6277262
You need to call API:
BOOL EnumMetaFile(
HDC hdc, // handle to DC HMETAFILE hmf, // handle to Windows-format metafile MFENUMPROC lpMetaFunc, // callback function LPARAM lParam // optional data );

and provide your callbac function:
int CALLBACK MyEnumMetaFileProc(
  HDC hDC,                // handle to DC
  HANDLETABLE *lpHTable,  // metafile handle table
  METARECORD *lpMFR,      // metafile record
  int nObj,               // count of objects
  LPARAM lpClientData     // optional data
)

for details See MSDN for this API.
But I`m not sure that this method will work for newly created metafiles (you nee HMETAFILE but you can`t get it unless CloseMetafile will be called)
0
 

Author Comment

by:dipak_kr_ghosh
ID: 6277272
Hi MichaelS,
Window Origin does not mean origin of Window we get to see on monitor. Basically it means the origin of logical co-ordinate system. And The logical co-ordinate system bears a relation with device co-ordinate system. All the GDI API calls ultimate boil down to device co-ordinate system before doing anything onto the associated dc. Actually you just change the origin of logical co-ordinate system bt using SetWindowOrg. You can use these APIs with printer dc
as you can use them with Window dc. Even You can use the SetWindowOrg API with metafile dc. And it is absolutely fine.
Regards
Dipak
0
 
LVL 6

Expert Comment

by:MichaelS
ID: 6277276
than use SetWindowOrg and remember what did you set.
0
 

Author Comment

by:dipak_kr_ghosh
ID: 6277281
Hi MichaelS,
Window Origin does not mean origin of Window we get to see on monitor. Basically it means the origin of logical co-ordinate system. And The logical co-ordinate system bears a relation with device co-ordinate system. All the GDI API calls ultimate boil down to device co-ordinate system before doing anything onto the associated dc. Actually you just change the origin of logical co-ordinate system bt using SetWindowOrg. You can use these APIs with printer dc
as you can use them with Window dc. Even You can use the SetWindowOrg API with metafile dc. And it is absolutely fine.
Regards
Dipak
0
 
LVL 6

Expert Comment

by:MichaelS
ID: 6277304
why you post each comment few times?
0
 

Author Comment

by:dipak_kr_ghosh
ID: 6277331
Hi MichaelS,
Window Origin does not mean origin of Window we get to see on monitor. Basically it means the origin of logical co-ordinate system. And The logical co-ordinate system bears a relation with device co-ordinate system. All the GDI API calls ultimate boil down to device co-ordinate system before doing anything onto the associated dc. Actually you just change the origin of logical co-ordinate system bt using SetWindowOrg. You can use these APIs with printer dc
as you can use them with Window dc. Even You can use the SetWindowOrg API with metafile dc. And it is absolutely fine.
Regards
Dipak
0
 

Author Comment

by:dipak_kr_ghosh
ID: 6277337
It is not my fault. I post a comment only once. Why it is happening, no idea.
Thanks
0
 
LVL 6

Expert Comment

by:MichaelS
ID: 6277342
Strange, may be you have to report it to support team :)
0
 
LVL 12

Expert Comment

by:migel
ID: 6277381
It appears after reloading page with entered (submitted) comment
0
 

Author Comment

by:dipak_kr_ghosh
ID: 6277441
Yes migel, probably you are right.
What I have been doing so far is that the page is open in browser and whenever I get mail, I just refresh my page and see your commnets. That might have caused the problem, but why on earth should it happen??!! The request is posted once carrying my commnet and the response does not carry the comment in the textarea. And it is not shown in the field either. On next post of the request it should not carry the textfiled value once again. It can so happen if is persisted in session and some fallacy is there.
Dipak
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

Introduction: Finishing the grid – keyboard support for arrow keys to manoeuvre, entering the numbers.  The PreTranslateMessage function is to be used to intercept and respond to keyboard events. Continuing from the fourth article about sudoku. …
If you use Adobe Reader X it is possible you can't open OLE PDF documents in the standard. The reason is the 'save box mode' in adobe reader X. Many people think the protected Mode of adobe reader x is only to stop the write access. But this fe…
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.
Illustrator's Shape Builder tool will let you combine shapes visually and interactively. This video shows the Mac version, but the tool works the same way in Windows. To follow along with this video, you can draw your own shapes or download the file…

743 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

13 Experts available now in Live!

Get 1:1 Help Now