[Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 451
  • Last Modified:

Some APIs do not work with Metafile DC

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
dipak_kr_ghosh
Asked:
dipak_kr_ghosh
  • 15
  • 7
  • 5
1 Solution
 
MichaelSCommented:
>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
 
dipak_kr_ghoshAuthor Commented:
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
 
migelCommented:
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
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
dipak_kr_ghoshAuthor Commented:
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
 
MichaelSCommented:
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
 
dipak_kr_ghoshAuthor Commented:
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
 
dipak_kr_ghoshAuthor Commented:
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
 
MichaelSCommented:
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
 
dipak_kr_ghoshAuthor Commented:
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
 
migelCommented:
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
 
dipak_kr_ghoshAuthor Commented:
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
 
dipak_kr_ghoshAuthor Commented:
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
 
MichaelSCommented:
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
 
dipak_kr_ghoshAuthor Commented:
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
 
migelCommented:
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
 
dipak_kr_ghoshAuthor Commented:
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
 
dipak_kr_ghoshAuthor Commented:
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
 
migelCommented:
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
 
dipak_kr_ghoshAuthor Commented:
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
 
MichaelSCommented:
than use SetWindowOrg and remember what did you set.
0
 
dipak_kr_ghoshAuthor Commented:
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
 
MichaelSCommented:
why you post each comment few times?
0
 
dipak_kr_ghoshAuthor Commented:
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
 
dipak_kr_ghoshAuthor Commented:
It is not my fault. I post a comment only once. Why it is happening, no idea.
Thanks
0
 
MichaelSCommented:
Strange, may be you have to report it to support team :)
0
 
migelCommented:
It appears after reloading page with entered (submitted) comment
0
 
dipak_kr_ghoshAuthor Commented:
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

Prep for the ITIL® Foundation Certification Exam

December’s Course of the Month is now available! Enroll to learn ITIL® Foundation best practices for delivering IT services effectively and efficiently.

  • 15
  • 7
  • 5
Tackle projects and never again get stuck behind a technical roadblock.
Join Now