windows编程初学

#include<windows.h>

LRESULT CALLBACK WinPro(HWND,UINT,WPARAM,LPARAM);

static BOOL InitWindow(HINSTANCE,int); 

int WINAPI WinMain(HINSTANCE hInstance,HINSTANCE PrevhInstance,

                               LPSTR lpszCmdLine,int nCmdShow)

{

      MSG msg;

      if(!InitWindow(hInstance,nCmdShow))

                 return FALSE; 

      while(GetMessage(&msg,NULL,0,0))

     {

             TranslateMessage(&msg);

             DispathMessage(&msg);

     }

     return msg.wParam;

}

 

static BOOL InitWindow(HINSTANCE hInstance,int nCmdShow)

{

        HWND hwnd;

        WNDCLASS wc;

        wc.style=CS_VREDRAW|CS_HREDRAW;

        wc.hCursor=LoadCursor(NULL,IDC_ARROW);

        wc.hIcon=LoadIcon(hInstance,IDI_APPLICATION);

        wc.lpfnWndProc = WndProc ;

        wc.cbClsExtra = 0 ;

        wc.cbWndExtra= 0 ;

        wc.hInstance = hInstance ;

        wc.hbrBackground = (HBRUSH) GetStockObject (WHITE_BRUSH) ;

        wc.lpszMenuName = NULL ;

        wc.lpszClassName ="Win32" ;
        if(!RegisterClass(&wc))

              return FALSE;

        hwnd=CreateWindow("Win32","Win32",WS_OVERLAPPEDWINDOW,CS_USEDEFAULT,

                                          CS_USEDEFAULT,CS_USEDEFAULT,CS_USEDEFAULT,NULL,NULL,

                                          hInstance,NULL);

       if(!hwnd)

           return FALSE;

      ShowWindow(hwnd,nCmdShow);

      UpdateWindow(hwnd);

      return TRUE;

}

 

 

LRESULT CALLBACK WinProc(HWND hWnd,UINT message,WPARAM wParam,

                                             LPARAM lParam)

{

        switch(message)

       {

                   case WM_CREATE:break;

                   case WM_SIZE:break;

                   case WM_PAINT:

                           {

                                 HDC hdc;

                                 PAINTSTRUCT ps;

                                 hdc=BeginPaint(whnd,&ps); 

                                 SetTextColor(hdc,RGB(0,0,255));

                                 TextOut(hdc,20,20,"This is my first windows applition!",

                                                 strlen("This is my first windows applition!",));

                                 EndPaint(hwnd,&ps);

                                 break;

                           }

                   case WM_DESTROY:

                              PostQuitMessage(0);

                              break;

       }

        return DefWindowPro(hWnd,message,wParam,lParam);

}

你可能感兴趣的:(编程,windows,null,application,callback,winapi)