Newsgroups : Borland : borland.public.delphi.nativeapi.win32 : 2005 Nov : HDC parameter in GetCharacterPlacement

www.cryer.info
Managed Newsgroup Archive

HDC parameter in GetCharacterPlacement

Subject:HDC parameter in GetCharacterPlacement
Posted by:"kcahcn" (al_aza..@hotmail.com)
Date:26 Nov 2005 23:49:55 -0700

function MyFunction(): String;
var
  dc: HDC;
  GCP: TGCPResults;
  ret,i:integer;
  m_glyphs : array[0..20]of UINT;
  glfix:array[0..7]of UINT;
  sText: String;
begin
  Result := '';
  Form1.Font.Name:='Andalus';
  sText:='abc'#$c7#$c8#$c9#$ca;
  SetLength(Result, Length(sText));
  GCP.lStructSize := sizeof(TGCPResults);
  GCP.lpOutString := PChar(Result);
  GCP.lpOrder := nil;
  GCP.lpDx := nil;
  GCP.lpCaretPos := nil;
  GCP.lpClass := nil;
  GCP.lpGlyphs := @m_glyphs;
  GCP.nGlyphs := Length(sText);
  GCP.nMaxFit := 0;
  DC := Form1.Canvas.Handle;
  GetCharacterPlacement(dc,
                        PChar(sText),
                        Length(sText),
                        512,
                        GCP,
                        0);

  if ret<>0 then
  for i:=0 to 6 do
  begin
    glfix[i]:= PUINT(ULONG(GCP.lpGlyphs)+(i*2))^ and $FFFF;
    //i*2 why 2? ;)
    showmessage(inttostr(glfix[i]));
  end;
  ReleaseDc(form1.Handle, DC);
  Result := Copy(Result, 1, Length(sText));
end;
Above code is working well.

showmessage(inttostr(glfix[i])); will output 68,69,70,346,349,352,355 which are the glyph indices of sText string (that is when Font is "Andalus", if we change the font the result may be diffirent ..). That is ok at all...

Problem:

If we you use DC := GetDC(Form1.Handle); we will not get that result ..

I think that is becuase the DC we got by using GetDC(Form1.Handle); doesn't have the same HFONT Object as Form1.canvas...

If we use

DC := GetDC(Form1.Handle);

selectobject(dc,HGDIOBJ(form1.Canvas.Font.Handle));

It will be ok.But that is not what I need..

What I need now is there another way to solve this problem?

If we are dealing with another program and we have a window handle only how we can get the true result (suppose window DC has the same attribute as above code ..)?

Thanx..

kcahcn

Glossary

Replies:

www.cryer.info
Managed Newsgroup Archive