精简版开发工具使用手记2(图解)
四 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文件;
總結
以上是生活随笔為你收集整理的精简版开发工具使用手记2(图解)的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 图解MyEclipse用DB Brows
- 下一篇: C语言实现压缩二例