Winapi 调用SetWindowPos会产生“错误”;无效的窗口句柄“;
我手头有太多的时间,决定用MASM32编写一个简单的程序。但是,我无法使对WinApi的SetWindowPos调用正常工作。以下是相关的代码位:Winapi 调用SetWindowPos会产生“错误”;无效的窗口句柄“;,winapi,assembly,x86,masm,masm32,Winapi,Assembly,X86,Masm,Masm32,我手头有太多的时间,决定用MASM32编写一个简单的程序。但是,我无法使对WinApi的SetWindowPos调用正常工作。以下是相关的代码位: invoke GetForegroundWindow mov ecx,eax invoke GetWindowLong, ecx, GWL_EXSTYLE AND eax,WS_EX_TOPMOST ; check if window- .if eax==0 ; is already on top mov edx
invoke GetForegroundWindow
mov ecx,eax
invoke GetWindowLong, ecx, GWL_EXSTYLE
AND eax,WS_EX_TOPMOST ; check if window-
.if eax==0 ; is already on top
mov edx,HWND_TOPMOST; nope, make it on top
.else
mov edx,HWND_NOTOPMOST; yes, make it not on top
.endif
push ecx ; window handle
push edx ; placement handle
push edi ; edi=0, someone told me this is faster
push edi
push edi
push edi
push 0043h ; SWP_SHOWWINDOW | SWP_NOSIZE | SWP_NOMOVE
call SetWindowPos
cmp eax,0
jne mLoop1 ; jump to message loop
invoke HandleError, addr appname ; make message box with error message
; ^^^^^^^^ this shows "Invalid Window Handle"
jmp mLoop1 ; jump to message loop
我确信我遗漏了一些非常明显的东西,但由于我对汇编的知识有限,我不知道会发生什么。将参数按相反顺序进行堆栈。因此,从代码窗口中,句柄是
0043h
当然无效,即使在我切换订单时,也会出现相同的错误。我不知道我是在倒车,所以谢谢你!可能GetWindowLong
会覆盖ecx
中的值(不确定invoke指令是否在masm中保留寄存器)。尝试使用一些非易失性寄存器(如ebx
或esi
等或内存变量)在调用之间保留窗口句柄。我以前尝试过使用memore变量,但我猜由于顺序错误而失败了。非常感谢!尝试一些调试。检查您在堆栈上实际放置的内容。