可到下面邮箱下载:[email protected]
密码:qq123321

解决方案 »

  1.   

    /************************************************************************/
    /*       MFC原理教程                                                    */
    /*       XuPei                                                          */
    /*       [email protected]                                                */
    /*       2007-4-2                                                       */
    /************************************************************************/#ifndef WND
    #define WND#include <commctrl.h>
    #include "ListCtrl.h"#define MESSAGE_MAP_DECLARE() \
    public: \
    static MSGMAP_ENTRY MessageEntry[];#define MESSAGE_MAP_BEGIN(ClassName) \
    MSGMAP_ENTRY Wnd::MessageEntry[] = \
    {#define MESSAGE(MSG, PEOC) \
    {MSG, &PEOC},#define MESSAGE_MAP_END() \
    {0, 0} \
    };class Wnd;
    typedef struct _MSGMAP_ENTRY
    {
    UINT nMessage;
    void (Wnd::*pfn)();
    }MSGMAP_ENTRY;LRESULT CALLBACK WndProc(HWND hWnd, UINT nMsg, WPARAM wParam, LPARAM lParam);class Wnd
    {
    public:
    ListCtrl m_List;

    Wnd(){m_hWnd = 0;}
    void Create(HINSTANCE hinstance)
    {
    WNDCLASSEX winclass = {0}; 

    winclass.cbSize = sizeof(WNDCLASSEX);
    winclass.style = CS_HREDRAW | CS_VREDRAW;
    winclass.lpfnWndProc = WndProc;
    winclass.hInstance = hinstance;
    winclass.hbrBackground = (HBRUSH)(COLOR_WINDOW);
    winclass.lpszClassName = "WinInit";
    winclass.hCursor = LoadCursor(NULL, IDC_ARROW);

    RegisterClassEx(&winclass);

    m_hWnd = CreateWindowEx(NULL, "WinInit", "First Window",  
    WS_OVERLAPPEDWINDOW | WS_VISIBLE | WS_CLIPCHILDREN, 0, 0, 
    260, 200, NULL, NULL, hinstance, NULL);
    m_List.Create(m_hWnd);
    m_List.AddItem("Hello!");
    m_List.AddItem("I'm XuPei!");

    /*
    HWND hWndThread = CreateWindow("LISTBOX", NULL, 
    WS_CHILD | WS_VISIBLE | WS_BORDER ,
    3,25,245,154, 
    m_hWnd, 
    0, 
    hinstance, NULL );
    SendMessage(hWndThread, LB_ADDSTRING, 0, 
    (LPARAM) "Hello1"); 
    SendMessage(hWndThread, LB_ADDSTRING, 0, 
    (LPARAM) "Hello, I'm XuPei"); 
    */
    }

    LRESULT WindowProc(UINT nMsg, WPARAM wParam, LPARAM lParam)
    {
    int count = 0;
    while((MessageEntry[count].pfn) != 0)
    {
    if(MessageEntry[count].nMessage == nMsg)
    {
    (this->*MessageEntry[count].pfn)();
    return 0;
    }
    count++;
    }
    return DefWindowProc(m_hWnd, nMsg, wParam, lParam);
    } HWND GetHWnd(){return m_hWnd;}
    private:
    void onClose();
    void onKeyDown();
    void onPaint();
    private:
    HWND m_hWnd;

    MESSAGE_MAP_DECLARE()
    };MESSAGE_MAP_BEGIN(Wnd)
    MESSAGE(WM_CLOSE, onClose)
    MESSAGE(WM_KEYDOWN, onKeyDown)
    MESSAGE(WM_PAINT, onPaint)
    MESSAGE_MAP_END()void Wnd::onPaint()
    {
    PAINTSTRUCT ps;
    HDC hdc;
    hdc = BeginPaint(m_hWnd, &ps);
    RECT rt;
    GetClientRect(m_hWnd, &rt);
    rt.top = 5;
    DrawText(hdc, "Hello World!", strlen("Hello World!"), &rt, DT_CENTER);
    EndPaint(m_hWnd, &ps);
    }void Wnd::onClose()
    {
    MessageBox(0,"我要退出了,再见!","你好", 0);
    PostQuitMessage(0);
    }void Wnd::onKeyDown()
    {
    MessageBox(0,"你好,键盘按下了!", "你好", 0);
    }
    #endif
      

  2.   


    #ifndef WINAPP
    #define WINAPP#include "Wnd.h"class WinApp
    {
    public:
    void InitInstance(HINSTANCE hinstance); int Run()
    {
    MSG  msg;   
    while(GetMessage(&msg, NULL, 0, 0))
    {  
    TranslateMessage(&msg);  
    DispatchMessage(&msg);

    return (msg.wParam);
    }
    Wnd* GetWnd()
    {
    return m_pWnd;
    } ~WinApp(){delete m_pWnd;}private:
    Wnd* m_pWnd; 
    };
    WinApp theApp;void WinApp::InitInstance(HINSTANCE hinstance)
    {
    m_pWnd = new Wnd;
    m_pWnd->Create(hinstance);
    }LRESULT CALLBACK WndProc(HWND hWnd, UINT nMsg, WPARAM wParam, LPARAM lParam)
    {  
    Wnd *pWnd = theApp.GetWnd();
    //pWnd = GetWndByHWnd(hWnd);
    if(pWnd->GetHWnd() == 0)
    return DefWindowProc(hWnd, nMsg, wParam, lParam);

    return pWnd->WindowProc(nMsg, wParam, lParam);
    } #endif
      

  3.   


    #ifndef LISTCTRL
    #define LISTCTRL#include "WinApp.h"
    /*
    LRESULT (*Proc)(HWND hWnd, UINT nMsg, WPARAM wParam, LPARAM lParam);LRESULT CALLBACK ListProc(HWND hWnd, UINT nMsg, WPARAM wParam, LPARAM lParam)
    {
    //return Proc(hWnd, nMsg, wParam, lParam);
    return DefWindowProc(hWnd, nMsg, wParam, lParam);

    */
    class ListCtrl
    {
    public:
    ListCtrl(){}
    void Create(HWND hParent)
    {
    m_hWnd = CreateWindow("LISTBOX", NULL, 
    WS_CHILD | WS_VISIBLE | WS_BORDER ,
    3,25,245,154, 
    hParent, 
    0, 
    NULL, NULL );
    //Proc = (long (*)(HWND,UINT,UINT,long))GetWindowLong(m_hWnd, GWL_WNDPROC);
    //SetWindowLong(m_hWnd, GWL_WNDPROC, (long)ListProc);
    }
    void AddItem(char * str)
    {
    SendMessage(m_hWnd, LB_ADDSTRING, 0, (LPARAM)str); 
    }private:
    HWND m_hWnd;
    };#endif
      

  4.   

    能不能发一个给我[email protected]!
    先谢谢了!