• 締切済み

色つきの円を描きたいです

色つきの円を描きたいです。 円の中心まで色を付きたいです。 出来ますか? おしえてください! お願いします。 この前教えたもらった方法でテストプログラム を作りましたが、実行不可能です。 絵を描くのが初めてですから、 サンプルを欲しいです。 お願いします。 #include <stdio.h> #include <string.h> #include <afxwin.h> void main( void ) { int X,Y,R; X=10; Y=20; R =100; Ellipse(X-R,Y-R, X+R, Y+R); }

みんなの回答

回答No.3

とりあえずサンプルです。 BCCで-Wオプションでコンパイルしてみました。VC++でもwindows用の設定にすればコンパイルできると思います。 #include <windows.h> LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM); void graph(HWND); int circle(HDC, int, int, int, int, int, int); int WINAPI WinMain(HINSTANCE hCurInst, HINSTANCE hPrevInst, LPSTR lpsCmdLine, int nCmdShow) { MSG msg; char szClassName[] = "grph02"; WNDCLASS wc; HWND hWnd; if (!hPrevInst) { wc.style = CS_HREDRAW | CS_VREDRAW; wc.lpfnWndProc = WndProc; wc.cbClsExtra = wc.cbWndExtra = 0; wc.hInstance = hCurInst; wc.hIcon = LoadIcon(NULL, IDI_APPLICATION); wc.hCursor = LoadCursor(NULL, IDC_ARROW); wc.hbrBackground = GetStockObject(BLACK_BRUSH); wc.lpszMenuName = NULL; wc.lpszClassName = (LPCSTR)szClassName; if (!RegisterClass(&wc)) return FALSE; } hWnd = CreateWindow( szClassName, "グラフィック", WS_OVERLAPPEDWINDOW, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, NULL, NULL, hCurInst, NULL); if (!hWnd) return FALSE; ShowWindow(hWnd, nCmdShow); UpdateWindow(hWnd); while (GetMessage(&msg, NULL, NULL, NULL)) { TranslateMessage(&msg); DispatchMessage(&msg); } return msg.wParam; } LRESULT CALLBACK WndProc(HWND hWnd, UINT msg, WPARAM wp, LPARAM lp) { int id; switch (msg) { case WM_PAINT: graph(hWnd); break; case WM_DESTROY: PostQuitMessage(0); break; default: return (DefWindowProc(hWnd, msg, wp, lp)); } return 0L; } /* グラフィック描画 */ void graph(HWND hWnd) { HDC hdc; PAINTSTRUCT ps; hdc = BeginPaint(hWnd, &ps); circle(hdc, 128,255,50, 100,150,80); EndPaint(hWnd, &ps); } /* 塗りつぶしの円 */ int circle(HDC hdc, int cr, int cg, int cb, int x, int y, int r) { HPEN hPen, hOldPen; HBRUSH hBrush, hOldBrush; /* ペン */ hPen = CreatePen(PS_SOLID, 1, RGB(cr, cg, cb)); hOldPen = SelectObject(hdc, hPen); /* ブラシ */ hBrush = CreateSolidBrush(RGB(cr, cg, cb)); hOldBrush = SelectObject(hdc, hBrush); /* 円 */ Ellipse(hdc, x-r, y-r, x+r, y+r); /* あとしまつ */ SelectObject(hdc, hOldPen); DeleteObject(hBrush); SelectObject(hdc, hOldBrush); DeleteObject(hPen); return 0; }

2003saki
質問者

お礼

ご回答、ありがとうございます。 コンパイルして、エラーが下記の通りです。 testofcircle.cpp c:\documents and settings\ryu\my documents\fs\temp\testofcircle.cpp(12) : error C2440: '=' : 'void *' から 'struct HBRUSH__ *' に変換することはできません。(新しい動作 ; ヘルプを参照) 'void*' から非 'void' 型への変換には明示的なキャストが必要です。 c:\documents and settings\ryu\my documents\fs\temp\testofcircle.cpp(57) : error C2440: '=' : 'void *' から 'struct HPEN__ *' に変換することはできません。(新しい動作 ; ヘルプを参照) 'void*' から非 'void' 型への変換には明示的なキャストが必要です。 c:\documents and settings\ryu\my documents\fs\temp\testofcircle.cpp(60) : error C2440: '=' : 'void *' から 'struct HBRUSH__ *' に変換することはできません。(新しい動作 ; ヘルプを参照) 'void*' から非 'void' 型への変換には明示的なキャストが必要です。 cl.exe の実行エラー testofcircle.exe - エラー 3、警告 0 どうやって治ります? 教えてください! お願いします。

全文を見る
すると、全ての回答が全文表示されます。
  • sha-girl
  • ベストアンサー率52% (430/816)
回答No.2

>LIBCD.lib(crt0.obj) : error LNK2001: 外部シンボル "_main" は未解決です コンソールプログラムでコンパイルしようとしているからです。 プロジェクトオプションのところで /subsystem:console を /subsystem:windows に変えてください。

参考URL:
http://www.doumo.jp/postgretips/tips.jsp?tips=12
2003saki
質問者

お礼

ご回答、ありがとうございます。 うまくいけません。

全文を見る
すると、全ての回答が全文表示されます。
  • sha-girl
  • ベストアンサー率52% (430/816)
回答No.1

Ellipseはwindows.hが必要です。#include <windows.h> ウインドウのサンプルならあります。 「猫でもわかるプログラミング」が有名です。 http://www.kumei.ne.jp/c_lang/sdk/sdk_25.htm http://www.doumo.jp/postgretips/tips.jsp?tips=13 のソースのswitch( message )の下に case WM_PAINT: { PAINTSTRUCT ps; int X,Y,R; HDC hDC = BeginPaint(hWnd,&ps); X=10; Y=20; R =100; Ellipse( hDC,X-R,Y-R, X+R, Y+R); } break; を追加してください。 使っているコンパイラはなんだかわからないですが BCCなら http://www.kumei.ne.jp/c_lang/bcc/index.html を参考にしてください。 ちなみにVC++も無償のものがあります。 http://msdn.microsoft.com/visualc/vctoolkit2003/

参考URL:
http://www.kumei.ne.jp/c_lang/
2003saki
質問者

お礼

ご回答、ありがとうございます。 早速sampleを使ってみましたが、 VC++ 6.00を使っています。 下記のエラーがでました。 ************** リンク中... LIBCD.lib(crt0.obj) : error LNK2001: 外部シンボル "_main" は未解決です Debug/testofcircle.exe : fatal error LNK1120: 外部参照 1 が未解決です。 link.exe の実行エラー ****************** なぜですか? 教えてください! お願いします。

全文を見る
すると、全ての回答が全文表示されます。

関連するQ&A

  • このソースは間違っていますか?

    ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ #include<stdio.h> #include<stdlib.h> #define MAXLINE 256 int main(void); int main(void) { char buffer[MAXLINE]; int x; int y; char a; char b; printf("一人目の名前を英数字で入力してください。\n"); gets(buffer); a = at

  • Cの九九を表示するプログラムについて

    九九の表示を変えたいんですけど #include <stdio.h> int main(void) { int x,y; for (x = 1;x <= 9;x++) { for (y = 1;y <= 9;y++) { printf(" %2d ", x * y); } printf("\n"); } return 0; } これを実行すると 1 2 3 4 5 6 7 8 9 2 4 6 8 10 12 14 16 18 . . 9 . . . . . . . 81 となるのですが、これを 1 * 1 1 * 2 1 * 3 . . . 1 * 9 1 * 2 . . 1 * 9 . . . . . 9 * 9 と表示させたいのですがどなたか知恵を貸していただきませんでしょうか?

  • C言語のポインタの考え方について

    ポインタについて理解ができていないのでお聞きしたいのですが 値を交換する関数のプログラミングでこの場合ポインタ で以下にしないといけないと思います。 #include<stdio.h> void swap(int *a int *b){ int c; c=*a; *a=*b; *b=c; } main(){ int x,y; x=123; y=456; swap(&x,&y); printf("x = %d, y = %d\n", x, y); } またポインタを使用せず以下のプログラムではなぜダメのでしょうか。 よろしくお願い致します。 #include<stdio.h> void swap(int a int b){ int c; c=a; a=b; b=c; } main(){ int x,y; x=123; y=456; swap(x,y); printf("x = %d, y = %d\n", x, y); }

  • ファイル分割について

    今本をみながら練習中なのですが、ファイル分割がうまくいきません。以下のような3つのプログラムをかいたのですが実行できません。 (一つ目:myfunc.h) int max(int x,int y); (二つ目:myfunc.c) int max(int x,int y){ if(x > y) return x; else return y;} (三つ目:sample.c) #include <stdio.h> #include "myfunc.h" int main(void){ int x,y,c; printf("1番目の整数\n"); scanf("%d",&x); printf("2番目の整数\n"); scanf("%d",&y); c = max(x,y); printf("最大値は%d\n",c); return 0;} すべてコンパイルしてsample.cを実行してもだめでした。ご指導お願いします><

  • c言語

    #include<stdio.h> main(void) { int x; double y,sum; void p(double *); for(sum=0.0,x=1;x<10;x++){ sum+=1.0/p(&x); ここでエラーがでます。 } printf("%d\n",sum); } void p(double *y) { *y*=*y; } どうしてエラーがでるかわかりません。教えてください!

  • C言語の質問です。

    #include"stdio.h" int main(void){ int a, b, add; scanf_s("%d%d", &a, &b); add = a+b; printf("add=%d\n", add); return 0; } と、------------------------------------------------------------------------------ #include"stdio.h" int tasizan(int x, int y); int main(void){ int a, b, add; scanf_s("%d%d", &a, &b); add = tasizan(a, b); printf("add=%d\n", add); return 0; } int tasizan(int x, int y){ int aa; aa = x + y; return aa; } の違いを教えてください。

  • 配列について

    初歩的な質問ですいませんが、質問よろしくお願いします。 ◎1----------------------------- #include<stdio.h> int main(void) { char ss[10]="AB"; printf("ss=%s\n",ss); return 0; } ------------------------------------ ◎2-------------------------------- #include<stdio.h> int main(void) { char ss[10]; ss[0]='A'; ss[1]='B'; ss[2]=0; printf("ss=%s\n",ss); return 0; } ----------------------------------- ◎3------------------------------- #include<stdio.h> #include<string.h> int main(void) { char ss[10]; strcpy(ss,"AB"); printf("ss=%s\n",ss); return 0; } ----------------------------------- ◎4------------------------------- #include<stdio.h> int main(void) { char ss[10]; ss="AB"; printf("ss=%s\n",ss); return 0; } ---------------------------------- 以上4つのプログラムで、◎2と◎3は正常に動くと理解できたのですが、何故、◎1は正常に動き、◎4は「'const char [3]' から 'char [10]' に変換できません。」といったようなエラーが出てしまうか分かりません。 教えていただければ嬉しいです。

  •  現在、私はC言語を学んでいます。

     現在、私はC言語を学んでいます。  プログラミングの初期の初期の問題なんですが、 「Hello World」という有名なプログラムがありますよね? それについての質問です。 #include<stdio.h> main() { printf("Hello World"); return 0; } も #include<stdio.h> main(void) { printf("Hello World"); return 0; } も #include<stdio.h> int main() { printf("Hello World"); } もちゃんと表示できます。 ここで質問です。 int main(void) int main() main() main(void) はどう違うんですか? あと、 return 0; はあっても無くてもいいようなんですが どういう意味があるんでしょうか?

  • callocで二次元配列を作成するには?

    今、動的オブジェクトの勉強をしております。 動的の一次元配列の作り方として #include <stdio.h> #include <stdlib.h> int main(void) {    int *a;    int x;    printf("配列の大きさX入力>");    scanf("%d",&x);    a=calloc(x,sizeof(int));    return (0); } これでいいと思うんですが動的な2次元配列を 作りたいときはどのようにすればよろしいのでしょうか? (↓作りたい二次元配列の例(1)↓) int main(void) {    int *a;    int x , y;    printf("配列の大きさX入力>");    scanf("%d",&x);         //5と入力    printf("配列の大きさY入力>");    scanf("%d",&y);         //10と入力    上のように入力するとa[5][10]という配列が完成する } よろしくお願いします

  • 配列について

    Visual c++なのですが #include<stdio.h> #include<stdlib.h> int main(){ FILE *fin,*fout; int HAP[135135][14];   long i,j; long x=135135,y=14; ・・・ のときは実行可能なのですが、 #include<stdio.h> #include<stdlib.h> int main(){ FILE *fin,*fout; int HAP[135135][14];   long i,j; long x=135135,y=14; ・・・ のときはビルトは可能できますが、デバックすると動作を停止してしまいます。なぜできないのかわからないで悩んでいます。是非教えてください。 ・・・の部分はほぼ同文です