0

我正在检查 Internet 连接状态,如果没有 Internet 连接,我想发送一个 MessageBox 我所拥有的是:

;build as a WINDOWS app

        .XCREF
        .NOLIST
        INCLUDE    \masm32\include\masm32rt.inc
        INCLUDE    \masm32\include\wininet.inc
        INCLUDELIB \masm32\lib\wininet.lib
        .LIST

;-------------------------------------------------------------------------

IsOnline PROTO   :LPSTR
Sleep PROTO STDCALL :DWORD

;-------------------------------------------------------------------------

IFNDEF FLAG_ICC_FORCE_CONNECTION
FLAG_ICC_FORCE_CONNECTION EQU 1
ENDIF

;-------------------------------------------------------------------------


        .CODE

IsOnline PROC    lpszURL:LPSTR

;Test Internet Connection
;
;lpszURL points to a zero-terminated test URL string (must start with "http://")
;
;Returns EAX = FALSE if not connected
;            = TRUE if connected
;        EDX = connection description (see InternetGetConnectedState documentation)

        push    eax
        mov     edx,esp

        INVOKE  InternetGetConnectedState,edx,0

        or      eax,eax
        jz      IsOnl0

        INVOKE  InternetCheckConnection,lpszURL,FLAG_ICC_FORCE_CONNECTION,0

IsOnl0: pop     edx
        ret

IsOnline ENDP

;-------------------------------------------------------------------------

szURL   db 'http://www.google.com',0

;-------------------------------------------------------------------------

_main   PROC

loop00: Invoke Sleep,5000 ;Sleep so it doesn't use 99% CPU
        INVOKE  IsOnline,offset szURL    
        or      eax,eax
        jz      loop00

        INVOKE  Beep,750,1000
        exit

_main   ENDP

;-------------------------------------------------------------------------

        END     _main

现在我想添加这样的东西

 .data
    MyTitle db "No internet",0
    MyText db "No active internet connection found, retrying in 5 seconds.",0

            push 0
            push offset MyTitle
            push offset MyText
            push 0
            call MessageBoxA

但我真的不知道我必须把它放在哪里

4

1 回答 1

1

这个怎么样:

_main   PROC

loop00: 
        INVOKE  IsOnline,offset szURL    
        or      eax,eax
        jnz      done

        push 0
        push offset MyTitle
        push offset MyText
        push 0
        call MessageBoxA

        Invoke Sleep,5000 ;Sleep so it doesn't use 99% CPU

        jmp loop00

done:
        INVOKE  Beep,750,1000
        exit

_main   ENDP

.data
    MyTitle db "No internet",0
    MyText db "No active internet connection found, retrying in 5 seconds.",0

这将首先等待 IsOnline 测试,如果失败,将等待 5 秒再试一次。否则它会在退出前发出哔哔声。

于 2013-02-25T23:09:20.040 回答