Showing posts with label Visual Studio. Show all posts
Showing posts with label Visual Studio. Show all posts

Sunday, May 4, 2008

Change color of CStatic object.

.h file
(add this function to your class)
afx_msg HBRUSH OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor);
// Called to change color of text
.cpp file
(add this to your message map)
ON_WM_CTLCOLOR()
(add this to the file too)
HBRUSH CYourDialog::OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor)
{
// Call original functions
HBRUSH hbr = CDialog::OnCtlColor(pDC, pWnd, nCtlColor);

// Create a blue color
COLORREF textColor = RGB(0, 0, 255);

// Set text color
if (pWnd->GetDlgCtrlID() == yourstatic)
{
pDC->SetTextColor(textColor);

}

// Return result of original function
return hbr;

}

Tuesday, April 22, 2008

麻烦的OCCI

在Windows环境下用OCCI编程真是一件很麻烦的事情,尽管到目前为止,我还没有在UNIX环境下测试过OCCI,数据库厂商(尤其是这种大型数据库)对于UNIX环境的重视和支持程度要远远超过了Windows环境,料想不会有太大的问题。

我用的环境是Windows XP SP2 5.1.2600,Oracle 10g 10.2.0.1.0,Visual C++ 2005(VS8)。按照惯例,在VS8里面添加了include路径(通常是%ORACLE_HOME%\oci\include),以及新的链接路径(通常是%ORACLE_HOME%\oci\lib)。编译通过、链接通过,运行时出现异常,通过try - catch机制捕获到的异常为“ORA-24960: 属性OCI_ATTR_USERNAME的长度大于最大允许长度255。”在各个论坛上以及OTN上对这个问题讨论的很多,感觉很大程度上这个问题似乎与VC++和Oracle的版本匹配有关。于是从OTN(Oracle C++ Call Interface - Downloads)上可以下载到用于Visual C++ 2005(VS8)上的相关库文件,并且按照安装说明把这些库文件解压缩在%ORACLE_HOME%\oci\lib\MSVC\vc8目录中,重新编译通过、链接通过,运行时出现了同样的问题(ORA-24960: 属性OCI_ATTR_USERNAME的长度大于最大允许长度255。)

此时注意到安装文件中提示在DEBUG编译模式中要使用oraocci10d.lib而不是oraocci10.lib作为链接库。调整以后出现了新的问题,首先是说找不到oraocci10d.dll,把该目录加入环境变量PATH之后(这时要注意一点,必须重新启动VS,系统的环境变量才会生效,换句话说,VS只在开始运行时检查一下环境变量。),又说找不到MSVCR80D.dll。而此时注意到Release版本的编译已经没有问题了,但是用Release版本会给调试过程带来很多麻烦,很不甘心。

如果直接把$(VCInstallDir)VC\redist\Debug_NonRedist\x86\Microsoft.VC80.DebugCRT加入PATH,编译链接通过,报错没有通过manifest加载动态链接库,于是耐心地阅读了MSDN相关文章,将Porject->Properties中的Configuration Properties\C/C++\Code Generation\Runtime Library设置为/MDd (Multi-threaded Debug DLL),出现新错误,/MDd选项与静态链接MFC库选项矛盾,于是在stdafx.h中添加“#define _AFXDLL”,最终所有问题得到解决。

所以尽管经过很多尝试,过程极其复杂,但结论总结起来十分简单:
1、不要选择使用静态链接MFC;
2、从OTN(Oracle C++ Call Interface - Downloads)下载VC8的OCCI库文件;
3、将OCCI库文件安装到%ORACLE_HOME%\oci\lib\MSVC\vc8目录中,将该目录加入环境变量;
4、Debug编译版本中选择oraocci10d.lib作为链接库文件,并使用/MDd编译选项。Release版本中选择oraocci.lib作为链接库文件,并使用/MD编译选项。

Sunday, April 20, 2008

OCCI with Visual Studio 2005

只写了一句:
Environment *env;

编译错误:
1>d:\documents\visual studio 2005\projects\oci_test\oci_test\oci_testdlg.h(16) : error C2143: syntax error : missing ';' before '*'
1>d:\documents\visual studio 2005\projects\oci_test\oci_test\oci_testdlg.h(16) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
1>d:\documents\visual studio 2005\projects\oci_test\oci_test\oci_testdlg.h(16) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int

解决方法:
using namespace oracle::occi;

Sunday, April 6, 2008

Using GDI+ in MFC Applications

1. In Visual C++ 2005 go to Project->Properties, Type gdiplus.lib into the Configuration Properties/Linker/Input/Additional Dependencies.
2. Add the following line to stdafx.h:
#include <gdiplus.h>

using namespace Gdiplus;
#pragma comment(lib, "gdiplus.lib")
3. Intialize the GDI+ resources. Add this to your CWinApp derived class as member:
GdiplusStartupInput gdiplusStartupInput;
ULONG_PTR gdiplusToken;
At InitInstance(), add:
GdiplusStartup(&gdiplusToken, &gdiplusStartupInput, NULL);

// note: GdiplusStartup() should be added before the
// following sentence:
CWinApp::InitInstance();
4. Your application is ready to consume GDI+ now.
5. Upon exit, release GDI+ resources. Add the following line to ExitInstance():
GdiplusShutdown(gdiplusToken);