您的位置:首页 > 其它

精简版开发工具使用手记2(图解)

2016-08-29 21:47 246 查看

四 C-Free

    下载C-Free 5.0,其安装包大小为14M。安装;运行后弹出如下界面;



    可见该软件自带有四个C程序模板:标准C和C++的Hello程序;简单Windows应用程序;简单dll程序;

    选中第一个CHello.c,双击后进入编辑窗口,出现一个标准C的Hello World;

#include <stdio.h>

int main()

{

    printf("Hello World!\n");

    return 0;

}

点击Run, 运行后出现下图;



可见该软件自带了编译器;由窗口左上角的提示可见,自带的编译器为mingw5;通过配置可配合不同的C/C++编译器使用;

下面来开发一个Windows API的应用程序,点击鼠标左键时,在窗口上画一条正弦曲线;

打开该工具,新建一个简单Windows应用程序,出现一个标准Win32 SDK的窗口程序的代码;

把窗口背景改为亮灰;

在鼠标左键单击时获取设备描述表,用SetPixel函数画正弦曲线;

全部代码如下;

#include <windows.h>

#include <math.h>

LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM);   /* Declare Windows procedure */

char szClassName[ ] = "WindowsApp";   /* Class Name */

int WINAPI WinMain(HINSTANCE hThisInstance,

                   HINSTANCE hPrevInstance,

                   LPSTR lpszArgument,

                   int nFunsterStil)

{

    HWND hwnd;               /* This is the handle for our window */

    MSG messages;            /* Here messages to the application are saved */

    WNDCLASSEX wincl;        /* Data structure for the windowclass */

    /* The WNDCLASSEX structure */

    wincl.hInstance = hThisInstance;

    wincl.lpszClassName = szClassName;

    wincl.lpfnWndProc = WndProc;      /* This function is called by windows */

    wincl.style = CS_DBLCLKS;                 /* Catch double-clicks */

    wincl.cbSize = sizeof(WNDCLASSEX);

    wincl.hIcon = LoadIcon(NULL, IDI_APPLICATION);

    wincl.hIconSm = LoadIcon(NULL, IDI_APPLICATION);

    wincl.hCursor = LoadCursor(NULL, IDC_ARROW);

    wincl.lpszMenuName = NULL; /* No menu */

    wincl.cbClsExtra = 0;

    wincl.cbWndExtra = 0;

    wincl.hbrBackground = (HBRUSH) GetStockObject(LTGRAY_BRUSH);    //亮灰

    /* Register the window class, if fail quit the program */

    if(!RegisterClassEx(&wincl)) return 0;

    /* The class is registered, create the window*/

    hwnd = CreateWindowEx(

           0,

           szClassName,

           "Simple Windows App",

           WS_OVERLAPPEDWINDOW,

           CW_USEDEFAULT,

           CW_USEDEFAULT,

           CW_USEDEFAULT,

           CW_USEDEFAULT,

           HWND_DESKTOP,

           NULL,

           hThisInstance,

           NULL

           );

    /* Make the window visible on the screen */

    ShowWindow(hwnd, nFunsterStil);

    /* Run the message loop. It will run until GetMessage( ) returns 0 */

    while(GetMessage(&messages, NULL, 0, 0))

    {

           TranslateMessage(&messages);

           DispatchMessage(&messages);

    }

    /* The program return-value is 0 - The value that PostQuitMessage( ) gave */

    return messages.wParam;

}

/* This function is called by the Windows function DispatchMessage( ) */

LRESULT CALLBACK WndProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)

{
int x;
HDC hdc ;

    switch (message)                    /* handle the messages */

    {

        case WM_DESTROY:

            PostQuitMessage(0);         /* send a WM_QUIT to the message queue */

            break;

        case WM_LBUTTONDOWN:

        hdc = GetDC (hwnd);

        for(x=0;x<600;x++)
{
SetPixel(hdc,x,300-100*sin(6.28*x/200),RGB(0,255,0));
}

        break;

        case WM_MOUSEMOVE:

        break;

        default:                        /* for messages that we don't deal with */

            return DefWindowProc(hwnd, message, wParam, lParam);

    }

    return 0;

}

运行后结果如下;



    该程序还可以新建一个纯Win32 API的MDI程序模板,Good,不错;下面用新建的MDI模板做一个应用程序;在子窗口1中画正弦曲线,在子窗口2中输出一组正弦坐标值;

主要在MDI模板基础上添加的代码如下;

hdc = GetDC (hwnd);

        pDocData = (PDOCDATA) GetWindowLong (hwnd, 0);

        r=strcmp(pDocData->szFileTitle,"Untitled1");

        if(!r)

        {
for(x=0;x<600;x++)
{
SetPixel(hdc,x,300-100*sin(6.28*x/200),RGB(0,255,0));
}
}

r=strcmp(pDocData->szFileTitle,"Untitled2");

        if(!r)

        {
for(x=0;x<10;x++)
{
//SetPixel(hdc,x,300-100*sin(6.28*x/200),RGB(0,255,0));
TextOut (hdc, 10+x*40, 10, szBuffer,wsprintf (szBuffer, TEXT ("%5d"),(int)(300-100*sin(6.28*x/10)))) ;
}
}

运行后,结果如下;



还可以新建OpenGL,Qt类型的图形应用程序;

该工具适合学习C语言,Windows SDK编程, 开发Windows SDK应用程序、DLL程序,OpenGL和Qt等图形应用程序。

五 Pelles C

Pelles C是一款windows下的C IDE,支持调试,且为免费。

它有一个高效率的链接器,目前已被广泛采用为各种语言的后台链接器使用LCC作为编译器

并且完整支持win32编程,支持任何API调用,包含所有winAPI的库且含有完整 C Runtime Library。

安装后的开始菜单;



使用情况如下;











这货好像是不支持C++,只能用纯C;添加源文件时只能加.C文件;
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息