| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 5435 人关注过本帖
标题:用C语言编写具有图形界面的小游戏用什么编译器好?
只看楼主 加入收藏
雪狼MJ
Rank: 8Rank: 8
来 自:甘肃
等 级:蝙蝠侠
威 望:4
帖 子:267
专家分:853
注 册:2012-5-27
结帖率:100%
收藏
已结贴  问题点数:20 回复次数:5 
用C语言编写具有图形界面的小游戏用什么编译器好?
这一学期学了C语言的基础,现在可以用C编写可以处理数据的小程序了,但一直没有编过有图形界面的程序
一直在用C-Free编译器,这个适用于初学者,容易上手嘛。
但现在想编有图形界面的程序了,感觉这个编译器不怎么好用了,这个编译器能编有图形界面的程序吗?有什么编译器更好呢?
老鸟们,求推荐!!!
搜索更多相关主题的帖子: 图形 编译器 C语言 
2012-07-08 09:18
jokerskill
Rank: 7Rank: 7Rank: 7
等 级:黑侠
帖 子:392
专家分:554
注 册:2012-3-4
收藏
得分:5 
你的贴怎么跑到这里来了???跳到顶上的贴是怎么发的???

2012-07-08 19:30
hellovfp
Rank: 16Rank: 16Rank: 16Rank: 16
等 级:禁止访问
威 望:30
帖 子:2976
专家分:7697
注 册:2009-7-21
收藏
得分:15 
偶测试了一下,可以把下面的三行拷到一个bat文件中,再把这个文件拷到cfree/mingw目录中。
然后进入cfree/mingw目录,运行一下这个bat批处理。

@echo.
@echo Setting up environment for using MinGW with GCC from %~dp0.
@set PATH=%~dp0bin;%PATH%

最后用命令行gcc -mwindows main.c -o main.exe可以编译下面的代码:

可以考虑换成codeblocks/codelite,都是同样的编译器,在库的支持上比c-free要好,c-free中添加libgdi32.a会出问题。

#include <windows.h>
#include <stdio.h>
#include <conio.h>
#include <stdlib.h>
#include <time.h>

//////////////////////////////////////////////////
//模拟库中的inigraph, closegraph, lineto函数
void init_graphics(int width, int height);
void close_graphics();
void draw_line(int x, int y, int x1, int y1, COLORREF color);

unsigned long _stdcall ThreadFunc(void *);
LRESULT CALLBACK main_proc(HWND, UINT, WPARAM, LPARAM);

//////////////////////////////////////////////////
HANDLE hwin_main;
DWORD ThreadID;
HWND hwnd_main;
HDC hdc_main;
HDC hdc_buff = 0;
HBITMAP hmap = 0;
int main_w, main_h;
UINT draw_timer;
HWND console;

/////////////////////////////////////////////////////////////////////////
// 模拟EasyX的Graphics图形库运行流程,主函数看着是不是有点TC代码的熟悉?
/////////////////////////////////////////////////////////////////////////
int main()
{
    int i;

    init_graphics(640, 480);
    srand( time(NULL) );
   
    for(i = 0; i < 120; i++)
    {
        draw_line(200, 200, rand()% 640 - (rand() % 100), rand() % 480 + rand() % 100, RGB(70, 40, 128));
        Sleep(20);
    }

    draw_line(30, 30, 100, 100+i, RGB(255, 0, 128));
    draw_line(40, 130, 100, 100+i, RGB(255, 0, 128));

    printf("start waitting.....\n");
    WaitForSingleObject(hwin_main, INFINITE);
    printf("waitting end.....\n");

    close_graphics();
    return 0;
}

unsigned long _stdcall ThreadFunc(void *lpvoid)
{
    MSG msg;
    WNDCLASS wnd;

    memset(&wnd, 0, sizeof(wnd));
    wnd.hbrBackground = (HBRUSH) GetStockObject(BLACK_BRUSH);
    wnd.hCursor = LoadCursor(NULL, IDC_ARROW);
    wnd.hInstance = GetModuleHandle(NULL);
    wnd.lpfnWndProc = main_proc;
    wnd.lpszClassName = "EasyWindow";
    wnd.style = CS_HREDRAW | CS_VREDRAW;

    if(! RegisterClass(&wnd) ) fprintf(stderr, "register class error!\n");

    hwnd_main = CreateWindow("EasyWindow", "EasyWindow Create",
                WS_OVERLAPPEDWINDOW,
                10, 10, main_w, main_h,
                NULL,
                NULL,
                wnd.hInstance,
                0);
    if(! hwnd_main ) fprintf(stderr, "Create windows error!\n");

    ShowWindow(hwnd_main, SW_SHOWNORMAL);
    UpdateWindow(hwnd_main);

    hdc_main = GetDC(hwnd_main);
    hdc_buff = CreateCompatibleDC(NULL);
    hmap = CreateCompatibleBitmap(hdc_main, main_w, main_h);
    SelectObject(hdc_buff, hmap);
    ReleaseDC(hwnd_main, hdc_main);

    SetTimer(hwnd_main, draw_timer, 30, NULL);

    while(GetMessage(&msg, NULL, 0, 0) > 0)
    {
        TranslateMessage(&msg);
        DispatchMessage(&msg);
    }
   
    return 0;
}

LRESULT CALLBACK main_proc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
{
    PAINTSTRUCT ps;
    HDC hdc;

    switch(uMsg)
    {
        case WM_CHAR:
            //SendMessage(console, WM_CHAR, wParam, lParam);
        case WM_DESTROY:
            DeleteDC(hdc_buff);
            DeleteObject(hmap);
            KillTimer(hwnd_main, draw_timer);
            PostQuitMessage(0);
            break;
        case WM_TIMER:
            InvalidateRect(hwnd_main, NULL, FALSE);
            break;
        case WM_PAINT:
            hdc = BeginPaint(hwnd, &ps);
            BitBlt(hdc, 0, 0, main_w, main_h, hdc_buff, 0, 0, SRCCOPY);
            EndPaint(hwnd, &ps);
            break;
        default:
            return DefWindowProc(hwnd, uMsg, wParam, lParam);
    }
    return 0;
}

void init_graphics(int width, int height)
{
    main_w = width;
    main_h = height;
    hwin_main=CreateThread(NULL,0,
                ThreadFunc,NULL,
                0,&ThreadID);

    Sleep(20);
    /* 下面这段可以隐藏控制台窗口 */
    console = FindWindow("ConsoleWindowClass", NULL);
    if(console)
        ShowWindow(console, SW_HIDE);
    else
        fprintf(stderr, "can't find console windows\n");

}

void close_graphics()
{
    CloseHandle(hwin_main);
    ShowWindow(console, SW_SHOWNORMAL);
}

void draw_line(int x, int y, int x1, int y1, COLORREF color)
{
    HPEN pen, old_pen;

    pen = CreatePen(PS_SOLID, 2, color);
    old_pen = (HPEN) SelectObject(hdc_buff, pen);
    MoveToEx(hdc_buff, x, y, NULL);
    LineTo(hdc_buff, x1, y1);
    DeleteObject(old_pen);
}

[ 本帖最后由 hellovfp 于 2012-7-9 13:01 编辑 ]

我们都在路上。。。。。
2012-07-09 11:43
二少爷
Rank: 1
等 级:新手上路
帖 子:1
专家分:0
注 册:2012-7-23
收藏
得分:0 
... ...
2012-07-24 00:22
Agdmeg
Rank: 4
来 自:四川成都
等 级:业余侠客
威 望:3
帖 子:101
专家分:201
注 册:2011-8-9
收藏
得分:0 
Tc可以
2012-08-16 12:53
c简
Rank: 1
等 级:新手上路
帖 子:1
专家分:0
注 册:2012-10-30
收藏
得分:0 
turbo c 3.0挺好的哇!
2012-10-30 21:52
快速回复:用C语言编写具有图形界面的小游戏用什么编译器好?
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.021858 second(s), 7 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved