首页
社区
课程
招聘
[求助]程序在失去焦点时占用50%CPU,请帮忙修正,谢谢!
发表于: 2008-8-2 14:09 3917

[求助]程序在失去焦点时占用50%CPU,请帮忙修正,谢谢!

2008-8-2 14:09
3917
.686p
.model flat, stdcall
option casemap:none
;//////////////////////////////////////////////////////////////////////////////////////////////////
include     \masm32\include\windows.inc   
include     \masm32\include\kernel32.inc
include     \masm32\include\user32.inc
include F:\masmplus\INCLUDE\winmm.inc
include F:\masmplus\d3d\include\d3d9_all.inc
include F:\masmplus\d3d\include\d3dx9tex.inc
include F:\masmplus\d3d\include\dinput8.inc

includelib  \masm32\lib\kernel32.lib
includelib  \masm32\lib\user32.lib
INCLUDELIB  F:\masmplus\Lib\winmm.lib
includelib  F:\masmplus\d3d\lib\d3d9.lib
includelib  F:\masmplus\d3d\lib\d3dx9.lib
includelib  F:\masmplus\d3d\lib\dinput8.lib
includelib  F:\masmplus\d3d\lib\dxguid.lib
;//////////////////////////////////////////////////////////////////////////////////////////////////
.CONST
szAppName db "www.hwbnet.net",0
;//////////////////////////////////////////////////////////////////////////////////////////////////
.data
wc WNDCLASSEX <12*4,CS_HREDRAW or CS_VREDRAW,offset WndProc,0,0,0,0,0,BLACK_PEN,0,offset szAppName,0>
d3dpp D3DPRESENT_PARAMETERS <800d,600d,D3DFMT_A8R8G8B8,1,0,0,D3DSWAPEFFECT_DISCARD,?,1,1,D3DFMT_D24S8,0,0,1>
ID_DirectInput GUID IID_IDirectInput8A
ID_Keyboard GUID GUID_SysKeyboard
ID_Mouse GUID GUID_SysMouse
.data?
hwnd HWND ?
hInst dd ?
msg MSG <?>
pd3d dd ?
pd3dDevice dd ?
pDirectInput dd ?
dijp dd ?
disb dd ?
jphcq db 256 dup(?)
;//////////////////////////////////////////////////////////////////////////////////////////////////
.CODE
kaishi:
invoke GetModuleHandle,NULL
mov wc.hInstance,EAX
mov hInst,eax
invoke LoadIcon,NULL,IDI_APPLICATION
mov wc.hIcon,EAX
mov wc.hIconSm,EAX
mov wc.hCursor,0
invoke RegisterClassEx,addr wc
mov ECX,WS_POPUP
invoke CreateWindowEx,WS_EX_APPWINDOW, addr szAppName, addr szAppName,\
               ECX,100,100,800,600,\
               NULL, NULL, wc.hInstance, NULL
mov hwnd,EAX
mov d3dpp.hDeviceWindow,EAX
call peizhidx
invoke ShowWindow, hwnd,SW_SHOWNORMAL
invoke UpdateWindow, hwnd
invoke LoadCursor,NULL,IDC_ARROW
invoke SetCursor,eax
;//////////////////////////////////////////////////////////////////////////////////////////////////
@NewMessage:
invoke PeekMessage,addr msg,NULL,0,0,PM_REMOVE
or EAX,EAX
jz @NoMessage
invoke TranslateMessage,addr msg
invoke DispatchMessage,addr msg
jmp @NewMessage
@NoMessage:
call cj
call jpp
jmp @NewMessage
;//////////////////////////////////////////////////////////////////////////////////////////////////
jieshuyouxi:
mov EAX,msg.wParam
invoke ExitProcess, EAX
;//////////////////////////////////////////////////////////////////////////////////////////////////
WndProc PROC  uses ESI EDI EBX hWnd:HWND, uMsg:UINT, wParam:WPARAM, lParam:LPARAM
invoke DefWindowProc, hWnd, uMsg, wParam, lParam
ret
WndProc ENDP
;//////////////////////////////////////////////////////////////////////////////////////////////////
peizhidx:
invoke Direct3DCreate9, D3D9b_SDK_VERSION
mov pd3d,EAX
d3d9   CreateDevice, pd3d, D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, hwnd , \
               D3DCREATE_HARDWARE_VERTEXPROCESSING, addr d3dpp, addr pd3dDevice
invoke DirectInput8Create,hInst,DIRECTINPUT_VERSION,ADDR ID_DirectInput,ADDR pDirectInput,0
din8 CreateDevice,pDirectInput,addr ID_Keyboard,ADDR dijp,0
din8 CreateDevice,pDirectInput,addr ID_Mouse,ADDR disb,0
dindev8 SetDataFormat,dijp,ADDR c_dfDIKeyboard
dindev8 SetDataFormat,disb,ADDR c_dfDIMouse
dindev8 SetCooperativeLevel,dijp,hwnd,DISCL_FOREGROUND or DISCL_NONEXCLUSIVE
dindev8 SetCooperativeLevel,disb,hwnd,DISCL_FOREGROUND or DISCL_NONEXCLUSIVE
push 10
push DIPH_DEVICE
push 0
push 16
push 20
add esp,16
dindev8 SetProperty,disb,DIPROP_BUFFERSIZE,esp
add esp,4
dindev8 Acquire,dijp
dindev8 Acquire,disb
ret
;//////////////////////////////////////////////////////////////////////////////////////////////////
cj:
d3dev9 Clear,pd3dDevice,0,NULL,D3DCLEAR_TARGET or D3DCLEAR_ZBUFFER,0,3f810000h,0
d3dev9 BeginScene,pd3dDevice
d3dev9 EndScene,pd3dDevice
d3dev9 Present,pd3dDevice,NULL,NULL,NULL,NULL
ret
;//////////////////////////////////////////////////////////////////////////////////////////////////
jpp:
dindev8 Acquire,dijp
dindev8 GetDeviceState,dijp,256,ADDR jphcq
test jphcq+1,80h
jnz jieshuyouxi
ret
;//////////////////////////////////////////////////////////////////////////////////////////////////
END kaishi

DX9头和库文件:http://hwbnet.bbs.pepo.cn/page/bbs/pages/bbstopic/getTopicById.aspx?id=322163

[培训]内核驱动高级班,冲击BAT一流互联网大厂工作,每周日13:00-18:00直播授课

收藏
免费 0
支持
分享
最新回复 (1)
雪    币: 172
活跃值: (10)
能力值: ( LV2,RANK:10 )
在线值:
发帖
回帖
粉丝
2
顶顶顶顶顶顶。
2008-9-6 10:29
0
游客
登录 | 注册 方可回帖
返回
//