文章详情

  • 游戏榜单
  • 软件榜单
关闭导航
热搜榜
热门下载
热门标签
php爱好者> php文档>孙鑫VC++深入详解第三课完整代码

孙鑫VC++深入详解第三课完整代码

时间:2010-08-11  来源:wgzlilu

以前看了孙鑫老师的书.. 第三课例子没有给完整,下面给个完整的例子.   居然复制后是乱码,不改了,大概意思就在这里了...    

//ËïöÎMFCÉîÈëÏê½â MFC¿ò¼Ü·â×°ÑÝʾ

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

LRESULT CALLBACK WindowProc(
                            HWND hwnd, // handle to window

                            UINT uMsg, // message identifier

                            WPARAM wParam, // first message parameter

                            LPARAM lParam); // second message parameter



class CWnd
{
public:
    BOOL CreateEx(
        DWORD dwExStyle, // extended window style

        LPCTSTR lpClassName, // registered class name

        LPCTSTR lpWindowName, // window name

        DWORD dwStyle, // window style

        int x, // horizontal position of window

        int y, // vertical position of window

        int nWidth, // window width

        int nHeight, // window height

        HWND hWndParent, // handle to parent or owner window

        HMENU hMenu, // menu handle or child identifier

        HINSTANCE hInstance, // handle to application instance

        LPVOID lpParam); // window-creation data

    
    BOOL ShowWindow(int nCmdShow); // show state

    BOOL UpdateWindow();
public:
    HWND m_hWnd;
};

BOOL CWnd::CreateEx(
                    DWORD dwExStyle, // extended window style

                    LPCTSTR lpClassName, // registered class name

                    LPCTSTR lpWindowName, // window name

                    DWORD dwStyle, // window style

                    int x, // horizontal position of window

                    int y, // vertical position of window

                    int nWidth, // window width

                    int nHeight, // window height

                    HWND hWndParent, // handle to parent or owner window

                    HMENU hMenu, // menu handle or child identifier

                    HINSTANCE hInstance, // handle to application instance

                    LPVOID lpParam) // window-creation data

{
    m_hWnd = CreateWindowEx(dwExStyle,lpClassName,lpWindowName,dwStyle,x,y,
         nWidth,nHeight,hWndParent,hMenu,hInstance,
                            lpParam);
    if(m_hWnd !=NULL)
        return TRUE;
    else
        return FALSE;

}

BOOL CWnd::ShowWindow(int nCmdShow)
{
    return ::ShowWindow(m_hWnd,nCmdShow);
}

BOOL CWnd::UpdateWindow()
{
    return ::UpdateWindow(m_hWnd);
}

int WINAPI WinMain(
                 HINSTANCE hInstance, // handle to current instance

                 HINSTANCE hPrevInstance, // handle to previous instance

                 LPSTR lpCmdLine, // command line

                 int nCmdShow) // show state


{
    WNDCLASS wndclass; //&Iuml;&Egrave;&Eacute;è&frac14;&AElig;&acute;°&iquest;&Uacute;&Agrave;à


    wndclass.cbClsExtra = 0;
    wndclass.cbWndExtra = 0;
    wndclass.hbrBackground = (HBRUSH)GetStockObject(DKGRAY_BRUSH);
    wndclass.hCursor = LoadCursor(NULL,IDC_ARROW);
    wndclass.hIcon = LoadIcon(NULL,IDI_APPLICATION);
    wndclass.hInstance = hInstance;
    wndclass.lpfnWndProc = WindowProc;
    wndclass.lpszClassName = "RPG";
    wndclass.lpszMenuName = 0;
    wndclass.style = CS_VREDRAW | CS_HREDRAW;
    
    RegisterClass(&wndclass); ///×&cent;&Ograve;&acirc;&Iuml;&Egrave;&frac12;¨&Aacute;&cent;&Ocirc;&Ugrave;×&cent;&sup2;á°&ordm;

    CWnd wnd;
    
    wnd.CreateEx(NULL,"RPG","RPG",WS_OVERLAPPEDWINDOW,0,0,800,600,NULL,NULL,hInstance,NULL);
    
    wnd.ShowWindow(SW_SHOWNORMAL);
    wnd.UpdateWindow();


    MSG msg; //&Iuml;&ucirc;&Iuml;&cent;&Ntilde;&shy;&raquo;·

   
    while(GetMessage(&msg,NULL,0,0))
    {
        TranslateMessage(&msg);
        DispatchMessage(&msg);
    }
    
    return 0;
}
 
 
LRESULT CALLBACK WindowProc(
                            HWND hwnd, // handle to window

                            UINT uMsg, // message identifier

                            WPARAM wParam, // first message parameter

                            LPARAM lParam) // second message parameter

{
    HDC hdc;
 switch(uMsg)
 {
 case WM_LBUTTONDOWN:
      MessageBox(hwnd,"&Auml;ú°&acute;&Iuml;&Acirc;&Aacute;&Euml;&Ecirc;ó±ê×ó&frac14;ü°&ordm;","×&cent;&Ograve;&acirc;",MB_OK);
      
      hdc = GetDC(hwnd);
      TextOut(hdc,0,0,"&cedil;&ETH;&ETH;&raquo;&Auml;ú&para;&Ocirc;VC++&Eacute;&icirc;&Egrave;&euml;&Iuml;ê&frac12;&acirc;&micro;&Auml;&Ouml;§&sup3;&Ouml;°&ordm;",strlen("&cedil;&ETH;&ETH;&raquo;&Auml;ú&para;&Ocirc;VC++&Eacute;&icirc;&Egrave;&euml;&Iuml;ê&frac12;&acirc;&micro;&Auml;&Ouml;§&sup3;&Ouml;°&ordm;"));
      ReleaseDC(hwnd,hdc);
      break;
 
case WM_CHAR:
      char szChar[20];
      sprintf(szChar,"Char is %d",wParam);
      MessageBox(hwnd,szChar,"×&cent;&Ograve;&acirc;",MB_OK);
      break;
 
case WM_PAINT:
      PAINTSTRUCT ps;
      
      hdc = BeginPaint(hwnd,&ps);
      TextOut(hdc,0,0,"&Otilde;&acirc;&cedil;&ouml;&Ecirc;&Ccedil;&Ouml;&Oslash;&raquo;&aelig;&micro;&Icirc;&Aring;&para;",strlen("&Otilde;&acirc;&cedil;&ouml;&Ecirc;&Ccedil;&Ouml;&Oslash;&raquo;&aelig;&micro;&Icirc;&Aring;&para;"));
      EndPaint(hwnd,&ps);
      break;
 
case WM_CLOSE: //&Otilde;&acirc;&cedil;&ouml;case&Oacute;&euml;&Iuml;&Acirc;±&szlig;&micro;&Auml;destroy&Otilde;&acirc;&cedil;&ouml;case&sup2;&raquo;&Ograve;&ordf;&Aring;&ordf;&acute;í&Aacute;&Euml;&pound;&not;·&ntilde;&Ocirc;ò&acute;°&iquest;&Uacute;&sup2;&raquo;&sup3;&ouml;&Iuml;&Ouml;&pound;&not;&micro;&laquo;&Ocirc;&Uacute;&Egrave;&Icirc;&Icirc;&ntilde;&sup1;&Uuml;&Agrave;í&AElig;÷&Ouml;&ETH;&Ocirc;&Euml;&ETH;&ETH;

      if(IDYES == MessageBox(hwnd,"&Auml;ú&Otilde;&aelig;&micro;&Auml;&Ograve;&ordf;&Iacute;&Euml;&sup3;&ouml;&Atilde;&acute;?","×&cent;&Ograve;&acirc;",MB_YESNO))
      {
           DestroyWindow(hwnd);
      }
      break;
 
case WM_DESTROY:
      PostQuitMessage(0);
      //////////////////////////////////////////?????????????????????

      break;
 
default:
     return DefWindowProc(hwnd,uMsg,wParam,lParam); // ±&eth;&Iacute;ü&frac14;&Ccedil;&Aacute;&Euml;return

 
  }
 return 0;
}





相关阅读 更多 +
排行榜 更多 +
辰域智控app

辰域智控app

系统工具 下载
网医联盟app

网医联盟app

运动健身 下载
汇丰汇选App

汇丰汇选App

金融理财 下载