--------------------------------------------------------------------------------
                      [ENHANCED] VFP 9.0 FIX - THE CLOSE BUTTON IN THE PRINT PREVIEW TOOLBAR
                                 January 2024
                 --------------------------------------------------------------------------------
                                     CCB



1. BUG:

     In vfp9 (and vfp6, vfp7, vfp8), it will ALWAYS enable the Close button in the Print Preview toolbar.


2. CAUSE:

     There are some BUGs in the following code.


3. RESOLUTION:

     We can write some code to fix the BUG.

     Fun40fc71 :: ; proc near
             push ebp                                                        ;0x0040fc71 :        55
             lea ebp ,  dword ptr [ esp - 120 ]                              ;0x0040fc72 :        8d6c2488
             sub esp , 0D8h                                                  ;0x0040fc76 :        81ecd8000000
             push esi                                                        ;0x0040fc7c :        56
             push edi                                                        ;0x0040fc7d :        57
             mov edi , ecx                                                   ;0x0040fc7e :        8bf9
             mov esi , edx                                                   ;0x0040fc80 :        8bf2
             mov  dword ptr [ ebp + 116 ] , edi                              ;0x0040fc82 :        897d74
             call Fun4367eb                                                  ;0x0040fc85 :        e8616b0200
             cmp eax , 0FFFFFFFFh                                            ;0x0040fc8a :        83f8ff
             jne Label40fdf9                                                 ;0x0040fc8d :        0f8566010000
             push ebx                                                        ;0x0040fc93 :        53
             pushd 032h                                                      ;0x0040fc94 :        6a32
             pop edi                                                         ;0x0040fc96 :        5f
             push esi                                                        ;0x0040fc97 :        56
             pushd 00h                                                       ;0x0040fc98 :        6a00
             pushd 0600000h                                                  ;0x0040fc9a :        6800006000
             pushd 02Ah                                                      ;0x0040fc9f :        6a2a
             lea edx ,  dword ptr [ ebp + 100 ]                              ;0x0040fca1 :        8d5564
             lea esi ,  dword ptr [ ebp - 96 ]                               ;0x0040fca4 :        8d75a0
             mov  dword ptr [ ebp + 100 ] , edi                              ;0x0040fca7 :        897d64
             mov  dword ptr [ ebp + 108 ] , 041h                             ;0x0040fcaa :        c7456c41000000
             mov  dword ptr [ ebp + 104 ] , 064h                             ;0x0040fcb1 :        c7456864000000
             mov  dword ptr [ ebp + 112 ] , 078h                             ;0x0040fcb8 :        c7457078000000
             call Fun4353bc                                                  ;0x0040fcbf :        e8f8560200
             push  dword ptr [ ebp + 116 ]                                   ;0x0040fcc4 :        ff7574
             mov  dword ptr [ ebp - 8 ] , 0Eh                                ;0x0040fcc7 :        c745f80e000000
             mov  dword ptr [ ebp - 48 ] , offset Label4377f7                          ;0x0040fcce :        c745d0f7774300
             call Fun40fe0a                                                  ;0x0040fcd5 :        e830010000
             and  byte ptr [ ebp - 19 ] , 0FBh                               ;0x0040fcda :        8065edfb
             xor edx , edx                                                   ;0x0040fcde :        33d2
             mov ecx , esi                                                   ;0x0040fce0 :        8bce
             mov  dword ptr [ ebp - 40 ] , eax                               ;0x0040fce2 :        8945d8
             call Fun42ef1e                                                  ;0x0040fce5 :        e834f20100
             mov ebx , eax                                                   ;0x0040fcea :        8bd8
             test ebx , ebx                                                  ;0x0040fcec :        85db
             je Label615e3a                                                  ;0x0040fcee :        0f8446612000


     ;
     ;                  ---------------------------------------------------------------------
     ;                       VFP 9.0 FIX - THE CLOSE BUTTON IN THE PRINT PREVIEW TOOLBAR
     ;                                  August 2021
     ;                  ---------------------------------------------------------------------
     ;                                     CCB
     ;
     ; In vfp9, it will ALWAYS enable the Close button in the Print Preview toolbar.
     ; In VFP Advanced, it can enable or disable the Close button in the Print Preview toolbar.
     ;
     ; 2021/8/8, by ccb
     ;

     Label40fcf4_closebutton_start ::
             cmp dword ptr vfpa_closebutton_iscreatewindow,01h
             jne Label40fcf4_closebutton_end
             ; mov  ecx , dword ptr [eax]
             ; mov  ecx , dword ptr [ecx]
             ; mov dword ptr vfpa_closebutton_hwnd,ecx
             cmp dword ptr vfpa_report_isreportform,00h
             je Label40fcf4_closebutton_end
             cmp  byte ptr [ Data93c280 ] , 05Ah
             jae Label40fcf4_closebutton_end
             ; cmp dword ptr vfpa_closebutton_isshowwindow,01h
             ; jne Label40fcf4_closebutton_end
             cmp dword ptr vfpa_sys9065_data,00h
             jne Label40fcf4_closebutton_end
             mov  ecx , dword ptr [eax]
             and  dword ptr [ecx+50h] , 0FFFFBFFFh
             ; mov dword ptr vfpa_closebutton_hwnd,00h
     Label40fcf4_closebutton_end ::


     Label40fcf4 ::
             mov  edx , dword ptr [ Data9393b4 ]                             ;0x0040fcf4 :        8b15b4939300
             test edx , edx                                                  ;0x0040fcfa :        85d2
             jne Label615e44                                                 ;0x0040fcfc :        0f8542612000
             pushd 0832h                                                     ;0x0040fd02 :        6832080000
             pushd 048h                                                      ;0x0040fd07 :        6a48
             pop eax                                                         ;0x0040fd09 :        58
             call Fun42bf2a                                                  ;0x0040fd0a :        e81bc20100
             test eax , eax                                                  ;0x0040fd0f :        85c0
             mov dword ptr [ Data9393b4 ] ,  eax                             ;0x0040fd11 :        a3b4939300
             je Label40fdee                                                  ;0x0040fd16 :        0f84d2000000
             xor edx , edx                                                   ;0x0040fd1c :        33d2
             inc edx                                                         ;0x0040fd1e :        42
             mov  dword ptr [ Data939270 ] , edx                             ;0x0040fd1f :        891570929300

     Label40fd25 ::
             test ebx , ebx                                                  ;0x0040fd25 :        85db
             je Label40fdd7                                                  ;0x0040fd27 :        0f84aa000000
             test eax , eax                                                  ;0x0040fd2d :        85c0
             je Label40fdd7                                                  ;0x0040fd2f :        0f84a2000000
             mov  eax , dword ptr [eax]                                      ;0x0040fd35 :        8b00
             mov  ecx , dword ptr [ ebp + 116 ]                              ;0x0040fd37 :        8b4d74
             lea esi ,  dword ptr [ edx + 8 * edx - 9 ]                      ;0x0040fd3a :        8d74d2f7
             shl esi , 03h                                                   ;0x0040fd3e :        c1e603
             add eax , esi                                                   ;0x0040fd41 :        03c6
             mov  dword ptr [eax] , ecx                                      ;0x0040fd43 :        8908
             mov ecx , ebx                                                   ;0x0040fd45 :        8bcb
             mov  dword ptr [ eax + 4 ] , ebx                                ;0x0040fd47 :        895804
             call Fun40fe25                                                  ;0x0040fd4a :        e8d6000000
             mov ecx , ebx                                                   ;0x0040fd4f :        8bcb
             mov  dword ptr [ ebp + 108 ] , eax                              ;0x0040fd51 :        89456c
             call Fun40fe96                                                  ;0x0040fd54 :        e83d010000
             mov  dword ptr [ ebp + 112 ] , eax                              ;0x0040fd59 :        894570
             xor edx , edx                                                   ;0x0040fd5c :        33d2
             lea ecx ,  dword ptr [ ebp + 108 ]                              ;0x0040fd5e :        8d4d6c
             mov eax , ebx                                                   ;0x0040fd61 :        8bc3
             call Fun427baa                                                  ;0x0040fd63 :        e8427e0100
             mov  eax , dword ptr [ ebp + 108 ]                              ;0x0040fd68 :        8b456c
             mov  edx , dword ptr [ ebp + 112 ]                              ;0x0040fd6b :        8b5570
             mov ecx , ebx                                                   ;0x0040fd6e :        8bcb
             call Fun43799f                                                  ;0x0040fd70 :        e82a7c0200
             mov eax ,  dword ptr [ Data9393b4 ]                             ;0x0040fd75 :        a1b4939300
             mov  eax , dword ptr [eax]                                      ;0x0040fd7a :        8b00
             add eax , esi                                                   ;0x0040fd7c :        03c6
             mov  dword ptr [ eax + 32 ] , 064h                              ;0x0040fd7e :        c7402064000000
             mov  dword ptr [ eax + 28 ] , edi                               ;0x0040fd85 :        89781c
             mov  ecx , dword ptr [ebx]                                      ;0x0040fd88 :        8b0b
             mov  ecx , dword ptr [ ecx + 0A0h ]                             ;0x0040fd8a :        8b89a0000000
             mov  dword ptr [ eax + 36 ] , ecx                               ;0x0040fd90 :        894824
             mov  ecx , dword ptr [ebx]                                      ;0x0040fd93 :        8b0b
             mov  ecx , dword ptr [ ecx + 0A4h ]                             ;0x0040fd95 :        8b89a4000000
             or  dword ptr [ eax + 60 ] , 0FFFFFFFFh                         ;0x0040fd9b :        83483cff
             or  byte ptr [ eax + 45 ] , 02h                                 ;0x0040fd9f :        80482d02
             or  dword ptr [ eax + 20 ] , 0FFFFFFFFh                         ;0x0040fda3 :        834814ff
             or  dword ptr [ eax + 24 ] , 0FFFFFFFFh                         ;0x0040fda7 :        834818ff
             mov  dword ptr [ eax + 40 ] , ecx                               ;0x0040fdab :        894828
             xor ecx , ecx                                                   ;0x0040fdae :        33c9
             push edi                                                        ;0x0040fdb0 :        57
             mov  dword ptr [ eax + 56 ] , ecx                               ;0x0040fdb1 :        894838
             mov  dword ptr [ eax + 64 ] , ecx                               ;0x0040fdb4 :        894840
             mov  dword ptr [ eax + 68 ] , ecx                               ;0x0040fdb7 :        894844
             call Fun430c00                                                  ;0x0040fdba :        e8410e0200
             mov  ecx , dword ptr [ Data9393b4 ]                             ;0x0040fdbf :        8b0db4939300
             mov  ecx , dword ptr [ecx]                                      ;0x0040fdc5 :        8b09
             mov  dword ptr [ esi + ecx + 16 ] , eax                         ;0x0040fdc7 :        89440e10
             mov edx , 080000000h                                            ;0x0040fdcb :        ba00000080
             mov ecx , ebx                                                   ;0x0040fdd0 :        8bcb
             call Fun430b14                                                  ;0x0040fdd2 :        e83d0d0200

     Label40fdd7 ::
             mov  ecx , dword ptr [ ebp + 116 ]                              ;0x0040fdd7 :        8b4d74
             pushd 00h                                                       ;0x0040fdda :        6a00
             pushd 00h                                                       ;0x0040fddc :        6a00
             call Fun40ff00                                                  ;0x0040fdde :        e81d010000
             xor eax , eax                                                   ;0x0040fde3 :        33c0
             inc eax                                                         ;0x0040fde5 :        40
             pop ebx                                                         ;0x0040fde6 :        5b

     Label40fde7 ::
             pop edi                                                         ;0x0040fde7 :        5f
             pop esi                                                         ;0x0040fde8 :        5e
             add ebp , 078h                                                  ;0x0040fde9 :        83c578
             leave                                                           ;0x0040fdec :        c9
             ret                                                             ;0x0040fded :        c3

     Now In VFP Advanced, it can enable or disable the Close button in the Print Preview toolbar.


4. APPLIES TO:

     VFP 6.0.8167.0
     VFP 6.0.8961.0 (SP5)

     VFP 7.0.0.9262
     VFP 7.0.0.9465 (SP1)

     VFP 8.0.0.2521
     VFP 8.0.0.3117 (SP1)

     VFP 9.0.0.2412
     VFP 9.0.0.3504 (SP1)
     VFP 9.0.0.4611 (SP2)
     VFP 9.0.0.5015 (SP2)
     VFP 9.0.0.5411 (SP2)
     VFP 9.0.0.5721 (SP2)
     VFP 9.0.0.5815 (SP2)
     VFP 9.0.0.6303 (SP2)
     VFP 9.0.0.6602 (SP2)
     VFP 9.0.0.7423 (SP2)

     The bug has been fixed in VFP Advanced.


5. REFERENCE WEBSITES:

     1, baiyujia.com:
     http://www.baiyujia.com
     http://www.baiyujia.com/vfpdocuments/f_vfp9fix186.asp


6. OTHER:

     For reference only, there is no guarantees.

     Any questions or suggestions, please send me an email at ccb2000@163.com.