菜鸟求助

guyuxiangtheone 2011-05-06 09:42:20

#include <windows.h>
#include <d3d9.h>

LPDIRECT3D9 g_pD3D = NULL;
LPDIRECT3DDEVICE9 g_pd3dDevice = NULL;
HRESULT InitializeD3D(HWND hWnd)
{
if(NULL == (g_pD3D = Direct3DCreate9(D3D_SDK_VERSION)))
return false;
D3DPRESENT_PARAMETERS d3dpp;
ZeroMemory(&d3dpp,sizeof(d3dpp));
d3dpp.Windowed = TRUE;
d3dpp.SwapEffect = D3DSWAPEFFECT_DISCARD;
d3dpp.BackBufferFormat = D3DFMT_UNKNOWN;

if(FAILED(g_pD3D->CreateDevice(D3DADAPTER_DEFAULT,D3DDEVTYPE_HAL,hWnd,D3DCREATE_SOFTWARE_VERTEXPROCESSING,&d3dpp,&g_pd3dDevice)))
{
return 0;
}
return 1;
}
void Render()
{
g_pd3dDevice->Clear(0,NULL,D3DCLEAR_TARGET,D3DCOLOR_XRGB(45,50,170),1.0f,0);
if (SUCCEEDED(g_pd3dDevice->BeginScene()))
{
g_pd3dDevice->EndScene();
}
g_pd3dDevice->Present(NULL,NULL,NULL,NULL);

}
void Cleanup()
{
if (g_pd3dDevice != NULL)
g_pd3dDevice->Release();
if (g_pD3D != NULL)
g_pD3D->Release();
}
LRESULT WINAPI MsgProc(HWND hWnd,UINT msg,WPARAM wParam,LPARAM lParam)
{
switch(msg)
{
case WM_DESTROY:
Cleanup();
PostQuitMessage(0);
return 0;
case WM_PAINT:
Render();
ValidateRect(hWnd,NULL);
return 0;
}
}
int WINAPI WinMain(HINSTANCE hInst,HINSTANCE,LPSTR,INT)
{
WNDCLASSEX wc = {sizeof(WNDCLASSEX),CS_CLASSDC,MsgProc,0L,0L,GetModuleHandle(NULL),NULL,NULL,NULL,NULL,L"ClassName",NULL};
RegisterClassEx(&wc);
HWND hWnd = CreateWindow(L"ClassName",L"aaaa",WS_OVERLAPPEDWINDOW,200,100,600,500,NULL,NULL,wc.hInstance,NULL);
if (SUCCEEDED(InitializeD3D(hWnd)))
{
ShowWindow(hWnd,SW_SHOWDEFAULT);
UpdateWindow(hWnd);
MSG msg;
ZeroMemory(&msg,sizeof(msg));
//GetMessage(&msg,0,0,0);
while(msg.message != WM_QUIT)
{
if(PeekMessage(&msg,NULL,0U,0U,PM_REMOVE))
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
else
{
Render();
}
}
UnregisterClass(L"ClassName",wc.hInstance);
return 0;
}
}

大家麻烦帮我看看这个代码 只是为了 用VCD3D入门做的小窗口
现在的问题是 代码跑过了 和 书上的效果不符合
少了窗口该有的那个蓝色上边栏就是写窗口名字的那个
...全文
187 11 打赏 收藏 转发到动态 举报
写回复
用AI写文章
11 条回复
切换为时间正序
请发表友善的回复…
发表回复
guyuxiangtheone 2011-05-06
  • 打赏
  • 举报
回复
没人能教下么??
guyuxiangtheone 2011-05-06
  • 打赏
  • 举报
回复
发现不管换什么样式都是不显示的 所以应该和样式无关吧
guyuxiangtheone 2011-05-06
  • 打赏
  • 举报
回复
不是风格不符是没有边框
'dxFramework.exe': Loaded 'C:\Documents and Settings\7fgame\My Documents\Visual Studio 2008\Projects\dxFramework\Debug\dxFramework.exe', Symbols loaded.
'dxFramework.exe': Loaded 'C:\WINDOWS\system32\ntdll.dll'
'dxFramework.exe': Loaded 'C:\WINDOWS\system32\kernel32.dll'
'dxFramework.exe': Loaded 'C:\WINDOWS\system32\d3d9.dll'
'dxFramework.exe': Loaded 'C:\WINDOWS\system32\d3d8thk.dll'
'dxFramework.exe': Loaded 'C:\WINDOWS\system32\gdi32.dll'
'dxFramework.exe': Loaded 'C:\WINDOWS\system32\user32.dll'
'dxFramework.exe': Loaded 'C:\WINDOWS\system32\msvcrt.dll'
'dxFramework.exe': Loaded 'C:\WINDOWS\system32\advapi32.dll'
'dxFramework.exe': Loaded 'C:\WINDOWS\system32\rpcrt4.dll'
'dxFramework.exe': Loaded 'C:\WINDOWS\system32\secur32.dll'
'dxFramework.exe': Loaded 'C:\WINDOWS\system32\version.dll'
'dxFramework.exe': Loaded 'C:\WINDOWS\system32\winmm.dll'
'dxFramework.exe': Loaded 'C:\WINDOWS\WinSxS\x86_Microsoft.VC90.DebugCRT_1fc8b3b9a1e18e3b_9.0.21022.8_x-ww_597c3456\msvcr90d.dll'
'dxFramework.exe': Loaded 'C:\WINDOWS\system32\imm32.dll'
'dxFramework.exe': Loaded 'C:\WINDOWS\system32\lpk.dll'
'dxFramework.exe': Loaded 'C:\WINDOWS\system32\usp10.dll'
'dxFramework.exe': Loaded 'C:\WINDOWS\system32\uxtheme.dll'
'dxFramework.exe': Loaded 'C:\WINDOWS\system32\msctf.dll'
'dxFramework.exe': Loaded 'C:\WINDOWS\system32\msctfime.ime'
'dxFramework.exe': Loaded 'C:\WINDOWS\system32\ole32.dll'
'dxFramework.exe': Loaded 'C:\WINDOWS\system32\d3d9d.dll'
'dxFramework.exe': Loaded 'C:\WINDOWS\system32\d3dx9d_33.dll'
D3D9 Helper: Enhanced D3DDebugging disabled; Application was not compiled with D3D_DEBUG_INFO
Direct3D9: (INFO) :======================= Hal SWVP device selected

Direct3D9: (INFO) :Using X3D PSGP
这是DEBUG OUTPUT
也没说哪里创建失败了呀
wanmeiluck123 2011-05-06
  • 打赏
  • 举报
回复
这些我还不懂,不过建议楼主重新输一遍关键代码吧
guyuxiangtheone 2011-05-06
  • 打赏
  • 举报
回复
	
WNDCLASSEX wc = {sizeof(WNDCLASSEX),CS_CLASSDC,MsgProc,0L,0L,GetModuleHandle(NULL),NULL,NULL,NULL,NULL,L"ClassName",NULL};
RegisterClassEx(&wc);
HWND hWnd = CreateWindow(L"ClassName",L"DX9 AAAAAAAA",WS_OVERLAPPEDWINDOW,200,100,600,500,NULL,NULL,wc.hInstance,NULL);
//

//
UnregisterClass(L"ClassName",wc.hInstance);
我看了下没什么问题啊 为什么生成不了边框呢??
ryfdizuo 2011-05-06
  • 打赏
  • 举报
回复
[Quote=引用 3 楼 guyuxiangtheone 的回复:]

其实就想知道如果创建个窗口的时候 是如何创建 WINDOWS窗口的外框的??
[/Quote]
CreateWindow函数的第三个参数dwstyle指定窗口样式。你说的是窗口的caption,标题栏。
http://baike.baidu.com/view/1001690.htm
书虫 2011-05-06
  • 打赏
  • 举报
回复
如果样式和你预想的不一样,那你的WNDCLASSEX 肯定是不符合的,你对比看看,哪个有问题咯!
书虫 2011-05-06
  • 打赏
  • 举报
回复
WNDCLASSEX Structure

--------------------------------------------------------------------------------

The WNDCLASSEX structure contains window class information. It is used with the RegisterClassEx and GetClassInfoEx functions.

The WNDCLASSEX structure is similar to the WNDCLASS structure. There are two differences. WNDCLASSEX includes the cbSize member, which specifies the size of the structure, and the hIconSm member, which contains a handle to a small icon associated with the window class.


Syntax

typedef struct {
UINT cbSize;
UINT style;
WNDPROC lpfnWndProc;
int cbClsExtra;
int cbWndExtra;
HINSTANCE hInstance;
HICON hIcon;
HCURSOR hCursor;
HBRUSH hbrBackground;
LPCTSTR lpszMenuName;
LPCTSTR lpszClassName;
HICON hIconSm;
} WNDCLASSEX, *PWNDCLASSEX;
Members

cbSize
Specifies the size, in bytes, of this structure. Set this member to sizeof(WNDCLASSEX). Be sure to set this member before calling the GetClassInfoEx function.
style
Specifies the class style(s). This member can be any combination of the Class Styles.
lpfnWndProc
Pointer to the window procedure. You must use the CallWindowProc function to call the window procedure. For more information, see WindowProc.
cbClsExtra
Specifies the number of extra bytes to allocate following the window-class structure. The system initializes the bytes to zero.
cbWndExtra
Specifies the number of extra bytes to allocate following the window instance. The system initializes the bytes to zero. If an application uses WNDCLASSEX to register a dialog box created by using the CLASS directive in the resource file, it must set this member to DLGWINDOWEXTRA.
hInstance
Handle to the instance that contains the window procedure for the class.
hIcon
Handle to the class icon. This member must be a handle to an icon resource. If this member is NULL, the system provides a default icon.
hCursor
Handle to the class cursor. This member must be a handle to a cursor resource. If this member is NULL, an application must explicitly set the cursor shape whenever the mouse moves into the application's window.
hbrBackground
Handle to the class background brush. This member can be a handle to the physical brush to be used for painting the background, or it can be a color value. A color value must be one of the following standard system colors (the value 1 must be added to the chosen color). If a color value is given, you must convert it to one of the following HBRUSH types:
COLOR_ACTIVEBORDER
COLOR_ACTIVECAPTION
COLOR_APPWORKSPACE
COLOR_BACKGROUND
COLOR_BTNFACE
COLOR_BTNSHADOW
COLOR_BTNTEXT
COLOR_CAPTIONTEXT
COLOR_GRAYTEXT
COLOR_HIGHLIGHT
COLOR_HIGHLIGHTTEXT
COLOR_INACTIVEBORDER
COLOR_INACTIVECAPTION
COLOR_MENU
COLOR_MENUTEXT
COLOR_SCROLLBAR
COLOR_WINDOW
COLOR_WINDOWFRAME
COLOR_WINDOWTEXT
The system automatically deletes class background brushes when the class is unregistered by using UnregisterClass. An application should not delete these brushes.

When this member is NULL, an application must paint its own background whenever it is requested to paint in its client area. To determine whether the background must be painted, an application can either process the WM_ERASEBKGND message or test the fErase member of the PAINTSTRUCT structure filled by the BeginPaint function.

lpszMenuName
Pointer to a null-terminated character string that specifies the resource name of the class menu, as the name appears in the resource file. If you use an integer to identify the menu, use the MAKEINTRESOURCE macro. If this member is NULL, windows belonging to this class have no default menu.
lpszClassName
Pointer to a null-terminated string or is an atom. If this parameter is an atom, it must be a class atom created by a previous call to the RegisterClass or RegisterClassEx function. The atom must be in the low-order word of lpszClassName; the high-order word must be zero.
If lpszClassName is a string, it specifies the window class name. The class name can be any name registered with RegisterClass or RegisterClassEx, or any of the predefined control-class names.

hIconSm
Handle to a small icon that is associated with the window class. If this member is NULL, the system searches the icon resource specified by the hIcon member for an icon of the appropriate size to use as the small icon.
guyuxiangtheone 2011-05-06
  • 打赏
  • 举报
回复
其实就想知道如果创建个窗口的时候 是如何创建 WINDOWS窗口的外框的??
guyuxiangtheone 2011-05-06
  • 打赏
  • 举报
回复
怎么说 毕竟书上的代码有误也是正常的 我只是想请帮忙看看这段代码里有没有问题
c_losed 2011-05-06
  • 打赏
  • 举报
回复
书上的效果不符合

请和书上的代码对比
如确认完全一样
请相信编译器

65,210

社区成员

发帖
与我相关
我的任务
社区描述
C++ 语言相关问题讨论,技术干货分享,前沿动态等
c++ 技术论坛(原bbs)
社区管理员
  • C++ 语言社区
  • encoderlee
  • paschen
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
  1. 请不要发布与C++技术无关的贴子
  2. 请不要发布与技术无关的招聘、广告的帖子
  3. 请尽可能的描述清楚你的问题,如果涉及到代码请尽可能的格式化一下

试试用AI创作助手写篇文章吧