------------------------------------------------------------
                        [BUG/PRB.] VFP 9.0 FIX - THE MODERN PRINT DIALOG
                                  August 2024
                 ------------------------------------------------------------
                                     CCB



1. BUG:

     In vfp8 (and vfp6, vfp7), it calls the PrintDlgA Windows API to display the Legacy Print Dialog.

     Please refer to the picture printdialog-vfp8.png:

     In vfp9, it calls the PrintDlgExA Windows API to display the Legacy Print Dialog on early Windows XP,
     Windows Vista, Windows 7, Windows 8 and Windows 8.1, Windows 10 and Windows 11 21H2.

     Please refer to the picture printdialog-vfp9.png:

     In vfp9, it calls the PrintDlgExA Windows API to display the Modern Print Dialog on Windows 11 22H2 or later.

     Please refer to the picture printdialog-win11.png:


2. CAUSE:

     There are some BUGs in the following code.


3. RESOLUTION:

     We can write some code to fix the BUG.

     Fun4925d4 :: ; proc near
             push ebp                                                        ;0x004925d4 :        55
             lea ebp ,  dword ptr [ esp + 0FFFFFD50h ]                       ;0x004925d5 :        8dac2450fdffff
             sub esp , 0368h                                                 ;0x004925dc :        81ec68030000
             mov eax ,  dword ptr [ Data937090 ]                             ;0x004925e2 :        a190709300
             mov  dword ptr [ ebp + 02ACh ] , eax                            ;0x004925e7 :        8985ac020000
             mov  eax , dword ptr [ ebp + 02B8h ]                            ;0x004925ed :        8b85b8020000
             push ebx                                                        ;0x004925f3 :        53
             push esi                                                        ;0x004925f4 :        56
             xor esi , esi                                                   ;0x004925f5 :        33f6
             mov  dword ptr [ ebp + 104 ] , eax                              ;0x004925f7 :        894568
             mov  dword ptr [ ebp + 124 ] , edx                              ;0x004925fa :        89557c
             push edi                                                        ;0x004925fd :        57
             lea edx ,  dword ptr [ ebp + 100 ]                              ;0x004925fe :        8d5564
             lea eax ,  dword ptr [ ebp + 0FFFFFF48h ]                       ;0x00492601 :        8d8548ffffff
             mov  dword ptr [ ebp - 16 ] , ecx                               ;0x00492607 :        894df0
             mov  dword ptr [ ebp + 108 ] , esi                              ;0x0049260a :        89756c
             mov  dword ptr [ ebp + 120 ] , esi                              ;0x0049260d :        897578
             mov  dword ptr [ ebp + 112 ] , 01h                              ;0x00492610 :        c7457001000000
             mov  dword ptr [ ebp - 8 ] , esi                                ;0x00492617 :        8975f8
             mov  dword ptr [ ebp + 080h ] , esi                             ;0x0049261a :        89b580000000
             call Fun42c27f                                                  ;0x00492620 :        e85a9cf9ff
             push esi                                                        ;0x00492625 :        56
             push eax                                                        ;0x00492626 :        50
             call Fun42c2be                                                  ;0x00492627 :        e8929cf9ff
             cmp eax , esi                                                   ;0x0049262c :        3bc6
             pop ecx                                                         ;0x0049262e :        59
             pop ecx                                                         ;0x0049262f :        59
             jne Label49263c                                                 ;0x00492630 :        750a
             xor eax , eax                                                   ;0x00492632 :        33c0
             call Fun492afb                                                  ;0x00492634 :        e8c2040000
             mov  dword ptr [ ebp - 8 ] , eax                                ;0x00492639 :        8945f8

     Label49263c ::
             lea eax ,  dword ptr [ ebp + 100 ]                              ;0x0049263c :        8d4564
             push eax                                                        ;0x0049263f :        50
             lea eax ,  dword ptr [ ebp + 0FFFFFF48h ]                       ;0x00492640 :        8d8548ffffff
             call Fun42d200                                                  ;0x00492646 :        e8b5abf9ff
             mov  eax , dword ptr [ ebp - 8 ]                                ;0x0049264b :        8b45f8
             cmp eax , esi                                                   ;0x0049264e :        3bc6
             je Label5c8324                                                  ;0x00492650 :        0f84ce5c1300
             mov  eax , dword ptr [eax]                                      ;0x00492656 :        8b00
             mov  eax , dword ptr [eax]                                      ;0x00492658 :        8b00

     Label49265a ::
             mov  dword ptr [ ebp + 88 ] , eax                               ;0x0049265a :        894558
             mov al ,  byte ptr [ Data9428dc ]                               ;0x0049265d :        a0dc289400
             xor ebx , ebx                                                   ;0x00492662 :        33db
             mov  byte ptr [ ebp + 119 ] , al                                ;0x00492664 :        884577
             call Fun551e94                                                  ;0x00492667 :        e828f80b00


     ;
     ;                 -------------------------------------------------
     ;                      VFP 9.0 FIX - THE MODERN PRINT DIALOG
     ;                                  August 2024
     ;                 -------------------------------------------------
     ;                                     CCB
     ;
     ; The Modern Print Dialog.
     ;
     ; 2024/8/14, by ccb
     ;

             cmp dword ptr vfpa_sys9163_data,0FFFFFFFFh
             je Label49268c


             mov eax ,  dword ptr [ Data9392c0 ]                             ;0x0049266c :        a1c0929300
             and eax , 0FFFFFF00h                                            ;0x00492671 :        2500ffffff
             cmp eax , 0500h                                                 ;0x00492676 :        3d00050000
             jl Label49268c                                                  ;0x0049267b :        7c0f
             cmp  dword ptr [ ebp + 88 ] , ebx                               ;0x0049267d :        395d58
             je Label49268c                                                  ;0x00492680 :        740a
             mov  dword ptr [ ebp + 080h ] , 01h                             ;0x00492682 :        c7858000000001000000

     Label49268c ::
             mov  eax , dword ptr [ ebp + 104 ]                              ;0x0049268c :        8b4568
             test eax , eax                                                  ;0x0049268f :        85c0
             jne Label5c832f                                                 ;0x00492691 :        0f85985c1300

     Label492697 ::
             mov  eax , dword ptr [ ebp + 124 ]                              ;0x00492697 :        8b457c
             mov  esi , dword ptr [ ebp - 16 ]                               ;0x0049269a :        8b75f0
             mov  dword ptr [ ebp + 92 ] , eax                               ;0x0049269d :        89455c
             and  dword ptr [ ebp + 92 ] , 080h                              ;0x004926a0 :        81655c80000000
             mov  dword ptr [ ebp + 96 ] , eax                               ;0x004926a7 :        894560
             and  dword ptr [ ebp + 96 ] , 010h                              ;0x004926aa :        83656010

     Label4926ae ::
             pushd 015h                                                      ;0x004926ae :        6a15
             pop ecx                                                         ;0x004926b0 :        59
             xor eax , eax                                                   ;0x004926b1 :        33c0
             lea edi ,  dword ptr [ ebp - 104 ]                              ;0x004926b3 :        8d7d98
             rep stosd                                                       ;0x004926b6 :        f3ab
             pushd 015h                                                      ;0x004926b8 :        6a15
             pop ecx                                                         ;0x004926ba :        59
             lea edi ,  dword ptr [ ebp + 4 ]                                ;0x004926bb :        8d7d04
             rep stosd                                                       ;0x004926be :        f3ab
             mov  eax , dword ptr [ ebp + 88 ]                               ;0x004926c0 :        8b4558
             xor edx , edx                                                   ;0x004926c3 :        33d2
             xor edi , edi                                                   ;0x004926c5 :        33ff
             inc edx                                                         ;0x004926c7 :        42
             cmp  dword ptr [ ebp + 92 ] , edi                               ;0x004926c8 :        397d5c
             mov  dword ptr [ ebp + 8 ] , eax                                ;0x004926cb :        894508
             mov  dword ptr [ ebp - 100 ] , eax                              ;0x004926ce :        89459c
             jne Label4926dc                                                 ;0x004926d1 :        7509
             cmp  dword ptr [ esi + 12 ] , edi                               ;0x004926d3 :        397e0c
             jne Label5c833a                                                 ;0x004926d6 :        0f855e5c1300

     Label4926dc ::
             mov  eax , dword ptr [ ebp + 080h ]                             ;0x004926dc :        8b8580000000
             neg eax                                                         ;0x004926e2 :        f7d8
             sbb eax , eax                                                   ;0x004926e4 :        1bc0
             and eax , 012h                                                  ;0x004926e6 :        83e012
             add eax , 042h                                                  ;0x004926e9 :        83c042
             cmp  dword ptr [ ebp + 080h ] , edi                             ;0x004926ec :        39bd80000000
             mov  dword ptr [ ebp + 4 ] , eax                                ;0x004926f2 :        894504
             mov  dword ptr [ ebp + 16 ] , edi                               ;0x004926f5 :        897d10
             mov  dword ptr [ ebp + 12 ] , edi                               ;0x004926f8 :        897d0c
             mov  dword ptr [ ebp + 24 ] , 0400h                             ;0x004926fb :        c7451800040000
             je Label5c8348                                                  ;0x00492702 :        0f84405c1300
             mov  eax , dword ptr [ ebp + 02BCh ]                            ;0x00492708 :        8b85bc020000
             or  dword ptr [ ebp + 80 ] , 0FFFFFFFFh                         ;0x0049270e :        834d50ff
             mov  dword ptr [ ebp - 4 ] , eax                                ;0x00492712 :        8945fc
             mov  eax , dword ptr [ ebp + 02C0h ]                            ;0x00492715 :        8b85c0020000
             mov  dword ptr [ ebp + 0 ] , eax                                ;0x0049271b :        894500
             lea eax ,  dword ptr [ ebp - 4 ]                                ;0x0049271e :        8d45fc
             mov  dword ptr [ ebp + 48 ] , edx                               ;0x00492721 :        895530
             mov  dword ptr [ ebp + 52 ] , 0FFFEh                            ;0x00492724 :        c74534feff0000
             mov  dword ptr [ ebp + 56 ] , edx                               ;0x0049272b :        895538
             mov  dword ptr [ ebp + 36 ] , edx                               ;0x0049272e :        895524
             mov  dword ptr [ ebp + 40 ] , edx                               ;0x00492731 :        895528
             mov  dword ptr [ ebp + 44 ] , eax                               ;0x00492734 :        89452c

     Label492737 ::
             call Fun492b5e                                                  ;0x00492737 :        e822040000
             cmp  dword ptr [ ebp + 080h ] , edi                             ;0x0049273c :        39bd80000000
             lea eax ,  dword ptr [ ebp + 4 ]                                ;0x00492742 :        8d4504
             push eax                                                        ;0x00492745 :        50
             je Label5c8365                                                  ;0x00492746 :        0f84195c1300
             call Fun492597                                                  ;0x0049274c :        e846feffff
             mov ebx , eax                                                   ;0x00492751 :        8bd8

     Label492753 ::
             neg ebx                                                         ;0x00492753 :        f7db
             sbb ebx , ebx                                                   ;0x00492755 :        1bdb
             inc ebx                                                         ;0x00492757 :        43
             call Fun492c0d                                                  ;0x00492758 :        e8b0040000
             test ebx , ebx                                                  ;0x0049275d :        85db
             mov  eax , dword ptr [ ebp + 16 ]                               ;0x0049275f :        8b4510
             mov  dword ptr [ esi + 12 ] , eax                               ;0x00492762 :        89460c
             mov  eax , dword ptr [ ebp + 12 ]                               ;0x00492765 :        8b450c
             mov  dword ptr [ esi + 16 ] , eax                               ;0x00492768 :        894610
             je Label5c8373                                                  ;0x0049276b :        0f84025c1300

     Label492771 ::
             cmp  dword ptr [ ebp + 96 ] , 00h                               ;0x00492771 :        837d6000
             jne Label5c837f                                                 ;0x00492775 :        0f85045c1300

     Label49277b ::
             test  byte ptr [ ebp + 125 ] , 02h                              ;0x0049277b :        f6457d02
             jne Label5c83fd                                                 ;0x0049277f :        0f85785c1300

     Label492785 ::
             mov  eax , dword ptr [ ebp + 124 ]                              ;0x00492785 :        8b457c
             and eax , 01h                                                   ;0x00492788 :        83e001
             mov  dword ptr [ ebp - 20 ] , eax                               ;0x0049278b :        8945ec
             jne Label5c84af                                                 ;0x0049278e :        0f851b5d1300
             test  byte ptr [ ebp + 125 ] , 01h                              ;0x00492794 :        f6457d01
             jne Label5c84af                                                 ;0x00492798 :        0f85115d1300

     Label49279e ::
             movzx ebx ,byte ptr [ ebp + 119 ]                               ;0x0049279e :        0fb65d77
             call Fun551e94                                                  ;0x004927a2 :        e8edf60b00
             cmp  dword ptr [ ebp + 120 ] , 00h                              ;0x004927a7 :        837d7800
             jne Label5c86b6                                                 ;0x004927ab :        0f85055f1300

     Label4927b1 ::
             mov  ecx , dword ptr [ ebp + 02ACh ]                            ;0x004927b1 :        8b8dac020000
             mov  eax , dword ptr [ ebp + 108 ]                              ;0x004927b7 :        8b456c
             call Fun42bf1d                                                  ;0x004927ba :        e85e97f9ff
             pop edi                                                         ;0x004927bf :        5f
             pop esi                                                         ;0x004927c0 :        5e
             pop ebx                                                         ;0x004927c1 :        5b
             add ebp , 02B0h                                                 ;0x004927c2 :        81c5b0020000
             leave                                                           ;0x004927c8 :        c9
             ret 0Ch                                                         ;0x004927c9 :        c20c00


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_vfp9fix335.asp
     http://www.baiyujia.com/vfpdocuments/f_vfp9fix6.asp
     http://www.baiyujia.com/vfpdocuments/f_vfp9fix205.asp

     2, winhelponline.com:
     https://www.winhelponline.com/blog/restore-legacy-print-dialog-windows-11/

     3, foxite.com:
     https://www.foxite.com/archives/windows-11-bug-in-print-dialog-0000498017.htm
     https://www.foxite.com/archives/different-prompts-for-prniter-in-vfp6-9-0000501168.htm
     https://www.foxite.com/archives/pdialog-class-and-copies-in-windows-11-0000497105.htm


6. OTHER:

     For reference only, there is no guarantees.

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