none
No such file or directory RRS feed

  • 问题

  • 下面是头文件

    #pragma once
    #include <string>

    class ZZfeiWin
    {
    public:
     ZZfeiWin(void);
      virtual~ZZfeiWin(void);

     ATOM MyRegisterClass(HINSTANCE hInstance);
     bool InitInstance(HINSTANCE hInstance,int nCmdShow);
        int RunMessage(void);
     HINSTANCE GetAppInstance(void)
     {
      return m_hInstance;
     }
    protected:
     static LRESULT CALLBACK WndProc(HWND hWnd,
      UINT message,WPARAM wParam,LPARAM lParam);
     static INT_PTR CALLBACK About(HWND Hdlg,
      UINT message,WPARAM wParam,LPARAM lParam);
    protected:
     HINSTANCE m_hInstance;
     HWND m_hWnd;

        std::wstring m_strWindowClass;
        std::wstring m_strTitle;

    }
     InitInstance(HINSTANCE,int)
        bool ZZfeiWin::InitInstance(HINSTANCE hInstance,int nCmdShow)
     {
     m_hInstance = hInstance;

        m_hWnd = CreateWindow(m_strWindowClass.c_str(),
     m_strTitle.c_str(),
       WS_OVERLAPPEDWINDOW,
        CW_USEDEFAULT,0,CW_USEDEFAULT,O,NULL,NULL,hInstance,NULL);

         if(!m_hWnd)
      {
       return false;
      }
      SetWindowLongPtr(m_hWnd,
           GWL_USERDATA,(LONG)(LONG_PTR)this);
      ShowWindow(m_hWnd,nCmdShow);
      UpdateWindow(m_hWnd);
           
      return true;
     }
       WndProc(HWND,UINT,WPARAM,LPARAM)
        LRESULT CALLBACK ZZfeiWin::WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)

       {
        //获取窗口对应的类指针
        LONG_PTR plptrWin = GetWindowLongPtr(hWnd,GWLP_USERDATA);
        if(plptrWin == NULL)
        {
         return DefWindowProc(hWnd,message,wParam,lParam);
        }
           ZZfeiWin *pWin = reinterpret_cast<ZZfeiWin*>(plptrWin);

        int wmId,wmEvent;
        PAINTSTRUCT ps;
        HDC hdc;

        switch(message)
        {
        case WM_COMMAND:
             wmId = LOWORD(wParam);
       wmEvent = HIWORD(wParam);
      
       //
                switch (wmId)
           {
       case IDM_ABOUT:
        DialogBox(pWin->GetAppInstance(),MAKEINTRESOURCE(IDD_ABOUTBOX),
         hWnd,ZZfeiWin::About);
        break;
       case IDM_EXIT:
        DestroyWindow(hWnd);
        break;
        default:
        return DefWindowProc(hWnd,message,wParam,lParam);
           }
       break;
        case WM_PAINT:
         {
          hdc = BeginPaint(hWnd,&ps);
          std::wstring strShow(_T("C++窗口类的实例,2010.5.31"));
          TextOut(hdc,10,10,strShow.c_str(),(int)strShow.length());

          EndPaint(hWnd,&ps);
         }
         break;
        case WM_DESTROY:
         //
         SetWindowLongPtr(hWnd,GWL_USERDATA,NULL);
         PostQuitMessage(0);
         break;
        default:
         return DefWindowProc(hWnd,message,wParam,lParam);
        }
        return 0;

       }
       void ZZfeiWinMsg::OnDraw(HDC hDC)
       {
        //
        std::wstring strShow(_T("C++窗口类的实现,2010.6.1"));
        TextOut(hDC,10,10,strShow.c_str(),(int)strShow.length());

        //设置输出字符串的颜色
       
        COLORREF crOld = SetTextColor(hDC,RGB(255,0,0));
        TextOut(hDC,10,50,strShow.c_str(),(int)strShow.length());

        SetTextColor(hDC,RGB(0,255,0));
        TextOut(hDC,10,50,strShow.c_str(),(int)strShow.length());

         SetTextColor(hDC,RGB(0,0,255));
        TextOut(hDC,10,70,strShow.c_str(),(int)strShow.length());

        //
        SetTextColor(hDC,crOld);
       }

     

    cpp文件

    #undef UNICODE

    #include "stdafx.h"
    #include "Third.h"


    int APIENTRY _tWinMain(HINSTANCE hInstance,
                         HINSTANCE hPrevInstance,
                         LPTSTR    lpCmdLine,
                         int       nCmdShow)
    {
     UNREFERENCED_PARAMETER(hPrevInstance);
     UNREFERENCED_PARAMETER(lpCmdLine);

      ZZfeiWin feiWin;
        feiWin.MyRegisterClass(hInstance);
       if(!feiWin.InitInstance(hInstance,nCmdShow))
       {
        return 0;
       }
       return feiWin.RunMessage();
    }

    • 已移动 liujj_xujjModerator 2011年3月21日 3:37 (发件人:微软敏捷软件开发与TFS (Team Foundation Server))
    2010年6月1日 12:57