300分求DELPHI 消息映射(300)

  • 主题发起人 主题发起人 yufeiguan
  • 开始时间 开始时间
Y

yufeiguan

Unregistered / Unconfirmed
GUEST, unregistred user!
下面是一段VC 代码,如果转换为DELPHI的该怎么写?只写基本框架函数即可.内部可以省略.******************************************************头文件******************************************************// MahjongDlg.h : header file#if !defined(AFX_MAHJONGDLG_H__BE37E4CF_7A4F_4452_8280_91342724CEDA__INCLUDED_)#define AFX_MAHJONGDLG_H__BE37E4CF_7A4F_4452_8280_91342724CEDA__INCLUDED_#if _MSC_VER > 1000#pragma once#endif // _MSC_VER > 1000/////////////////////////////////////////////////////////////////////////////// CMahjongDlg dialog class CMahjongDlg : public CDialog{// Constructionpublic: CMahjongDlg(CWnd* pParent = NULL); // standard constructor// Dialog Data //{{AFX_DATA(CMahjongDlg) enum { IDD = IDD_MAHJONG_DIALOG }; // NOTE: the ClassWizard will add data members here //}}AFX_DATA // ClassWizard generated virtual function overrides //{{AFX_VIRTUAL(CMahjongDlg) protected: virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV support //}}AFX_VIRTUAL// Implementationprotected: HICON m_hIcon; HCURSOR m_hCursorHand; //光标 HCURSOR m_hCursor; //光标 // Generated message map functions //{{AFX_MSG(CMahjongDlg) virtual BOOL OnInitDialog(); afx_msg void OnPaint(); afx_msg HCURSOR OnQueryDragIcon(); afx_msg void OnTimer(UINT nIDEvent); afx_msg void OnMouseMove(UINT nFlags, CPoint point); afx_msg BOOL OnSetCursor(CWnd* pWnd, UINT nHitTest, UINT message); afx_msg void OnLButtonUp(UINT nFlags, CPoint point); afx_msg void OnLButtonDown(UINT nFlags, CPoint point); afx_msg int OnCreate(LPCREATESTRUCT lpCreateStruct); //}}AFX_MSG DECLARE_MESSAGE_MAP()};**************************************************程序主体***************************************************// MahjongDlg.cpp : implementation file//#include "stdafx.h"#include "Mahjong.h"#include "MahjongDlg.h"#ifdef _DEBUG#define new DEBUG_NEW#undef THIS_FILEstatic char THIS_FILE[] = __FILE__;#endif/////////////////////////////////////////////////////////////////////////////// CMahjongDlg dialogCMahjongDlg::CMahjongDlg(CWnd* pParent /*=NULL*/): CDialog(CMahjongDlg::IDD, pParent){ //{{AFX_DATA_INIT(CMahjongDlg) // NOTE: the ClassWizard will add member initialization here //}}AFX_DATA_INIT // Note that LoadIcon does not require a subsequent DestroyIcon in Win32 m_hCursor = AfxGetApp()->LoadCursor (IDC_CURSOR); m_hCursorHand = AfxGetApp()->LoadCursor (IDC_CURSOR_Hand); m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);}void CMahjongDlg::DoDataExchange(CDataExchange* pDX){ CDialog::DoDataExchange(pDX); //{{AFX_DATA_MAP(CMahjongDlg) // NOTE: the ClassWizard will add DDX and DDV calls here //}}AFX_DATA_MAP}BEGIN_MESSAGE_MAP(CMahjongDlg, CDialog)//{{AFX_MSG_MAP(CMahjongDlg)ON_WM_PAINT()ON_WM_QUERYDRAGICON()ON_WM_TIMER()ON_WM_MOUSEMOVE()ON_WM_SETCURSOR()ON_WM_LBUTTONUP()ON_WM_LBUTTONDOWN()ON_WM_CREATE()//}}AFX_MSG_MAPEND_MESSAGE_MAP()/////////////////////////////////////////////////////////////////////////////// CMahjongDlg message handlersBOOL CMahjongDlg::OnInitDialog(){ m_bgDC.CreateCompatibleDC(GetDC()); m_paiDC.CreateCompatibleDC(GetDC()); m_memDC.CreateCompatibleDC(GetDC()); CBitmap bm; bm.LoadBitmap(IDB_BITMAP_Bg); m_bgDC.SelectObject(&bm); bm.DeleteObject(); bm.LoadBitmap(IDB_BITMAP_Maj); m_paiDC.SelectObject(&bm); bm.DeleteObject(); bm.CreateCompatibleBitmap(GetDC(),800,600); m_memDC.SelectObject(&bm); bm.DeleteObject(); m_memDC.BitBlt(0,0,800,600,&m_bgDC,0,0,SRCCOPY); CDialog::OnInitDialog(); // 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 return TRUE; // return TRUE unless you set the focus to a control}// 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 CMahjongDlg::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(); UpdateFrame(); }}// The system calls this to obtain the cursor to display while the user drags// the minimized window.HCURSOR CMahjongDlg::OnQueryDragIcon(){ return (HCURSOR) m_hIcon;}void CMahjongDlg::OnTimer(UINT nIDEvent) { // TODO: Add your message handler code here and/or call default switch(nIDEvent) { case 1: { DrawSezi(); } break; case 2: { //选择时的数字秒表 if(m_bwjState) { m_nSelectTime = m_nSelectTime-1; //时间到一半提示 if(m_nSelectTime < TimeSelect/2) { sndPlaySound("Sounds//hurry.wav",SND_ASYNC|SND_NODEFAULT); } //时间用完自动放弃 if(m_nSelectTime < 0) { m_bwjState = false; m_nAbandon = true; m_nSelectTime = TimeSelect; OnTimer(1); KillTimer(3); } UpdateFrame(); } } break; } CDialog::OnTimer(nIDEvent);}void CMahjongDlg::OnMouseMove(UINT nFlags, CPoint point) { // TODO: Add your message handler code here and/or call default //如果是放动画就直接退出 if(m_bCaton) return; MoveTitle(point); CRect rt; //开始 if(m_bStart) { rt.SetRect(370,400,425,428); if(rt.PtInRect(point)) { m_nTitle = 3; DrawTitle(); UpdateFrame(); return; } m_nTitle = -1; DrawTitle(); UpdateFrame(); } CDialog::OnMouseMove(nFlags, point);}BOOL CMahjongDlg::OnSetCursor(CWnd* pWnd, UINT nHitTest, UINT message) { // TODO: Add your message handler code here and/or call default //设置鼠标 if(m_bStart || m_bOver) { if(m_nTitle == 3||m_nTitle == 4) { SetCursor(m_hCursorHand); } else { SetCursor(m_hCursor); } } else { if(m_nMousePai < 0 || m_nMousePai >= 100) { SetCursor(m_hCursor); } else { SetCursor(m_hCursorHand); } } return TRUE; return CDialog::OnSetCursor(pWnd, nHitTest, message);}void CMahjongDlg::OnLButtonUp(UINT nFlags, CPoint point) { // TODO: Add your message handler code here and/or call default m_bHandDown=false; //开始状态 if(m_bStart) { if(m_nTitle == 3) { sndPlaySound("Sounds//start.wav",SND_ASYNC); m_bCaton = true; m_bStart = false; SetTimer(2,50,NULL); SetTimer(1,TimeRun,NULL); SetCursor(m_hCursor); return; } } return; CDialog::OnLButtonUp(nFlags, point);}void CMahjongDlg::OnLButtonDown(UINT nFlags, CPoint point) { // TODO: Add your message handler code here and/or call default m_bHandDown = true; if(m_bOver||m_bStart) { DrawTitle(); UpdateFrame(); } CDialog::OnLButtonDown(nFlags, point); MSG message; while(::PeekMessage(&message,this->m_hWnd,WM_LBUTTONDOWN,WM_LBUTTONDOWN,PM_REMOVE));}int CMahjongDlg::OnCreate(LPCREATESTRUCT lpCreateStruct) { if (CDialog::OnCreate(lpCreateStruct) == -1) return -1; // TODO: Add your specialized creation code here return 0;}
 
只写OnLButtonDown,OnLButtonUp,OnMouseMove,OnTimer这几个就可以了,如果不想要分可以给人民币酬谢.
 
Delphi的窗体也有对应的事件,直接新建个Form就有了;OnTimer就是放一个Timer上去。
 
如果你想用纯API来创建窗口,那也是一样的,消息循环你要自己处理,然后在相应的消息里面执行你的代码即可,相当于就是触发了相应的事件。
 

Similar threads

I
回复
0
查看
642
import
I
I
回复
0
查看
742
import
I
I
回复
0
查看
2K
import
I
I
回复
0
查看
3K
import
I
后退
顶部