vc 画点 画线 

#include <windows.h>
#include <tchar.h>

// Global Variables:
HINSTANCE hInst;      // current instance
TCHAR szTitle[]="aa";     // The title bar text
TCHAR szWindowClass[]="WinApp";     // the class name

// Foward declarations of functions included in this code module:
ATOM     MyRegisterClass(HINSTANCE hInstance);
BOOL     InitInstance(HINSTANCE, int);
LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM);


int APIENTRY WinMain(HINSTANCE hInstance,
                      HINSTANCE hPrevInstance,
                      LPSTR      lpCmdLine,
                      int        nCmdShow)
{
   // TODO: Place code here.
MSG msg;

// Register Class
MyRegisterClass(hInstance);

// Perform application initialization:
if (!InitInstance (hInstance, nCmdShow))
{
   return FALSE;
}

// Main message loop:
while (GetMessage(&msg, NULL, 0, 0))
{
   TranslateMessage(&msg);
   DispatchMessage(&msg);
}

return msg.wParam;
}

 

//
//   FUNCTION: MyRegisterClass()
//
//   PURPOSE: Registers the window class.
//
//   COMMENTS:
//
//     This function and its usage is only necessary if you want this code
//     to be compatible with Win32 systems prior to the 'RegisterClassEx'
//     function that was added to Windows 95.
//
ATOM MyRegisterClass(HINSTANCE hInstance)
{
WNDCLASSEX wcex;

wcex.cbSize = sizeof(WNDCLASSEX);

wcex.style    = CS_HREDRAW | CS_VREDRAW;
wcex.lpfnWndProc = (WNDPROC)WndProc;
wcex.cbClsExtra   = 0;
wcex.cbWndExtra   = 0;
wcex.hInstance   = hInstance;
wcex.hIcon    = LoadIcon (NULL, IDI_APPLICATION);
wcex.hCursor   = LoadCursor(NULL, IDC_ARROW);
wcex.hbrBackground = (HBRUSH)(COLOR_WINDOW+1);
wcex.lpszMenuName = NULL;
wcex.lpszClassName = szWindowClass;
wcex.hIconSm   = LoadIcon (NULL, IDI_APPLICATION);

return RegisterClassEx(&wcex);
}

//
//    FUNCTION: InitInstance(HANDLE, int)
//
//    PURPOSE: Saves instance handle and creates main window
//
//    COMMENTS:
//
//         In this function, we save the instance handle in a global variable and
//         create and display the main program window.
//
BOOL InitInstance(HINSTANCE hInstance, int nCmdShow)
{
    HWND hWnd;

    hInst = hInstance; // Store instance handle in our global variable

    hWnd = CreateWindow(szWindowClass, szTitle, WS_OVERLAPPEDWINDOW,
       CW_USEDEFAULT, 0, CW_USEDEFAULT, 0, NULL, NULL, hInstance, NULL);

    if (!hWnd)
    {
       return FALSE;
    }

    ShowWindow(hWnd, nCmdShow);
    UpdateWindow(hWnd);

    return TRUE;
}

//
//   FUNCTION: WndProc(HWND, unsigned, WORD, LONG)
//
//   PURPOSE:   Processes messages for the main window.
//
//   WM_COMMAND - process the application menu
//   WM_PAINT - Paint the main window
//   WM_DESTROY - post a quit message and return
//
//
LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
{
PAINTSTRUCT ps;
HDC hdc;
RECT rt;
char szHello[]="Hello, C-Free!";
rt.left= 100;
rt.top = 300;
rt.bottom= 300;
rt.right= 300;


switch (message)
{
   case WM_PAINT:
    hdc = BeginPaint(hWnd, &ps);
    // TODO: Add any drawing code here...
   
    GetClientRect(hWnd, &rt);
  
    DrawText(hdc, szHello, strlen(szHello), &rt, NULL);
   
    //下面是画矩形
   
   
   
   
    Rectangle( hdc, 40, 100, 40+200, 100+50 );
   
   
    ///下面是椭圆
    Ellipse( hdc, 40, 200, 40+200, 200+50 );
   
    //下面是直线
     MoveToEx( hdc, 0, 600, NULL );
               LineTo( hdc, 800, 0 );
              
              
               下面是画点
               int i ;
               for (i= 0 ;i <300 ; i= i +10)
     {   SetPixel( hdc, 200+ i, 200, RGB(0,0,0) );
                SetPixel( hdc, 200+ i+1, 200, RGB(0,0,0) );
                SetPixel( hdc, 200+ i+1, 200+1, RGB(0,0,0) );
                //多画几个点好看得清
     }
               ///
   
    EndPaint(hWnd, &ps);
    break;
   case WM_CLOSE:
    DestroyWindow(hWnd);
    break;
   case WM_DESTROY:
    PostQuitMessage(0);
    break;
   default:
    return DefWindowProc(hWnd, message, wParam, lParam);
}
return 0;
}

  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 2
    评论
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值