Chinaunix首页 | 论坛 | 博客
  • 博客访问: 1063270
  • 博文数量: 284
  • 博客积分: 8223
  • 博客等级: 中将
  • 技术积分: 3188
  • 用 户 组: 普通用户
  • 注册时间: 2008-12-01 13:26
文章分类

全部博文(284)

文章存档

2012年(18)

2011年(33)

2010年(83)

2009年(147)

2008年(3)

分类: C/C++

2010-03-31 22:07:57

#include <windows.h>
#include <stdio.h>
#include <TCHAR.h>
#include <string.h>

LRESULT CALLBACK WinSunProc(
    HWND    hwnd,
    UINT    uMsg,
    WPARAM    wParam,
    LPARAM    lParam
    );

int WINAPI WinMain(
    HINSTANCE hInstance,
    HINSTANCE hPrevInstance,
    LPSTR     lpCmdLine,
    int nCmdShow
    )
{    
    WNDCLASS wndcls;
    wndcls.cbClsExtra = 0;
    wndcls.cbWndExtra = 0;
    wndcls.hbrBackground = (HBRUSH) GetStockObject(WHITE_BRUSH);
    wndcls.hIcon = LoadIcon (NULL,IDI_ERROR);
    wndcls.hCursor = LoadCursor (NULL,IDC_CROSS);
    wndcls.hInstance = hInstance;
    wndcls.lpfnWndProc = WinSunProc;    //这个是什么函数?自己写的吗?

    wndcls.lpszClassName = _T("cj");
    wndcls.style = CS_HREDRAW | CS_VREDRAW;
    wndcls.lpszMenuName = NULL;

    RegisterClass(&wndcls);    //注册窗口类


    HWND hwnd;
    hwnd = CreateWindow (_T("cj"),_T("cj"), WS_OVERLAPPEDWINDOW, 0, 0, 600, 400, NULL, NULL, hInstance, NULL );
    ShowWindow (hwnd, SW_SHOWNORMAL);
    UpdateWindow (hwnd);

    MSG msg;
    while (GetMessage (&msg, NULL, 0, 0 ))
    {
        TranslateMessage (&msg);
        DispatchMessage (&msg);
    }//endof while

    return 0;



}    //endof winMain()




LRESULT CALLBACK WinSunProc(
    HWND    hwnd,
    UINT    uMsg,
    WPARAM    wParam,
    LPARAM    lParam
    )
{
    switch(uMsg)
    {
    case WM_CHAR:
        char szChar[20];
        sprintf (szChar , "char is %d",wParam);
        MessageBox(hwnd,_T(""),_T("wenxin"),0);
        break;
    case WM_LBUTTONDOWN:
        MessageBox(hwnd,_T("mouse clicked"),_T("wenxin"),0);
        HDC hdc;
        hdc = GetDC(hwnd);
        TextOut (hdc,0,50,_T("like you"),strlen("like you"));
        ReleaseDC (hwnd,hdc);
        break;
    case WM_PAINT:
        HDC hDC;
        PAINTSTRUCT ps;
        hDC = BeginPaint(hwnd,&ps);
        TextOut(hDC,0, 0, _T("我的第一个程序"),lstrlen(_T("我的第一个程序")));
        EndPaint(hwnd,&ps);
        break;
    case WM_CLOSE:
        if(IDYES == MessageBox(hwnd,_T("是否真的结束?"),_T("要退出第一个写的程序吗?"),MB_YESNO))
        {
            DestroyWindow(hwnd);
        }//ENDOF IF

        break;
    case WM_DESTROY:
        PostQuitMessage(0);

        break;
    default:
        return DefWindowProc(hwnd,uMsg, wParam, lParam);
    }//endof swith()


    return 0;
}


阅读(806) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~