Archive

Posts Tagged ‘MFC’

ADO连接SQL Server的问题解决

November 6th, 2007 No comments

这是在Hexapod项目中遇到的头疼了很久的问题,今天终于得到了解决。回头看来,其实都非常简单。

使用ADO进行数据库操作可以有许多便利之处,比如兼容多种数据库,速度快等,在此不再赘述。

在项目中使用了A set of ADO classes – version 2.20提供的ADO封装类,ADO的connection string参考了ADO Connection Strings

其中遇到的问题主要和这几个问题有关:

  • SQLServer的身份验证方式
  • SQLServer的实例名称

先说第一个,身份验证有两种方式:windows账户验证和SQLServer本身的验证。如果使用SQLServer的身份验证,链接字符串为:

“Provider=sqloledb;Data Source=(local);”
“Initial Catalog=master;User Id=sa;Password=123456;”

如果使用Windows账户验证,则为:

“Provider=sqloledb;Data Source=(local);”
“Initial Catalog=master;Integrated Security=SSPI;”

第二个,从SQLServer2000开始,支持一台服务器上运行多个SQLServer实例,互不影响。如果不是默认的实例名称,则需要在Data Source中提供,如:

“Data Source=(local)\HexaDatabase;”

点破的就简单了,第一次用的时候还是真头疼,以此备忘。

 

Categories: 随心所记 Tags: , ,

让MFC程序具有XP的风格(style)

October 30th, 2007 No comments

有两种方法可以使vc6或者vc2003编译出来的MFC程序具有XP的风格,当然这需要在Windows XP系统下运行。

方法一,使用外置的manifest描述文件
在exe文件所在目录中建立一个同名的.manifest文件。假设你有一个可执行文件app1.exe,则建立app1.exe.manifest。注意该文件的文件名是在exe的完整文件名后加.manifest。该文件的内容如下:

Code:

< ?xml version="1.0" encoding="UTF-8" standalone="yes"?>


Your app description here








方法二,使用内置的manifest描述文件
这种方法可以将manifest文件编译到exe文件当中,发布的时候不需要额外增加一个.manifest文件。
步骤如下:
[阅读剩余部分…]

Categories: 技术讨论 Tags: ,

Dive into PASSCAL call

June 25th, 2007 No comments

It’s a thread on microsoft.public.vc.mfc group and the orial url is :old skool vc++ 1.0.

I will take it as some English discussion material and I has no copyright of the following text.

从中可以看到和只懂C#的人交流寄存器,堆栈是多么困难的事情。Scott McPhilips 和Doug Harrison都是很有耐心的MVP. 最后Doug Harrison的总结似乎也不错。

[阅读剩余部分…]

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: , ,

一个小故事

December 11th, 2006 No comments

这件事情已经过去几天了,但是回想起来总还是觉得比较有意思,所以发上来做个纪念。

事情发生在microsoft.public.vc.mfc新闻组上面,是一个英文的新闻组。然后在某天,有位叫“松竹”的同学发了一篇帖子,询问关于CEdit::GetSel的问题。这本来也很正常,不过唯一例外的是这篇帖子使用中文写的。于是故事开始了…

由于字符集的问题,老外看来肯定是乱码,于是有位叫Ajay Kalra的MVP就re了一句简单的“That’s all right”,或许就不想再离了,然后我们这位“松竹”就re Ajay Kalra的回帖,继续用中文写了很长一段描述。于是Ajay Kalra和Tom Serface开始讨论到底是自己的字体不对呢,还是怎么回事。其中有个建议说应该试一下UNICODE编码,另外一个同意,然后说了一句“I think you are right. I missed that completely. Next time I will put on my UNICODE glasses.”,很幽默的一句话。

当然故事并没有结束,因为这位同学根本就不是用的UNICODE的字符集,理所当然的这两位先生看到的还是乱码。直到2天之后,另外一位fiveight的看不下去了,re了一下,说“It is not your font’s fault, Tom.This artical is writen in Chinese,and uses GB2312 code.”,故事才告结束,否则还不知道那两位老外要研究多久。 : )

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: ,