Archive

Posts Tagged ‘program’

Fortran创始人John W. Backus辞世

March 21st, 2007 No comments

昨天还提到了Fortran,没有想到今天中午就看到John W. Backus去世的消息,真有些巧合。

其实我现在才真正知道John W. Backus是Fortran的创始人,但是对Fortran的了解却要追溯到1998年。Fortran是我接触的第一门计算机语言(以前的QBasic不算),对它的理解最终在一定程度上是今天很多事情的开始,直到今天,我每天还要面对许多的Fortran代码。

Fortran作为第一门高级语言,有着重要的历史意义。虽然今天我更喜欢C++。

向John W. Backus表示崇高的敬意。

Categories: 随心所记 Tags: ,

MFC group上一个有意思的讨论

March 20th, 2007 No comments

今天看了一个比较有意思的灌水,好玩。

1. 某君提了一个问题,归纳一下就说,我的程序有问题(具体有价值的材料没有),怎么解决呢?

ermutarra Mar 20, 4:00 am

Newsgroups: microsoft.public.vc.mfc

Subject: Can’t change content of edit box !?

Hi all,

I have a dialog window for the user to enter some data and then the program goes and does something with it. The edit controls used for the data are initialised to some default values but then I don’t seem to be able to change the value (these have NOT been disabled and are NOT read-only). Can anybody tell me what’s going on and how to fix it so that I can change the values?

Thank you very much in advance.

Noelia

2. 这样的问题肯定是没法回答的,不过一位MVP这样RE的 [阅读剩余部分…]

Categories: 快乐每一天 Tags: , ,

Displaying a Bitmap from a BMP File

September 13th, 2006 No comments

发件人: wangxl [mailto:hamo2k@163.com]
发送时间: 2006年9月13日 23:09
收件人: ‘wangxianlei@cabrtech.com’
主题: Displaying a Bitmap from a BMP File

Displaying a Bitmap from a BMP File
Rating:

  Ramakrishna Talla (view profile)
April 3, 2003

Environment: MFC, Visual C++ 6.0, Windows 2000
(continued)

The following code fragment shows how to read an image from a BMP file and display it in your MFC application window. You could see several articles on the same focus; the one I present here is very simple, with just a few lines of code. The code given below has been tested with Visual C++ 6.0 on Win 2000.

Create a single document interface application; select CFormView as the base class for the application’s view base class. Click on the resource tab on the project explorer to navigate to the resource editor and drag a button to the dialog resource. Double-click the button to add a handler to the application’s view class, as shown below.

void AppView::OnButton1()
{
}

Step 1: Load the Image File

Call the following:

CString szFilename ("C:\Talla\yourimg.bmp");
HBITMAP hBmp = (HBITMAP)::LoadImage(
                NULL,
                szFilename,
                IMAGE_BITMAP,
                0,
                0,
                LR_LOADFROMFILE|LR_CREATEDIBSECTION
                );

Step 2: Create a Bitmap Object and Attach It to the Object

CBitmap bmp;
bmp.Attach(hBmp);

Step 3: Create a Memory DC and Select the BMP to It

You also need to store the old BMP pointer:

CClientDC dc(this);
CDC bmDC;
bmDC.CreateCompatibleDC(&dc);
CBitmap *pOldbmp = bmDC.SelectObject(&bmp);

Step 4: Get the BMP Height and Width

Obtain this from CBitmap’s GetBitmap function.

BITMAP  bi;
  bmp.GetBitmap(&bi);

Step 5: Get the Block of Pixels from memoryDC to the Screen

Use CClientDC’s BitBlt function. Next, re-select the old BMP. The complete code is as follows:

void AppView::OnButton1()
{
   CString szFilename("C:\Talla\yourimg.bmp");
   HBITMAP hBmp = (HBITMAP)::LoadImage(NULL,szFilename,
                             IMAGE_BITMAP,0,0,
                             LR_LOADFROMFILE|LR_CREATEDIBSECTION);

   CBitmap bmp;
   bmp.Attach(hBmp);

   CClientDC dc(this);
   CDC bmDC;
   bmDC.CreateCompatibleDC(&dc);
   CBitmap *pOldbmp = bmDC.SelectObject(&bmp);

   BITMAP  bi;
   bmp.GetBitmap(&bi);

   dc.BitBlt(0,0,bi.bmWidth,bi.bmHeight,&bmDC,0,0,SRCCOPY);

   bmDC.SelectObject(pOldbmp);
}

Borland CaliberRM Integrates with Visual Studio to Bring Sophistication to Requirements Management
Get DB2 Express-C 9. Free to Develop, Deploy, Distribute. No limits–just data. Download Now!
Webcast: Linux on Multi-Core–WAS CE and the Open Stack Appliance
Learn how to navigate the key issues that affect developing and deploying mobile applications.
Developer.com Webcast: Defining Your Own Software Development Methodology.

Categories: 技术讨论 Tags: ,

auto_ptr的应用

September 13th, 2006 No comments

template<class T>
class auto_ptr {
public:
typedef T element_type;
explicit auto_ptr(T *p = 0) throw();
auto_ptr(const auto_ptr<T>& rhs) throw();
auto_ptr<T>& operator=(auto_ptr<T>& rhs) throw();
~auto_ptr();
T& operator*() const throw();
T *operator->() const throw();
T *get() const throw();
T *release() const throw();
};
The class describes an object that stores a pointer to an allocated object
of type T. The stored pointer must either be null or designate an object
allocated by a new expression. The object also stores an ownership
indicator. An object constructed with a non-null pointer owns the pointer.
It transfers ownership if its stored value is assigned to another object.
The destructor for auto_ptr<T> deletes the allocated object if it owns it.
Hence, an object of class auto_ptr<T> ensures that an allocated object is
automatically deleted when control leaves a block, even via a thrown
exception.

—–
可以自动释放对象。

auto_ptr<C> p(new C());
p->DoSomething();

Categories: 技术讨论 Tags:

由定义消息引起的Debug版正常而Release版异常的问题及解决方案

September 1st, 2006 No comments

在使用了自定义消息的程序中,有可能出现Debug版正常而Release版非法操作的问题。

下面是一种原因以及其解决办法:

问题的描述:
================

定了了自定义消息: #define WM_DEMOWORK WM_USER+1
消息相应函数: afx_msg void OnDemoWork();
消息映射: ON_MESSAGE(WM_DEMOWORK,OnDemoWork)

上述代码编译没有任何错误,并且在Debug版中运行正常,但是在Release版中会报非法
操作。

原因:
================
在MFC中,ON_MESSAGE宏的定义如下:
#define ON_MESSAGE(message, memberFxn) { message, 0, 0, 0, AfxSig_lwl,
(AFX_PMSG)(AFX_PMSGW)(LRESULT (AFX_MSG_CALL CWnd::*)(WPARAM,
LPARAM))&memberFxn },

可见,在ON_MESSAGE宏中认为消息相应函数memberFxn的原型为 LRESULT
(*pProc)(WPARAM, LPARAM)的形式,它有两个参数,
分别为WPARAM, LPARAM。

解决方案
===============
了解具体的原因后,解决就非常容易。有两个方案:

方案1:
修改消息相应函数的定义,增加函数参数。如:
afx_msg void OnDemoWork(WPARAM wParam, LPARAM lParam);

方案2:
如果消息相应函数中不需要消息参数,可以利用另外一个消息映射宏ON_MESSAGE_VOID
即可。如
ON_MESSAGE_VOID(WM_DEMOWORK,OnDemoWork)

其中ON_MESSAGE_VOID的宏定义为:
#define ON_MESSAGE_VOID(message, memberFxn) { message, 0, 0, 0, AfxSig_vv,
(AFX_PMSG)(AFX_PMSGW)(void (AFX_MSG_CALL CWnd::*)(void))&memberFxn },

其中消息相应函数原型为void (*pProc)(void)。
;

Categories: 技术讨论 Tags: ,

用VC纯资源dll解决国际化问题

August 22nd, 2006 No comments

由于MFC应用程序也有自己的资源文件,当你调用MFC函数比如 CString::LoadString
或其它 LoadIcon 时,MFC应用程序框架首先跟踪搜索EXE文件的资源,然后才是DLL和
MFC的资源,因此在使用纯资源DLL时候,必须人为先改变资源的搜索顺序,可以通过使
用 AfxSetResourceHandle 函数来实现,具体实现如下:

BOOL CMultilanguageApp::InitInstance()
{
AfxEnableControlContainer();

if (m_bChinese)
{
m_hLangDLL=::LoadLibrary(“chinese.dll”);
}
else
{
m_hLangDLL=::LoadLibrary(“english.dll”);
}

AfxSetResourceHandle(m_hLangDLL);

……
}

Categories: 技术讨论 Tags: ,