全用api写的程序


#include <windows.h>

#include <stdio.h>

#include <TCHAR.h>

LRESULT CALLBACK winsProc(         

 HWND hwnd,

    UINT uMsg,

    WPARAM wParam,

    LPARAM lParam

);

int WinMain(         

   HINSTANCE hInstance,

    HINSTANCE hPrevInstance,

    LPSTR lpCmdLine,

    int nCmdShow

)

{

 WNDCLASS wclass;

 wclass.cbClsExtra=0;

 wclass.cbWndExtra=0;

 wclass.hbrBackground=(HBRUSH)GetStockObject(BLACK_BRUSH);

 wclass.hCursor=LoadCursor(NULL,IDC_ARROW);

 wclass.hIcon=LoadIcon(NULL,IDI_ERROR);

 wclass.hInstance=hInstance;

 wclass.lpfnWndProc=winsProc;

 wclass.lpszClassName=_T("Wins32");

 wclass.lpszMenuName=NULL;

 wclass.style=CS_HREDRAW|CS_VREDRAW;

 RegisterClass(&wclass);

 HWND hwnd;

 hwnd=CreateWindow(_T("Wins32"),_T("linkwork"),

  WS_OVERLAPPEDWINDOW,0,0,800,600,NULL,NULL,hInstance,NULL);

 ShowWindow(hwnd,SW_SHOWNORMAL);

 UpdateWindow(hwnd);

 MSG msg;

 BOOL bRet;

while( (bRet = GetMessage( &msg, NULL, 0, 0 )) != 0)

{

    if (bRet == -1)

    {

        // handle the error and possibly exit

    }

    else

    {

        TranslateMessage(&msg);

        DispatchMessage(&msg);

    }

}

 return 0;

}

LRESULT CALLBACK winsProc(

  HWND hwnd,

  UINT uMsg,

  WPARAM wParam,

  LPARAM lParam

  )

{

 HDC dc;

 PAINTSTRUCT ps;

 switch(uMsg)

 {

 case WM_PAINT:

  dc=BeginPaint(hwnd,&ps);

  TextOut(dc,20,20,_T("Hello Word!"),10);

  EndPaint(hwnd,&ps);

  break;

 case WM_CLOSE:

  DestroyWindow(hwnd);

 case WM_DESTROY:

  PostQuitMessage(0);

 default:

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


 }

 return 0;

}