GetCharacterPlacement 的 hdc?? ( 积分: 200 )

  • 主题发起人 主题发起人 kcahcn
  • 开始时间 开始时间
K

kcahcn

Unregistered / Unconfirmed
GUEST, unregistred user!
以下代码没问题。 不过如果把<br>whdc:=form1.Canvas.handle; 改为<br>whdc:=Getdc(form1.handle); <br>GetCharacterPlacement的返回值为0 ,为什么?怎么解决?<br>如果知道窗体的句丙(别的程序的窗体),怎么能成功的利用以下代码。。<br>用GetDC取得DC好像不对。用其他的API取得DC都会导致GetCharacterPlacement的返回值为0。。<br>代码:-<br><br>const maxlength=512;<br><br>var<br> &nbsp;m_gcp:GCP_RESULTS ;<br> &nbsp;m_strOut : array[0..maxlength]of char;<br> &nbsp;m_dx : array [0..maxlength] of integer;<br> &nbsp;m_order : array[0..maxlength]of cardinal;<br> &nbsp;m_caret : array[0..maxlength]of integer;<br> &nbsp;m_class : array [0..maxlength]of char;<br> &nbsp;m_glyphs : array[0..maxlength]of UINT;<br> &nbsp;mess:string;<br> &nbsp;whDC:HDC;<br> &nbsp;ret:integer;<br>begin<br> &nbsp; &nbsp;mess:='abc'#$c7#$c8#$c9#$ca;<br><br> &nbsp; FillMemory(@m_gcp, &nbsp;sizeof(m_gcp), 0);<br> &nbsp; m_gcp.lStructSize := sizeof(GCP_RESULTS);<br> &nbsp; m_gcp.lpOutString := m_strOut;<br> &nbsp; m_gcp.lpOrder &nbsp; &nbsp; := @m_order;<br> &nbsp; m_gcp.lpDx &nbsp; &nbsp; &nbsp; &nbsp;:= @m_dx;<br> &nbsp; m_gcp.lpCaretPos &nbsp;:= @m_caret;<br> &nbsp; m_gcp.lpClass &nbsp; &nbsp; := @m_class;<br> &nbsp; m_gcp.lpGlyphs &nbsp; &nbsp;:= @m_glyphs;<br> &nbsp; m_gcp.nGlyphs &nbsp; &nbsp; := maxlength;<br> &nbsp; Form1.Font.Charset:=ARABIC_CHARSET ;<br> &nbsp; whdc:=form1.Canvas.handle;<br> &nbsp; //SetTextAlign(whDC, TA_LEFT or TA_RTLREADING);<br> &nbsp; ret:=GetCharacterPlacement(whDC, Pchar(mess), 7, 0, &nbsp;m_gcp, 0);<br>...<br>end;
 
以下代码没问题。 不过如果把<br>whdc:=form1.Canvas.handle; 改为<br>whdc:=Getdc(form1.handle); <br>GetCharacterPlacement的返回值为0 ,为什么?怎么解决?<br>如果知道窗体的句丙(别的程序的窗体),怎么能成功的利用以下代码。。<br>用GetDC取得DC好像不对。用其他的API取得DC都会导致GetCharacterPlacement的返回值为0。。<br>代码:-<br><br>const maxlength=512;<br><br>var<br> &nbsp;m_gcp:GCP_RESULTS ;<br> &nbsp;m_strOut : array[0..maxlength]of char;<br> &nbsp;m_dx : array [0..maxlength] of integer;<br> &nbsp;m_order : array[0..maxlength]of cardinal;<br> &nbsp;m_caret : array[0..maxlength]of integer;<br> &nbsp;m_class : array [0..maxlength]of char;<br> &nbsp;m_glyphs : array[0..maxlength]of UINT;<br> &nbsp;mess:string;<br> &nbsp;whDC:HDC;<br> &nbsp;ret:integer;<br>begin<br> &nbsp; &nbsp;mess:='abc'#$c7#$c8#$c9#$ca;<br><br> &nbsp; FillMemory(@m_gcp, &nbsp;sizeof(m_gcp), 0);<br> &nbsp; m_gcp.lStructSize := sizeof(GCP_RESULTS);<br> &nbsp; m_gcp.lpOutString := m_strOut;<br> &nbsp; m_gcp.lpOrder &nbsp; &nbsp; := @m_order;<br> &nbsp; m_gcp.lpDx &nbsp; &nbsp; &nbsp; &nbsp;:= @m_dx;<br> &nbsp; m_gcp.lpCaretPos &nbsp;:= @m_caret;<br> &nbsp; m_gcp.lpClass &nbsp; &nbsp; := @m_class;<br> &nbsp; m_gcp.lpGlyphs &nbsp; &nbsp;:= @m_glyphs;<br> &nbsp; m_gcp.nGlyphs &nbsp; &nbsp; := maxlength;<br> &nbsp; Form1.Font.Charset:=ARABIC_CHARSET ;<br> &nbsp; whdc:=form1.Canvas.handle;<br> &nbsp; //SetTextAlign(whDC, TA_LEFT or TA_RTLREADING);<br> &nbsp; ret:=GetCharacterPlacement(whDC, Pchar(mess), 7, 0, &nbsp;m_gcp, 0);<br>...<br>end;
 
帖子被改了。
 
难道没人知道?!!<br>[:D] 第三次在这儿问。前两次都没人知道答案,自己找到了答案。。
 
不知道你那里怎么了,这段代码在我机器上正常执行,你可以在后面加上<br>一行看看什么错误<br> <br> &nbsp; ret:=GetCharacterPlacement(whDC, Pchar(mess), 7, 0, &nbsp;m_gcp, 0);<br> &nbsp; if ret = 0 then ShowMessage(SysErrorMessage(GetLastError));
 
我写的代码没问题<br>你把<br>whdc:=form1.Canvas.handle; 改为<br>whdc:=Getdc(form1.handle); <br>看看有没有错?<br>我早就用了<br>if ret = 0 then ShowMessage(SysErrorMessage(GetLastError));<br>是122错误<br>“传递给系统调用的数据区域太小“
 
function MyFunction(): String;<br>var<br> &nbsp;dc: HDC;<br> &nbsp;GCP: TGCPResults;<br> &nbsp;ret,i:integer;<br> &nbsp;m_glyphs : array[0..20]of UINT;<br> &nbsp;glfix:array[0..7]of UINT;<br> &nbsp;sText: String;<br>begin<br> &nbsp;Result := '';<br> &nbsp;Form1.Font.Name:='Andalus';<br> &nbsp;sText:='abc'#$c7#$c8#$c9#$ca;<br> &nbsp;SetLength(Result, Length(sText));<br> &nbsp;GCP.lStructSize := sizeof(TGCPResults);<br> &nbsp;GCP.lpOutString := PChar(Result);<br> &nbsp;GCP.lpOrder := nil;<br> &nbsp;GCP.lpDx := nil;<br> &nbsp;GCP.lpCaretPos := nil;<br> &nbsp;GCP.lpClass := nil;<br> &nbsp;GCP.lpGlyphs := @m_glyphs;<br> &nbsp;GCP.nGlyphs := Length(sText);<br> &nbsp;GCP.nMaxFit := 0;<br> &nbsp;DC := Form1.Canvas.Handle;<br> &nbsp;GetCharacterPlacement(dc,<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;PChar(sText),<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;Length(sText),<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;512,<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;GCP,<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;0);<br><br> &nbsp;if ret&lt;&gt;0 then<br> &nbsp;for i:=0 to 6 do<br> &nbsp;begin<br> &nbsp; &nbsp;glfix:= PUINT(ULONG(GCP.lpGlyphs)+(i*2))^ and $FFFF;<br> &nbsp; &nbsp;//i*2 why 2? ;)<br> &nbsp; &nbsp;showmessage(inttostr(glfix));<br> &nbsp;end;<br> &nbsp;ReleaseDc(form1.Handle, DC);<br> &nbsp;Result := Copy(Result, 1, Length(sText));<br>end;<br>以上的代码运行后输出的是<br>68,69,70,346,349,352,355 就是sText字符的glyphindex(当字体是&quot;Andalus&quot;,如果是其它字体值不一定一样)。这个都没错<br>问题呢?<br>当我们把<br>DC := Form1.Canvas.Handle;<br>改为<br>DC := Getdc(Form1.Handle);<br>结果就不对?<br>据我的观察,用Getdc(Form1.Handle);得到的HDC没有Form1.Canvas.Handle所拥有的图形对象比如HFONT..<br>*** 如果用selectobject(dc,HGDIOBJ(form1.Canvas.Font.Handle));得到的结果跟上面一样<br>该怎么解决这个问题?<br>主要是:<br>如果我们有一个窗体的handle(另外个程序的)怎么取得正确的结果?
 
奇怪!<br>没人回答!<br>几分不够的话可以加。。
 
正在抽空看VCL代码,[:(]
 
后退
顶部