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

LRESULT CALLBACK WinProc(    HWND hwnd,      // handle to window
                                UINT uMsg,      // message identifier
                                WPARAM wParam,  // first message parameter
                                LPARAM lParam   // second message parameter
  );
int WINAPI WinMain(  HINSTANCE hInstance,      // handle to current instance
                     HINSTANCE hPrevInstance,  // handle to previous instance
                     LPSTR lpCmdLine,          // command line
                     int nCmdShow              // show state);how state
)
{
    WNDCLASS wndcls;
    wndcls.cbClsExtra=0;
    wndcls.cbWndExtra=0;
    wndcls.hbrBackground=(HBRUSH)GetStockObject(BLACK_BRUSH);
    wndcls.hCursor=LoadCursor(NULL,IDC_CROSS);
    wndcls.hIcon=LoadIcon(NULL,IDI_APPLICATION);
    wndcls.hInstance=hInstance;//应用程序实例句柄由winmain函数传递进来
    wndcls.lpfnWndProc=WinProc;
    wndcls.lpszClassName="zhijz";
    wndcls.lpszMenuName=NULL;
    wndcls.style= CS_VREDRAW | CS_HREDRAW;

    RegisterClass(&wndcls);
    HWND hwnd;//用来保存创建窗口后传递的句柄
    hwnd=CreateWindow("zhijz","MYEXE",WS_OVERLAPPEDWINDOW,0,0,600,400,NULL,NULL,
        hInstance,NULL);
    ShowWindow(hwnd,SW_NORMAL);
    UpdateWindow(hwnd);
    MSG msg;

    while(GetMessage(&msg,NULL,0,0))
    {
        TranslateMessage(&msg);
        DispatchMessage(&msg);
    }
    return msg.lParam;
}
LRESULT CALLBACK WinProc(    HWND hwnd,      // handle to window
                         UINT uMsg,      // message identifier
                         WPARAM wParam,  // first message parameter
                         LPARAM lParam   // second message parameter
                        )
{

    switch (uMsg)
    {
    case WM_CHAR:
        char szChar[20];
        sprintf(szChar,"char is %c",wParam);
        MessageBox(hwnd,szChar,"Myexe",0);
        break;
    case WM_LBUTTONDOWN:
        HDC hDC;
        hDC=GetDC(hwnd);
        TextOut(hDC,0,50,"文字输出完成!",sizeof("文字输出完成!"));
        MessageBox(hwnd,"Mouse Click!","Myexe",0);
        break;
    case WM_CLOSE:
        if (IDYES==MessageBox(hwnd,"真的要关闭吗?","退出提示",MB_YESNO))
        {
            DestroyWindow(hwnd);
        }
        break;
    case WM_DESTROY:
        PostQuitMessage(0);
    default:
        return DefWindowProc(hwnd,uMsg,wParam,lParam);
    }
    return 0;
}