Visual C++编程技巧之13
这里的 Visual C++ 窍门由 Visual C++ 开发者杂志提供.
建立一束特殊效果的黑光在 Direct3D
作者 Peter Kovach
下面的例子告诉您如何建立一束光线并且将它设置为一束 黑光:
//
// g_lpD3D3 holds the address of an IDirect3D3 interface
//
LPDIRECT3DLIGHT g_lpD3DLight;
HRESULT hr;
hr = g_lpD3D3->CreateLight (&g_lpD3DLight, NULL);
if (SUCCEEDED(hr))
{
//
// g_lpD3DLight variable is a valid pointer to an IDirect3D3 interface.
//
D3DLIGHT2 g_light;
HRESULT hr;
//
// Initialize the structure
//
ZeroMemory(&g_light, sizeof(D3DLIGHT2));
g_light.dwSize = sizeof(D3DLIGHT2); // MUST set the size!
//
// Create our Dark point light.
//
g_light.dltType = D3DLIGHT_POINT;
g_light.dcvColor.r = -0.5f;
g_light.dcvColor.g = -0.5f;
g_light.dcvColor.b = -0.5f;
//
// Position the light high in the scene, and behind the viewer.
// These coordinates are in world space, so
// the viewer could be anywhere in world space.
// For this example, the viewer is at the origin of world space.
//
g_light.dvPosition.x = 0.0f;
g_light.dvPosition.y = 1000.0f;
g_light.dvPosition.z = -100.0f;
//
// Don't attenuate
//
g_light.dvAttenuation0 = 1.0f;
g_light.dvRange = D3DLIGHT_RANGE_MAX;
//
// Make the light active light.
//
g_light.dwFlags = D3DLIGHT_ACTIVE;
//
// Set the property info for this light.
// We have to cast the LPD3DLIGHT2 to be
// an LPD3DLIGHT.
//
hr = g_lpD3DLight->SetLight((LPD3DLIGHT)&g_light);
if (SUCCEEDED(hr))
{
//
// Add the light to the viewport here.
//
}
else
return hr;
}
else
return hr;
2:列表显示所有网上邻居
有很多网友问过这个问题,今天看精华版没有相关内容,
所以上贴。
网上邻居的查找在www.codeguru.com上有例子,只是它
把它做成了类,本是好事,但对大家理解它的原理增加了难度,
所以现在把它实现在一对话框中,以便大家能一目了然。
#include <winnetwk.h>
#pragma comment(lib, “mpr.lib”)
BOOL CNetEnum2Dlg::Enumerate(LPNETRESOURCE lpNetRC_p)
{
HANDLE hEnum = 0;
DWORD dwScope = RESOURCE_GLOBALNET ;
DWORD dwType = RESOURCETYPE_ANY ;
DWORD dwResult = WNetOpenEnum(
dwScope, // scope of enumeration
dwType, // resource types to list
0, // enumerate all resources
lpNetRC_p, // pointer to resource structure (NULL at first time)
&hEnum // handle to resource
) ;
if( dwResult != NO_ERROR )
return FALSE;
DWORD dwBuffer = 16384 ; // 16K is reasonable size
DWORD dwEntries = 0xFFFFFFFF ; // enumerate all possible entries
LPNETRESOURCE lpnrLocal = 0;
BOOL bRet = TRUE;
//try
{
do
{
// first allocate buffer for NETRESOURCE structures ...
lpnrLocal = (LPNETRESOURCE) GlobalAlloc( GPTR, dwBuffer ) ;
dwResult = WNetEnumResource(
hEnum, // resource-handle
&dwEntries,
lpnrLocal,
&dwBuffer
) ;
if( dwResult == NO_ERROR )
{
for( register DWORD i = 0 ; i {
CString nsname;
nsname = lpnrLocal[i].lpRemoteName;
nsname += " ";
nsname +=lpnrLocal[i].lpLocalName;
nsname += " ";
nsname +=lpnrLocal[i].lpComment;
m_netList.AddString(nsname); // m_netList defined in NetEnumDlg2.h
: CListBox m_netList;
if( RESOURCEUSAGE_CONTAINER ==
(lpnrLocal[i].dwUsage & RESOURCEUSAGE_CONTAINER) &&
lpnrLocal[i].dwDisplayType != RESOURCEDISPLAYTYPE_SERVER )
if( !Enumerate( &lpnrLocal[i]) )
{
//TRACE0( "CNetwork::Enumerate(): recursiv call failed\n"
);
//throw CNetworkBreak(FALSE);
return FALSE;
}
}
} else if( dwResult != ERROR_NO_MORE_ITEMS )
{
//AfxMessageBox("WNetEnumResource");
return FALSE;
}
} while( dwResult != ERROR_NO_MORE_ITEMS );
}
if( lpnrLocal )
GlobalFree((HGLOBAL) lpnrLocal) ;
WNetCloseEnum(hEnum) ;
return bRet;
}
void CNetEnum2Dlg::OnListWNet()
{
Enumerate(0);
}