正文

FileMapServer_FileMapClient2006-10-12 13:56:00

【评论】 【打印】 【字体: 】 本文链接:http://blog.pfan.cn/embed/19243.html

分享到:


// FileMapServerDlg.h : header file
//

#define WM_MYMESSAGE WM_USER+1
#if !defined(AFX_FILEMAPSERVERDLG_H__212D073F_1A13_43B5_B431_0B5546BD2DB5__INCLUDED_)
#define AFX_FILEMAPSERVERDLG_H__212D073F_1A13_43B5_B431_0B5546BD2DB5__INCLUDED_

#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000

/////////////////////////////////////////////////////////////////////////////
// CFileMapServerDlg dialog
typedef struct _UserInfo{
    char name[20];
    char age[20];
    char telecode[20];
    char address[20];
}UserInfo;

class CFileMapServerDlg : public CDialog
{
// Construction
public:
    CFileMapServerDlg(CWnd* pParent = NULL);    // standard constructor

// Dialog Data
    //{{AFX_DATA(CFileMapServerDlg)
    enum { IDD = IDD_FILEMAPSERVER_DIALOG };
    CString    m_name;
    CString    m_age;
    CString    m_telecode;
    CString    m_address;

    UserInfo m_info;
    HANDLE m_hMapObject;
    LPVOID m_hMapView;
    //}}AFX_DATA

    // ClassWizard generated virtual function overrides
    //{{AFX_VIRTUAL(CFileMapServerDlg)
    protected:
    virtual void DoDataExchange(CDataExchange* pDX);    // DDX/DDV support
    //}}AFX_VIRTUAL

// Implementation
protected:
    HICON m_hIcon;

    // Generated message map functions
    //{{AFX_MSG(CFileMapServerDlg)
    virtual BOOL OnInitDialog();
    afx_msg void OnSysCommand(UINT nID, LPARAM lParam);
    afx_msg void OnPaint();
    afx_msg HCURSOR OnQueryDragIcon();
    virtual void OnOK();
    afx_msg void OnRead();
    afx_msg void Message(WPARAM wParam,LPARAM lParam);
    //}}AFX_MSG
    DECLARE_MESSAGE_MAP()
};

//{{AFX_INSERT_LOCATION}}
// Microsoft Visual C++ will insert additional declarations immediately before the previous line.

#endif // !defined(AFX_FILEMAPSERVERDLG_H__212D073F_1A13_43B5_B431_0B5546BD2DB5__INCLUDED_)

// FileMapServerDlg.cpp : implementation file
//

#include "stdafx.h"
#include "FileMapServer.h"
#include "FileMapServerDlg.h"
#include "afxadv.h"

#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif

#ifndef WM_MYMESSAGE
#define WM_MYMESSAGE WM_USER+1
#endif

/////////////////////////////////////////////////////////////////////////////
// CAboutDlg dialog used for App About

class CAboutDlg : public CDialog
{
public:
    CAboutDlg();

// Dialog Data
    //{{AFX_DATA(CAboutDlg)
    enum { IDD = IDD_ABOUTBOX };
    //}}AFX_DATA

    // ClassWizard generated virtual function overrides
    //{{AFX_VIRTUAL(CAboutDlg)
    protected:
    virtual void DoDataExchange(CDataExchange* pDX);    // DDX/DDV support
    //}}AFX_VIRTUAL

// Implementation
protected:
    //{{AFX_MSG(CAboutDlg)
    //}}AFX_MSG
    DECLARE_MESSAGE_MAP()
};

CAboutDlg::CAboutDlg() : CDialog(CAboutDlg::IDD)
{
    //{{AFX_DATA_INIT(CAboutDlg)
    //}}AFX_DATA_INIT
}

void CAboutDlg::DoDataExchange(CDataExchange* pDX)
{
    CDialog::DoDataExchange(pDX);
    //{{AFX_DATA_MAP(CAboutDlg)
    //}}AFX_DATA_MAP
}

BEGIN_MESSAGE_MAP(CAboutDlg, CDialog)
    //{{AFX_MSG_MAP(CAboutDlg)
        // No message handlers
    //}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CFileMapServerDlg dialog

CFileMapServerDlg::CFileMapServerDlg(CWnd* pParent /*=NULL*/)
    : CDialog(CFileMapServerDlg::IDD, pParent)
{
    //{{AFX_DATA_INIT(CFileMapServerDlg)
    m_name = _T("");
    m_age = _T("");
    m_telecode = _T("");
    m_address = _T("");
    //}}AFX_DATA_INIT
    // Note that LoadIcon does not require a subsequent DestroyIcon in Win32
    m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
}

void CFileMapServerDlg::DoDataExchange(CDataExchange* pDX)
{
    CDialog::DoDataExchange(pDX);
    //{{AFX_DATA_MAP(CFileMapServerDlg)
    DDX_Text(pDX, IDC_NAME, m_name);
    DDX_Text(pDX, IDC_AGE, m_age);
    DDX_Text(pDX, IDC_TELECODE, m_telecode);
    DDX_Text(pDX, IDC_ADDRESS, m_address);
    //}}AFX_DATA_MAP
}

BEGIN_MESSAGE_MAP(CFileMapServerDlg, CDialog)
    //{{AFX_MSG_MAP(CFileMapServerDlg)
    ON_WM_SYSCOMMAND()
    ON_WM_PAINT()
    ON_WM_QUERYDRAGICON()
    ON_BN_CLICKED(IDREAD, OnRead)
    ON_MESSAGE(WM_MYMESSAGE,Message)
    //}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CFileMapServerDlg message handlers

BOOL CFileMapServerDlg::OnInitDialog()
{
    CDialog::OnInitDialog();

    // Add "About..." menu item to system menu.

    // IDM_ABOUTBOX must be in the system command range.
    ASSERT((IDM_ABOUTBOX & 0xFFF0) == IDM_ABOUTBOX);
    ASSERT(IDM_ABOUTBOX < 0xF000);

    CMenu* pSysMenu = GetSystemMenu(FALSE);
    if (pSysMenu != NULL)
    {
        CString strAboutMenu;
        strAboutMenu.LoadString(IDS_ABOUTBOX);
        if (!strAboutMenu.IsEmpty())
        {
            pSysMenu->AppendMenu(MF_SEPARATOR);
            pSysMenu->AppendMenu(MF_STRING, IDM_ABOUTBOX, strAboutMenu);
        }
    }

    // Set the icon for this dialog.  The framework does this automatically
    //  when the application's main window is not a dialog
    SetIcon(m_hIcon, TRUE);            // Set big icon
    SetIcon(m_hIcon, FALSE);        // Set small icon
    
    // TODO: Add extra initialization here
    m_hMapObject=::OpenFileMapping(FILE_MAP_READ,FALSE,_T("MultiServer"));
    if(m_hMapObject==NULL)
    {
        AfxMessageBox("无法打开文件映射对象");
        return TRUE;
    }

    m_hMapView=::MapViewOfFile(m_hMapObject,FILE_MAP_READ,0,0,0);
    if(m_hMapView==NULL)
    {
        AfxMessageBox("无法获取文件视图");
        return TRUE;
    }
    memcpy((void*)&m_info,m_hMapView,sizeof(UserInfo));
    /*
    char tmp[10];
    strcpy(tmp,(char*)m_hMapView);
    AfxMessageBox(tmp);
    memcpy((void*)m_hMapView,(void*)&m_Info,sizeof(UserInfo));
    */
    return TRUE;  // return TRUE  unless you set the focus to a control
}

void CFileMapServerDlg::OnSysCommand(UINT nID, LPARAM lParam)
{
    if ((nID & 0xFFF0) == IDM_ABOUTBOX)
    {
        CAboutDlg dlgAbout;
        dlgAbout.DoModal();
    }
    else
    {
        CDialog::OnSysCommand(nID, lParam);
    }
}

// If you add a minimize button to your dialog, you will need the code below
//  to draw the icon.  For MFC applications using the document/view model,
//  this is automatically done for you by the framework.

void CFileMapServerDlg::OnPaint() 
{
    if (IsIconic())
    {
        CPaintDC dc(this); // device context for painting

        SendMessage(WM_ICONERASEBKGND, (WPARAM) dc.GetSafeHdc(), 0);

        // Center icon in client rectangle
        int cxIcon = GetSystemMetrics(SM_CXICON);
        int cyIcon = GetSystemMetrics(SM_CYICON);
        CRect rect;
        GetClientRect(&rect);
        int x = (rect.Width() - cxIcon + 1) / 2;
        int y = (rect.Height() - cyIcon + 1) / 2;

        // Draw the icon
        dc.DrawIcon(x, y, m_hIcon);
    }
    else
    {
        CDialog::OnPaint();
    }
}

// The system calls this to obtain the cursor to display while the user drags
//  the minimized window.
HCURSOR CFileMapServerDlg::OnQueryDragIcon()
{
    return (HCURSOR) m_hIcon;
}

void CFileMapServerDlg::OnOK() 
{    
    CDialog::OnOK();
}

void CFileMapServerDlg::OnRead() 
{    
    memcpy((void*)&m_info,m_hMapView,sizeof(UserInfo));//??
    m_name=m_info.name;
    m_age=m_info.age;
    m_telecode=m_info.telecode;
    m_address=m_info.address;
    UpdateData(FALSE);

}
void CFileMapServerDlg::Message(WPARAM wParam,LPARAM lParam) 
{    
}


/////////////////////////////////////////
// FileMapServerDlg.h : header file
//

#define WM_MYMESSAGE WM_USER+1
#if !defined(AFX_FILEMAPSERVERDLG_H__212D073F_1A13_43B5_B431_0B5546BD2DB5__INCLUDED_)
#define AFX_FILEMAPSERVERDLG_H__212D073F_1A13_43B5_B431_0B5546BD2DB5__INCLUDED_

#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000

/////////////////////////////////////////////////////////////////////////////
// CFileMapServerDlg dialog
typedef struct _UserInfo{
    char name[20];
    char age[20];
    char telecode[20];
    char address[20];
}UserInfo;

class CFileMapServerDlg : public CDialog
{
// Construction
public:
    CFileMapServerDlg(CWnd* pParent = NULL);    // standard constructor

// Dialog Data
    //{{AFX_DATA(CFileMapServerDlg)
    enum { IDD = IDD_FILEMAPSERVER_DIALOG };
    CString    m_name;
    CString    m_age;
    CString    m_telecode;
    CString    m_address;

    UserInfo m_info;
    HANDLE m_hMapObject;
    LPVOID m_hMapView;
    //}}AFX_DATA

    // ClassWizard generated virtual function overrides
    //{{AFX_VIRTUAL(CFileMapServerDlg)
    protected:
    virtual void DoDataExchange(CDataExchange* pDX);    // DDX/DDV support
    //}}AFX_VIRTUAL

// Implementation
protected:
    HICON m_hIcon;

    // Generated message map functions
    //{{AFX_MSG(CFileMapServerDlg)
    virtual BOOL OnInitDialog();
    afx_msg void OnSysCommand(UINT nID, LPARAM lParam);
    afx_msg void OnPaint();
    afx_msg HCURSOR OnQueryDragIcon();
    virtual void OnOK();
    afx_msg void OnRead();
    afx_msg void Message(WPARAM wParam,LPARAM lParam);
    //}}AFX_MSG
    DECLARE_MESSAGE_MAP()
};

//{{AFX_INSERT_LOCATION}}
// Microsoft Visual C++ will insert additional declarations immediately before the previous line.

#endif // !defined(AFX_FILEMAPSERVERDLG_H__212D073F_1A13_43B5_B431_0B5546BD2DB5__INCLUDED_)

/////////////////////////////
// FileMapServerDlg.cpp : implementation file
//

#include "stdafx.h"
#include "FileMapServer.h"
#include "FileMapServerDlg.h"
#include "afxadv.h"

#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif

#ifndef WM_MYMESSAGE
#define WM_MYMESSAGE WM_USER+1
#endif

/////////////////////////////////////////////////////////////////////////////
// CAboutDlg dialog used for App About

class CAboutDlg : public CDialog
{
public:
    CAboutDlg();

// Dialog Data
    //{{AFX_DATA(CAboutDlg)
    enum { IDD = IDD_ABOUTBOX };
    //}}AFX_DATA

    // ClassWizard generated virtual function overrides
    //{{AFX_VIRTUAL(CAboutDlg)
    protected:
    virtual void DoDataExchange(CDataExchange* pDX);    // DDX/DDV support
    //}}AFX_VIRTUAL

// Implementation
protected:
    //{{AFX_MSG(CAboutDlg)
    //}}AFX_MSG
    DECLARE_MESSAGE_MAP()
};

CAboutDlg::CAboutDlg() : CDialog(CAboutDlg::IDD)
{
    //{{AFX_DATA_INIT(CAboutDlg)
    //}}AFX_DATA_INIT
}

void CAboutDlg::DoDataExchange(CDataExchange* pDX)
{
    CDialog::DoDataExchange(pDX);
    //{{AFX_DATA_MAP(CAboutDlg)
    //}}AFX_DATA_MAP
}

BEGIN_MESSAGE_MAP(CAboutDlg, CDialog)
    //{{AFX_MSG_MAP(CAboutDlg)
        // No message handlers
    //}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CFileMapServerDlg dialog

CFileMapServerDlg::CFileMapServerDlg(CWnd* pParent /*=NULL*/)
    : CDialog(CFileMapServerDlg::IDD, pParent)
{
    //{{AFX_DATA_INIT(CFileMapServerDlg)
    m_name = _T("");
    m_age = _T("");
    m_telecode = _T("");
    m_address = _T("");
    //}}AFX_DATA_INIT
    // Note that LoadIcon does not require a subsequent DestroyIcon in Win32
    m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
}

void CFileMapServerDlg::DoDataExchange(CDataExchange* pDX)
{
    CDialog::DoDataExchange(pDX);
    //{{AFX_DATA_MAP(CFileMapServerDlg)
    DDX_Text(pDX, IDC_NAME, m_name);
    DDX_Text(pDX, IDC_AGE, m_age);
    DDX_Text(pDX, IDC_TELECODE, m_telecode);
    DDX_Text(pDX, IDC_ADDRESS, m_address);
    //}}AFX_DATA_MAP
}

BEGIN_MESSAGE_MAP(CFileMapServerDlg, CDialog)
    //{{AFX_MSG_MAP(CFileMapServerDlg)
    ON_WM_SYSCOMMAND()
    ON_WM_PAINT()
    ON_WM_QUERYDRAGICON()
    ON_BN_CLICKED(IDREAD, OnRead)
    ON_MESSAGE(WM_MYMESSAGE,Message)
    //}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CFileMapServerDlg message handlers

BOOL CFileMapServerDlg::OnInitDialog()
{
    CDialog::OnInitDialog();

    // Add "About..." menu item to system menu.

    // IDM_ABOUTBOX must be in the system command range.
    ASSERT((IDM_ABOUTBOX & 0xFFF0) == IDM_ABOUTBOX);
    ASSERT(IDM_ABOUTBOX < 0xF000);

    CMenu* pSysMenu = GetSystemMenu(FALSE);
    if (pSysMenu != NULL)
    {
        CString strAboutMenu;
        strAboutMenu.LoadString(IDS_ABOUTBOX);
        if (!strAboutMenu.IsEmpty())
        {
            pSysMenu->AppendMenu(MF_SEPARATOR);
            pSysMenu->AppendMenu(MF_STRING, IDM_ABOUTBOX, strAboutMenu);
        }
    }

    // Set the icon for this dialog.  The framework does this automatically
    //  when the application's main window is not a dialog
    SetIcon(m_hIcon, TRUE);            // Set big icon
    SetIcon(m_hIcon, FALSE);        // Set small icon
    
    // TODO: Add extra initialization here
    m_hMapObject=::OpenFileMapping(FILE_MAP_READ,FALSE,_T("MultiServer"));
    if(m_hMapObject==NULL)
    {
        AfxMessageBox("无法打开文件映射对象");
        return TRUE;
    }

    m_hMapView=::MapViewOfFile(m_hMapObject,FILE_MAP_READ,0,0,0);
    if(m_hMapView==NULL)
    {
        AfxMessageBox("无法获取文件视图");
        return TRUE;
    }
    memcpy((void*)&m_info,m_hMapView,sizeof(UserInfo));
    /*
    char tmp[10];
    strcpy(tmp,(char*)m_hMapView);
    AfxMessageBox(tmp);
    memcpy((void*)m_hMapView,(void*)&m_Info,sizeof(UserInfo));
    */
    return TRUE;  // return TRUE  unless you set the focus to a control
}

void CFileMapServerDlg::OnSysCommand(UINT nID, LPARAM lParam)
{
    if ((nID & 0xFFF0) == IDM_ABOUTBOX)
    {
        CAboutDlg dlgAbout;
        dlgAbout.DoModal();
    }
    else
    {
        CDialog::OnSysCommand(nID, lParam);
    }
}

// If you add a minimize button to your dialog, you will need the code below
//  to draw the icon.  For MFC applications using the document/view model,
//  this is automatically done for you by the framework.

void CFileMapServerDlg::OnPaint() 
{
    if (IsIconic())
    {
        CPaintDC dc(this); // device context for painting

        SendMessage(WM_ICONERASEBKGND, (WPARAM) dc.GetSafeHdc(), 0);

        // Center icon in client rectangle
        int cxIcon = GetSystemMetrics(SM_CXICON);
        int cyIcon = GetSystemMetrics(SM_CYICON);
        CRect rect;
        GetClientRect(&rect);
        int x = (rect.Width() - cxIcon + 1) / 2;
        int y = (rect.Height() - cyIcon + 1) / 2;

        // Draw the icon
        dc.DrawIcon(x, y, m_hIcon);
    }
    else
    {
        CDialog::OnPaint();
    }
}

// The system calls this to obtain the cursor to display while the user drags
//  the minimized window.
HCURSOR CFileMapServerDlg::OnQueryDragIcon()
{
    return (HCURSOR) m_hIcon;
}

void CFileMapServerDlg::OnOK() 
{    
    CDialog::OnOK();
}

void CFileMapServerDlg::OnRead() 
{    
    memcpy((void*)&m_info,m_hMapView,sizeof(UserInfo));//??
    m_name=m_info.name;
    m_age=m_info.age;
    m_telecode=m_info.telecode;
    m_address=m_info.address;
    UpdateData(FALSE);

}
void CFileMapServerDlg::Message(WPARAM wParam,LPARAM lParam) 
{    
}



阅读(2823) | 评论(0)


版权声明:编程爱好者网站为此博客服务提供商,如本文牵涉到版权问题,编程爱好者网站不承担相关责任,如有版权问题请直接与本文作者联系解决。谢谢!

评论

暂无评论
您需要登录后才能评论,请 登录 或者 注册