あるデータを用いて円を描画したく、Ellipse関数に読み込んだデータの値を配列(x[0])として入れたところ、ビルドはできるのですが円が描画されません。x[0]=1.47であるので、1.47を直接Ellipse関数に入れて実行させたところ、円が描画されました。配列を用いて描画したいです。分かる方いましたらよろしくお願いいたします。以下が円(楕円)を描画するコードの一部です。ブレークポイントで確かめたところ、配列に入っている値は0でした。同じプロジェクト中の別のソースファイルでx[i]の色々な値読み込みは成功しています。ですが、そのx[i]を以下のソースファイルにも使いたいです。
コード
'''
#include "kobayashi.h"
#include "time.h"
//月を描画するウィンドウのウィンドウプロシージャ
LRESULT CALLBACK WndProc2( HWND hWnd2, UINT msg, WPARAM wp, LPARAM lp )
{
PAINTSTRUCT ps;
HDC hdc;
HPEN hPen,h01dPen;
HBRUSH hBrush, h01dBrush;
RECT rect;
switch (msg) { case WM_PAINT: hdc = BeginPaint(hWnd2, &ps); Ellipse(hdc,0 , 0, x[0]/2*226.5+0.5, x[0]/2*226.5+0.5 ); hPen = CreatePen(PS_DOT, 0, RGB(255, 0, 0)); h01dPen = (HPEN)SelectObject(hdc, hPen); hBrush = (HBRUSH)GetStockObject(NULL_BRUSH); h01dBrush = (HBRUSH)SelectObject(hdc, hBrush); DeleteObject(hPen); SelectObject(hdc, h01dPen); SelectObject(hdc, h01dBrush); EndPaint(hWnd2, &ps); break;
case WM_DESTROY:
PostQuitMessage(0);
break;
default: return (DefWindowProc(hWnd2, msg, wp, lp)); } return 0;
}'''
もう一つ、x[]を読み込んだプログラムを以下に表示します。
、、、
BOOL read_data( HWND hDlg, FILE *hm, int channel )
{
char cbuf[500]; // 1行分のデータを読み込む文字列
char *p, *context; // strtok_sを使うために必要
int i = 0;
static bool flag = TRUE;// 最初のデータの読み込み時はTRUE、後はFAULTにする int i = 0; while ( fgets( cbuf, 501, hm ) != NULL ){ // データを最後まで読み込む p = strtok_s( cbuf, ",", &context ); sscanf_s( p, "%f", &ET[i] ); p = strtok_s( NULL, ",", &context ); sscanf_s( p, "%f", &XEQL[i]); p = strtok_s( NULL, ",", &context ); sscanf_s( p, "%f", &YEQL[i]); p = strtok_s( NULL, ",", &context ); sscanf_s( p, "%f", &ZEQL[i]); p = strtok_s( NULL, ",", &context ); sscanf_s( p, "%f", &VXEQL[i]); p = strtok_s( NULL, ",", &context ); sscanf_s( p, "%f", &VYEQL[i]); p = strtok_s( NULL, ",", &context ); sscanf_s( p, "%f", &VZEQL[i]); p = strtok_s( NULL, ",", &context ); sscanf_s( p, "%f", &XSUN[i]); p = strtok_s( NULL, ",", &context ); sscanf_s( p, "%f", &YSUN[i]); p = strtok_s( NULL, ",", &context ); sscanf_s( p, "%f", &ZSUN[i]); p = strtok_s( NULL, ",", &context ); sscanf_s( p, "%f", &VXSUN[i]); p = strtok_s( NULL, ",", &context ); sscanf_s( p, "%f", &VYSUN[i]); p = strtok_s( NULL, ",", &context ); sscanf_s( p, "%f", &VZSUN[i]); p = strtok_s( NULL, ",", &context ); sscanf_s( p, "%f", &XMOON[i]); p = strtok_s( NULL, ",", &context ); sscanf_s( p, "%f", &YMOON[i]); p = strtok_s( NULL, ",", &context ); sscanf_s( p, "%f", &ZMOON[i]); p = strtok_s( NULL, ",", &context ); sscanf_s( p, "%f", &VXMOON[i]); p = strtok_s( NULL, ",", &context ); sscanf_s( p, "%f", &VYMOON[i]); p = strtok_s( NULL, ",", &context ); sscanf_s( p, "%f", &VZMOON[i]); EQL_MOON[i] = sqrtf((XMOON[i]-XEQL[i])*(XMOON[i]-XEQL[i]) + (YMOON[i]-YEQL[i])*(YMOON[i]-YEQL[i]) + (ZMOON[i]-ZEQL[i])*(ZMOON[i]-ZEQL[i]));
x[i] = (0.00005*1737)/(EQL_MOON[i]-50);
i++;
} SetDlgItemInt( hDlg, IDC_EDIT_header1, total_n, FALSE ); if ( flag == TRUE ){ SetDlgItemInt( hDlg, IDC_EDIT_STOP, total_n-1, FALSE ); // 全体表示する場合の最後のサンプル番号が決まる SetDlgItemInt( hDlg, IDC_EDIT_START, 0, FALSE ); // 最初のサンプル番号は0にしておく flag = FALSE; } return TRUE; // 戻り値TRUEを返す
}、、、
回答3件
あなたの回答
tips
プレビュー