win32 application

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

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

int  WINAPI WinMain( HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine,  int  nShowCmd )
{
    
// 设计一个窗口类
    WNDCLASS wndclass;
    wndclass.cbClsExtra 
=   0 ;
    wndclass.cbWndExtra 
=   0 ;
    wndclass.hbrBackground 
=  (HBRUSH)GetStockObject(BLACK_BRUSH);
    wndclass.hCursor 
=  LoadCursor(NULL, IDC_CROSS);
    wndclass.hIcon 
=  LoadIcon(NULL, IDI_ERROR);
    wndclass.hInstance 
=  hInstance;  // 应用程序句柄由WinMain函数传进来
    wndclass.lpfnWndProc  =  WinProc;
    wndclass.lpszClassName 
=   " WinTest " ;
    wndclass.lpszMenuName 
=  NULL;
    wndclass.style 
=  CS_HREDRAW  |  CS_VREDRAW;
    RegisterClass(
& wndclass);

    HWND hwnd 
=  CreateWindow(wndclass.lpszClassName,  " TEst " ,
        WS_OVERLAPPEDWINDOW, 
0 0 600 400 , 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
             return   - 1 ;
        }
        
else
        {
            TranslateMessage(
& msg);
            DispatchMessage(
& msg);
        }
    }

    
return  msg.wParam;
}

LRESULT CALLBACK WinProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
{
    
switch (uMsg)
    {
    
case  WM_CHAR:
        {
            
char  szChar[ 20 ];
            sprintf(szChar, 
" char code is %d " , wParam);
            MessageBox(hwnd, szChar, 
" char " 0 );
        }
        
break ;
    
case  WM_LBUTTONDOWN:
        {
            MessageBox(hwnd, 
" Mouse clicked " " message " 0 );
            HDC hdc 
=  GetDC(hwnd); // 不能在WM_PAINT消息中调用
            TextOut(hdc,  0 50 " 程序员 " , strlen( " 程序员 " ));
            ReleaseDC(hwnd, hdc);
        }
        
break ;
    
case  WM_PAINT:
        {
            PAINTSTRUCT ps;
            HDC hdc 
=  BeginPaint(hwnd,  & ps); // 只能在响应WM_PAINT中调用
            TextOut(hdc,  0 0 " http://www " , strlen( " http://www " ));
            EndPaint(hwnd, 
& ps);
        }
        
break ;
    
case  WM_CLOSE:
        {
            
if (IDYES  ==  MessageBox(hwnd,  " 是否结束? " " message " , MB_YESNO))
            {
                DestroyWindow(hwnd);
            }
        }
        
break ;
    
case  WM_DESTROY:
        {
            PostQuitMessage(
0 );
        }
        
break ;
    
default :
        {
            
return  DefWindowProc(hwnd, uMsg, wParam, lParam);
        }

    }
// end of switch

    
return   false ;
}

 

你可能感兴趣的:(application)