[技术学习]在Linux平台学习Windows开发技术(二)----给MFC程序来个消息映射...

本文介绍了一个使用MFC的示例程序,在Linux环境下通过wine库进行编译。该程序包括消息映射和消息框功能,当用户在窗口点击左键时会弹出消息框。

来个复杂点的MFC程序,加个消息映射和消息框。


Mak efile(注意Makefile进化了):

###########################################################################################
# Makefile for MFC Application with wineLib on Linux(Ubuntu 9.10)
# *****************************************************************************************
# * Previous steps:
# * 1. Install wine 1.1.35
# *wgethttp://ibiblio.org/pub/linux/system/emulators/wine/wine-1.1.35.tar.bz2
# *unzip && ./configure && install
# *
# *Q: configure: error: FreeType development files not found.
# * A:sudo apt-get installlibfreetype6-dev
# *
# * 2. Copy all the files of Vistual Studio 6 to wine directory.
# *
# * Notice:
# * When you make with this Makefile at first time,there are some errors about "err:module". Dont worry,make again,you will be success.
# *
# * Creator: think.hy@gmail.com
# * Date:2010年 01月 03日 星期日 17:20:53 CST
# ****************************************************************************************

WINE = /home/thinkhy/work/wine/wine-1.1.35/wine


LINK = LINK.EXE
LFLAG = /subsystem:windows #/OPT:REF

CC = CL.EXE
CFLAG =/MT /c #/GX /D "_AFXDLL"


INCLUDE = /I. /I/home/thinkhy/.wine/drive_c/Program/ Files/Microsof/ Visual/ Studio/VC98/Include /
/I/home/thinkhy/.wine/drive_c/Program/ Files/Microsof/ Visual/ Studio/VC98/MFC/Include
LIB = /LIBPATH:/home/thinkhy/.wine/drive_c/Program/ Files/Microsof/ Visual/ Studio/VC98/Lib /LIBPATH:/home/thinkhy/.wine/drive_c/Program/ Files/Microsof/ Visual/ Studio/VC98/MFC/Lib

RES =
SRC = ./mfc2.cpp
OBJ = ./mfc2.obj
OUTFILE = mfc2.exe
OUTPUT = /OUT:$(OUTFILE)

all : compile link

compile : $(SRC)
$(WINE) $(CC) $(SRC) $(CFLAG) $(INCLUDE)

link : $(OBJ)
$(WINE) $(LINK) $(LFLAG) $(LIB) $(OBJ) $(RES) $(OUTPUT)

clean:
- rm $(OBJ)
- rm $(OUTFILE)
touch $(SRC)
###########################################################################################

测试文件

/* ***********************************************************
* File: mfc2.cpp
* Author: think.hy@gmail.com
* Refer: http://www.codersource.net/mfc_tutorial_Part2.html
*********************************************************** */
// MFC2.cpp - MFC Tutorial Part 2 from CoderSource.net

#include "AFXWIN.H"

class MFC_Tutorial_Window :public CFrameWnd
{
public :
MFC_Tutorial_Window()
{
Create(NULL ,"MFC Tutorial Part 2 CoderSource Window" );
}

void OnLButtonDown(UINT nFlags, CPoint point);
DECLARE_MESSAGE_MAP()
};

BEGIN_MESSAGE_MAP(MFC_Tutorial_Window, CFrameWnd)
ON_WM_LBUTTONDOWN() // Macro to map the left button click to the handler
END_MESSAGE_MAP()

void MFC_Tutorial_Window::OnLButtonDown(UINT nFlags, CPoint point)
{
CFrameWnd::OnLButtonDown(nFlags, point);
MessageBox("Hello, World" );
}

class MyApp :public CWinApp
{
MFC_Tutorial_Window *wnd;
public :
BOOL InitInstance()
{
wnd = new MFC_Tutorial_Window();
m_pMainWnd = wnd;
m_pMainWnd->ShowWindow(1 );
return 1 ;
}
//CDialog cd;
};

MyApp theApp;
在窗口里左击,弹出一个MessageBox,COOL! 按扭中出现乱码的问题待明天解决。
参考资料:http://www.codersource.net/mfc_tutorial_Part1.html
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值