News:

MASM32 SDK Description, downloads and other helpful links
MASM32.com New Forum Link
masmforum WebSite

Recognize a display of video games

Started by Faiseur, August 14, 2010, 10:51:02 PM

Previous topic - Next topic

Faiseur

Hello,

for an application i need to recognize if the user plays a video game or not. I think the solution is to recognize when a video mode (d3d, etc.) is launched but I do not know much about this subject. If anyone has a good solution to offer i thank him.

French asm Forum: http://www.asmforum.net/   Website: http://www.faiseur.net/

Twister

You could use this to check for a window that is in full-screen:
IsInFullScreen proc
    LOCAL tWnd:RECT
    LOCAL _x:DWORD
    LOCAL _y:DWORD
   
    invoke GetForegroundWindow
    invoke GetWindowRect, eax, addr tWnd
   
    mov _x, tWnd.bottom
    mov _y, tWnd.right
   
    invoke GetSystemMetrics, SM_CXSCREEN
    mov edx, _x
    cmp edx, eax
    jne @not_full
   
    invoke GetSystemMetrics, SM_CYSCREEN
    mov edx, _y
    cmp edx, eax
    jne @not_full

    mov eax, TRUE
    ret

@not_full:
    mov eax, FALSE
    ret
IsInFullScreen endp


It may or may not work. I whipped this code up on the spot. :P



In Windows XP and up, I don't think there are video modes. I think that was just in the DOS days.

jj2007

Your code works with small modifications:
IsInFullScreen proc
LOCAL rc:RECT

invoke GetForegroundWindow
lea edx, rc
invoke GetWindowRect, eax, edx

invoke GetSystemMetrics, SM_CXSCREEN
cmp eax, rc.right
jne @not_full

invoke GetSystemMetrics, SM_CYSCREEN
cmp eax, rc.bottom
jne @not_full

mov eax, TRUE
ret

@not_full:
mov eax, FALSE
ret
IsInFullScreen endp

Faiseur

Quote from: GTX on August 15, 2010, 01:17:19 AM



In Windows XP and up, I don't think there are video modes. I think that was just in the DOS days.

Thank you GTX, I thought the same idea. Unfortunately it can happen that other utilities use a full screen mode. This is the case, for example, with Firefox using the F11 key. In this case, your example assumes that the full screen. Therefore it would be better to recognize when the full screen mode uses opengl or d3d.
French asm Forum: http://www.asmforum.net/   Website: http://www.faiseur.net/

jj2007

Can't you check for the window title? At least you can exclude Firefox that way.

Faiseur

Yes but this is not enough. It must also exclude the desktop window :) This is not very clean.
French asm Forum: http://www.asmforum.net/   Website: http://www.faiseur.net/

jj2007

Quote from: Faiseur on August 15, 2010, 10:21:55 AM
Yes but this is not enough. It must also exclude the desktop window :) This is not very clean.

GetDesktopWindow can deal with that. But explain what exactly you want to achieve...

Faiseur

QuoteGetDesktopWindow can deal with that. But explain what exactly you want to achieve...

I am trying to implement a function that I explained...

My application is here:

http://www.faiseur.net/2010/08/horizon-toolbar-100b.html

His window is displayed in certain circumstances (when the user moves his mouse to the far right of the screen) and I want to block its view if the user uses a video mode (this can disturb the user). I can not explain it better, I do not speak English well. To understand in more detail you should try the program (in French).
French asm Forum: http://www.asmforum.net/   Website: http://www.faiseur.net/

Twister

I'm not sure what you can do then. When applications go full screen they use the entire monitor, and they are the active, foreground window. That is what the procedure looks for. You can add in more code so it doesn't detect the desktop.

IsInFullScreen uses edx proc
    LOCAL tWnd:RECT
   
    invoke GetForegroundWindow
    push eax
    lea edx, tWnd
    invoke GetWindowRect, eax, edx
    pop eax
    mov edx, eax
    call GetDesktopWindow
    cmp eax, edx
    je @not_full
       
    invoke GetSystemMetrics, SM_CXSCREEN
    cmp edx, tWnd.bottom
    jne @not_full
   
    invoke GetSystemMetrics, SM_CYSCREEN
    cmp edx, tWnd.right
    jne @not_full

    mov eax, TRUE
    ret

@not_full:
    mov eax, FALSE
    ret
IsInFullScreen endp


I'm not sure how it can be done any other way.

Faiseur

Yes. This solution is correct GTX. What I can do is to exclude Desktop and Firefox, but... there may be other applications to exclude that I do not know (we do not know what other users use of applications).

This is why I seek a better solution that would check if the window focus is opengl or d3d type. Is this type of applications (video games) i'm trying to detect. Sorry for my bad english.
French asm Forum: http://www.asmforum.net/   Website: http://www.faiseur.net/

jj2007

Quote from: GTX on August 15, 2010, 02:17:42 PM
    mov edx, eax
    call GetDesktopWindow
    cmp eax, edx

While it is true that under Win XP the call GetDesktopWindow does not trash edx, it is an undocumented behaviour.
Just for fun: This snippet shows the "handle" returned by GetDesktopWindow ::)

include \masm32\include\masm32rt.inc
include \masm32\macros\ucmacros.asm
.code
start:
call GetDesktopWindow
invoke MessageBoxW, 0, eax, uni$("The so-called handle:"), MB_OK
exit
end start

Twister

Oh I see it in the disassembly. :lol

This is user32.dll in Windows 7.
sub_77D25A07 proc near
mov     eax, 11C7h
mov     edx, 7FFE0300h
call    dword ptr [edx]
retn    4
sub_77D25A07 endp

Neo

A video game window probably also uses the WS_EX_TOPMOST extended style to make sure it's on top and possibly the WS_POPUP style to make sure that there's no border.  You could check for those using GetWindowInfo.  :U

jj2007

By the way: I can't see GetDesktopWindow being foreground window. See the "handle" snippet above - it just doesn't look like a real window's handle. Progman as foreground window works fine, so the test has to be for the window title, which is "Program Manager" also for my Italian XP version.

Faiseur

This version is ok:

IsInFullScreen proc uses ebx
LOCAL rc:RECT
LOCAL szWinBuf[261]:BYTE

invoke GetForegroundWindow
mov ebx,eax
lea edx, rc
invoke GetWindowRect, eax, edx

invoke GetSystemMetrics, SM_CXSCREEN
cmp eax, rc.right
jne @not_full

invoke GetSystemMetrics, SM_CYSCREEN
cmp eax, rc.bottom
jne @not_full


invoke RealGetWindowClass,ebx,addr szWinBuf,261 ;  exception: Mozilla F11
fn lstrcmpi,addr szWinBuf,"MozillaUIWindowClass"
cmp eax,0
je @not_full
fn lstrcmpi,addr szWinBuf,"Shell_TrayWnd" ; exception: clic taskbar
cmp eax,0
je @not_full
fn lstrcmpi,addr szWinBuf,"IEFrame";  exception: IE F11
cmp eax,0
je @not_full
fn lstrcmpi,addr szWinBuf,"Progman" ;  exception: clic desktop icons
cmp eax,0
je @not_full

mov eax,TRUE
ret

@not_full:
xor eax,eax ; FALSE
ret
IsInFullScreen endp


It is necessary to exclude several applications (progman, explorer and browsers can use the full screen mode). There may be other exceptions.


French asm Forum: http://www.asmforum.net/   Website: http://www.faiseur.net/