在Delphi 例程中没有类似于C中的system
函数
int system(const char* command);
用下面的方法可以让你在Delphi中使用msvc runtime的函数
program YourProg;
function system(command:PChar):Integer;cdecl;external "msvcrt.dll" name "system";
begin
system("pause");
end.
在Delphi 例程中没有类似于C中的system
函数
int system(const char* command);
用下面的方法可以让你在Delphi中使用msvc runtime的函数
program YourProg;
function system(command:PChar):Integer;cdecl;external "msvcrt.dll" name "system";
begin
system("pause");
end.
用gem安装wxruby2
c:>gem install wxruby2-preview
在文件前面增加下列代码
begin
require "wx"
rescue LoadError => no_wx_err
begin
require "rubygems"
require "wx"
rescue LoadError
raise no_wx_err
end
end
测试:
class TroutApp < Wx::App
def on_init
frame = Wx::Frame.new(nil, -1, "Tiny wxRuby Application")
panel = Wx::StaticText.new(frame, -1, "You are a trout!",
Wx::Point.new(-1,1), Wx::DEFAULT_SIZE,
Wx::ALIGN_CENTER)
frame.show
end
end
TroutApp.new.main_loop
update:
FOX界面库
require "fox16"
include Foxapplication = FXApp.new("Hello", "FoxTest")
application.init(ARGV)
main = FXMainWindow.new(application, "Hello", nil, nil, DECOR_ALL)
FXButton.new(main, "&Hello, World!", nil, application, FXApp::ID_QUIT)
application.create()
main.show(PLACEMENT_SCREEN)
application.run()
问题:
有时候我们希望用一个函数处理一系列的菜单命令
分析:
在处理菜单命令的函数中必须能知道菜单的ID;
以前用过ON_COMMANDRANGE宏;
在afxmsg.h中发现有个ON_COMMAND_EX宏;
解决:
BEGIN_MESSAGE_MAP(CClassName, CBaseClass)
...
ON_COMMAND_EX_RANGE(ID_MENUITEM_FIRST,ID_MENUITEM_FIRST, OnMenuItemClicked)
...
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
因为
#define ON_COMMAND_EX_RANGE(id, idLast, memberFxn)
{ WM_COMMAND, CN_COMMAND, (WORD)id, (WORD)idLast, AfxSig_bw,
(AFX_PMSG)(BOOL (AFX_MSG_CALL CCmdTarget::*)(UINT))&memberFxn },
而且
enum AfxSig{
...
AfxSig_bw = AfxSig_bb, // BOOL (UINT)
...
}
所以
BOOL CClassName::OnMiWlToSubDesk(UINT nID)
{
int nMenuIndex = nID - ID_MENUITEM_FIRST;
return TRUE;
}
问题:
在MFC程序中需要响应显示器分辨率变化
分析:
如果分辨率变化会产生消息并发送给所有程序,那么只要响应该消息就可以了
解决:
通过在winuser.h中搜索DISPLAY找到
#define WM_DISPLAYCHANGE 0x007E
由于VC的ClassWizard无法自动生成响应处理该消息的成员函数,
所以要手工增加消息映射
在afxmsg_.h中找到
#define ON_MESSAGE(message, memberFxn)
{ message, 0, 0, 0, AfxSig_lwl,
(AFX_PMSG)(AFX_PMSGW)
(static_cast< LRESULT (AFX_MSG_CALL CWnd::*)(WPARAM, LPARAM) >
(memberFxn)) },
所以可以在相应的类中增加消息映射和函数:
函数:
// Generated message map functions
//{{AFX_MSG(CNuTsWMDlg)
virtual BOOL OnInitDialog();
...
afx_msg void OnDislayChanged(WPARAM wParam,LPARAM lParam);
...
//}}AFX_MSG
DECLARE_MESSAGE_MAP()
消息映射:
“c++
BEGIN_MESSAGE_MAP(CNuTsWMDlg, CDialog)
//{{AFX_MSG_MAP(CNuTsWMDlg)
…
ON_MESSAGE(WM_DISPLAYCHANGE,OnDislayChanged)
…
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
“`