トップページ > 記事閲覧
GetDrawFormatStringWidthの値
名前:ひる 日時: 2014/04/21 16:21

GetDrawFormatStringWidthを使用して文字列を右揃えをしようと思ったのですが上手く揃いません。 例 DrawFormatStringToHandle( 400 - GetDrawFormatStringWidth( "%d", 1 ), 0, GetColor( 0, 0, 0 ), font_handle, "%d", 1 ); DrawFormatStringToHandle( 400 - GetDrawFormatStringWidth( "%d", 12 ), 20, GetColor( 0, 0, 0 ), font_handle, "%d", 12 ); DrawFormatStringToHandle( 400 - GetDrawFormatStringWidth( "%d", 123 ), 40, GetColor( 0, 0, 0 ), font_handle, "%d", 123 ); DrawFormatStringToHandle( 400 - GetDrawFormatStringWidth( "%d", 123456789 ), 0, GetColor( 0, 0, 0 ), font_handle, "%d", 123456789 ); DrawFormatStringToHandle( 400 - GetDrawFormatStringWidth( "%s", "テスト" ), 60, GetColor( 0, 0, 0 ), font_handle, "%d", "%s", "テスト" ); ※フォントサイズ:16、フォント名:メイリオ 上記のコードだと各行の右端がX:400に揃うと思っていたのですが、 実際には文字列のサイズが長くなるほど右側に微妙にずれていってます。 もし右揃えのやり方が良くないのであれば、上手く行く方法を教えて頂けたらありがたいです。 よろしくお願いします。
メンテ

Page: 1 |

Re: GetDrawFormatStringWidthの値 ( No.1 )
名前:takatwu 日時:2014/04/21 20:18

GetDrawFormatStringWidthでは作成したフォントハンドルに対応しません。 上記関数ではデフォルトのフォントで描画する文字列分の横幅値が返ってくるため font_handleで指定したフォントが違うとズレてしまいます。 int GetDrawStringWidthToHandle( char *String, int StrLen, int FontHandle ) ; int GetDrawFormatStringWidthToHandle( int FontHandle, char *FormatString, ... ) ; などのフォントハンドルを指定するタイプのものを使用してください。
メンテ
Re: GetDrawFormatStringWidthの値 ( No.2 )
名前:ひる(解決) 日時:2014/04/22 01:10

あ、GetDrawFormatStringWidthToHandleがあったのですね。 失念してました。 ありがとうございます。
メンテ

Page: 1 |

題名
名前
コメント
パスワード (記事メンテ時に使用)

   クッキー保存