1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301
| Option Explicit
'------------------------------------------------------------------------------------------------
' Vous trouverez dans ce modules 2 fonctions principales:
'
' - MsgBoxEx : Affiche une fenêtre de message comme MsgBox mais qui lit le format RTF (qui
' permet d'afficher un texte formaté et des liens hypertextes) obtenu, par exemple, en enregistrant
' un texte Word ou WordPad au format RTF (tout simplement). Il est possible d'inclure un compte à rebours
' qui valide automatiquement l'un des boutons de la fenêtre quand le temps est écoulé, et de
' copier/coller le texte de la fenêtre.
'
' - MsgBoxRTF : permet de simplifier l'usage de MsgBoxEx en partant du principe que le texte
' de la fenêtre est soit dans un fichier RTF, soit passé en dur.
' Suivant votre volonté, il est possible d'inclure dans ce fichier des informations pour modifier,
' en plus du texte, l'icône, la largeur de la fenêtre, son titre, le libellé des boutons,
' la durée du compte à rebours.
'------------------------------------------------------------------------------------------------
'***************************************************************************************
'* MESSAGE BOX ETENDUE V0.4 *
'* ---------------------------------------------------------------------------- *
'***************************************************************************************
' Auteur : Thierry GASPERMENT (Arkham46)
' Le code est libre pour toute utilisation
' Le code est indenté avec Smart Indenter (http://www.oaltd.co.uk)
'***************************************************************************************
' v0.2 (12/06/07) :
' --> Correction sur positionnement des boutons si pas de timer
' v0.3 (06/11/08) :
' --> Ajout de marges de 10px par défaut
' v0.4 (13/05/16) :
' --> Compatibilité Office 64 bits
' v0.5 (14/05/18) :
' --> Correction d'affichage (rectangle gris) sur windows récents (> XP)
'***************************************************************************************
'* LIENS *
'***************************************************************************************
'** Info sur les contrôles
'http://msdn.microsoft.com/library/default.asp?url=/library/en-us/shellcc/platform/commctls/indivcontrol.asp
'** Mon Site DVP
'http://arkham46.developpez.com/
'***************************************************************************************
'* API *
'***************************************************************************************
#If VBA7 Then
DefLngPtr A-Z
#Else
DefLng A-Z
#End If
' Pour remplacement de AddressOf pour version 97
#If VBA6 Then
#Else
Private Declare Function GetCurrentVbaProject _
Lib "vba332.dll" Alias "EbGetExecutingProj" _
(hProject As Long) As Long
Private Declare Function GetFuncID _
Lib "vba332.dll" Alias "TipGetFunctionId" _
(ByVal hProject As Long, ByVal strFunctionName As String, _
ByRef strFunctionId As String) As Long
Private Declare Function GetAddr _
Lib "vba332.dll" Alias "TipGetLpfnOfFunctionId" _
(ByVal hProject As Long, ByVal strFunctionId As String, _
ByRef lpfn As Long) As Long
#End If
#If VBA7 Then
Private Declare PtrSafe Function FillRect Lib "user32" (ByVal hdc As LongPtr, lpRect As RECT, ByVal hBrush As LongPtr) As Long
Private Declare PtrSafe Function BeginPaint Lib "user32" (ByVal hwnd As LongPtr, lpPaint As PAINTSTRUCT) As LongPtr
Private Declare PtrSafe Function EndPaint Lib "user32" (ByVal hwnd As LongPtr, lpPaint As PAINTSTRUCT) As Long
Private Declare PtrSafe Function GetUpdateRect Lib "user32" (ByVal hwnd As LongPtr, lpRect As RECT, ByVal bErase As Long) As Long
' API pour menu
Private Declare PtrSafe Function CreatePopupMenu Lib "user32" () As LongPtr
Private Declare PtrSafe Function TrackPopupMenuEx Lib "user32" (ByVal hMenu As LongPtr, ByVal un As Long, ByVal n1 As Long, ByVal n2 As Long, ByVal hwnd As LongPtr, ByVal lpTPMParams As Any) As Long
Private Declare PtrSafe Function AppendMenu Lib "user32" Alias "AppendMenuA" (ByVal hMenu As LongPtr, ByVal wFlags As Long, ByVal wIDNewItem As LongPtr, ByVal lpNewItem As Any) As Long
Private Declare PtrSafe Function DestroyMenu Lib "user32" (ByVal hMenu As LongPtr) As Long
Private Declare PtrSafe Function GetCursorPos Lib "user32" (lpPoint As PointAPI) As Long
Private Declare PtrSafe Function ShellExecute Lib "shell32.dll" Alias "ShellExecuteA" (ByVal hwnd As LongPtr, ByVal lpOperation As String, ByVal lpFile As String, ByVal lpParameters As String, _
ByVal lpDirectory As String, ByVal nShowCmd As Long) As LongPtr
Private Declare PtrSafe Function GetFileSize Lib "kernel32" (ByVal hFile As LongPtr, lpFileSizeHigh As Long) As Long
Private Declare PtrSafe Function CreateFile Lib "kernel32" Alias "CreateFileA" (ByVal lpFileName As String, ByVal dwDesiredAccess As Long, ByVal dwShareMode As Long, _
ByVal lpSecurityAttributes As Any, ByVal dwCreationDisposition As Long, ByVal dwFlagsAndAttributes As Long, _
ByVal hTemplateFile As LongPtr) As LongPtr
Private Declare PtrSafe Function ReadFile Lib "kernel32" (ByVal hFile As LongPtr, lpBuffer As Any, ByVal nNumberOfBytesToRead As Long, lpNumberOfBytesRead As Long, ByVal lpOverlapped As Any) As Long
Private Declare PtrSafe Function CloseHandle Lib "kernel32" (ByVal hObject As LongPtr) As Long
Private Declare PtrSafe Function LoadLibrary Lib "kernel32" Alias "LoadLibraryA" (ByVal lpLibFileName As String) As LongPtr
Private Declare PtrSafe Function APISetTimer Lib "user32.dll" Alias "SetTimer" (ByVal hwnd As LongPtr, ByVal nIDEvent As LongPtr, ByVal uElapse As Long, ByVal lpTimerFunc As LongPtr) As LongPtr
Private Declare PtrSafe Function APIKillTimer Lib "user32" Alias "KillTimer" (ByVal hwnd As LongPtr, ByVal nIDEvent As LongPtr) As Long
Private Declare PtrSafe Sub RtlMoveMemory Lib "kernel32" (Destination As Any, Source As Any, ByVal length As LongPtr)
Private Declare PtrSafe Function OleTranslateColor Lib "oleaut32.dll" (ByVal OLE_COLOR As Long, ByVal hPalette As LongPtr, pccolorref As Long) As Long
Private Declare PtrSafe Function GetFocus Lib "user32" () As LongPtr
Private Declare PtrSafe Function GetDeviceCaps Lib "Gdi32" (ByVal hdc As LongPtr, ByVal nIndex As Long) As Long
Private Declare PtrSafe Function GetSystemMetrics Lib "user32" (ByVal nIndex As Long) As Long
Private Declare PtrSafe Function CreateWindowEx Lib "user32" Alias "CreateWindowExA" (ByVal dwExStyle As Long, ByVal lpClassName As String, ByVal lpWindowName As String, ByVal dwStyle As Long, _
ByVal x As Long, ByVal Y As Long, ByVal nWidth As Long, ByVal nHeight As Long, ByVal hwndParent As LongPtr, _
ByVal hMenu As LongPtr, ByVal hInstance As LongPtr, lpParam As Any) As LongPtr
Private Declare PtrSafe Function CreateBrushIndirect Lib "Gdi32" (lpLogBrush As LOGBRUSH) As LongPtr
Private Declare PtrSafe Function GetClientRect Lib "user32" (ByVal hwnd As LongPtr, lpRect As RECT) As Long
Private Declare PtrSafe Function ShowWindow Lib "user32" (ByVal hwnd As LongPtr, ByVal nCmdShow As Long) As Long
Private Declare PtrSafe Function DestroyWindow Lib "user32" (ByVal hwnd As LongPtr) As Long
Private Declare PtrSafe Function GetCurrentThreadId Lib "kernel32" () As Long
#If Win64 Then
Private Declare PtrSafe Function GetWindowLong Lib "user32" Alias "GetWindowLongPtrA" (ByVal hwnd As LongPtr, ByVal nIndex As Long) As LongPtr
Private Declare PtrSafe Function SetWindowLong Lib "user32" Alias "SetWindowLongPtrA" (ByVal hwnd As LongPtr, ByVal nIndex As Long, ByVal dwNewLong As LongPtr) As LongPtr
#Else
Private Declare PtrSafe Function GetWindowLong Lib "user32" Alias "GetWindowLongA" (ByVal hwnd As LongPtr, ByVal nIndex As Long) As LongPtr
Private Declare PtrSafe Function SetWindowLong Lib "user32" Alias "SetWindowLongA" (ByVal hwnd As LongPtr, ByVal nIndex As Long, ByVal dwNewLong As LongPtr) As LongPtr
#End If
Private Declare PtrSafe Function GetForegroundWindow Lib "user32" () As LongPtr
Private Declare PtrSafe Function SetWindowsHookEx Lib "user32" Alias "SetWindowsHookExA" (ByVal idHook As Long, ByVal lpfn As LongPtr, ByVal hmod As LongPtr, ByVal dwThreadId As Long) As LongPtr
Private Declare PtrSafe Function CallNextHookEx Lib "user32" (ByVal hHook As LongPtr, ByVal nCode As Long, ByVal wParam As LongPtr, lParam As Any) As LongPtr
Private Declare PtrSafe Function UnhookWindowsHookEx Lib "user32" (ByVal hHook As LongPtr) As Long
Private Declare PtrSafe Function CallWindowProc Lib "user32" Alias "CallWindowProcA" (ByVal lpPrevWndFunc As LongPtr, ByVal hwnd As LongPtr, ByVal Msg As Long, _
ByVal wParam As LongPtr, ByVal lParam As LongPtr) As LongPtr
Private Declare PtrSafe Function GetClassName Lib "user32" Alias "GetClassNameA" (ByVal hwnd As LongPtr, ByVal lpClassName As String, ByVal nMaxCount As Long) As Long
Private Declare PtrSafe Function SetBkColor Lib "Gdi32" (ByVal hdc As LongPtr, ByVal crColor As Long) As Long
Private Declare PtrSafe Function SetWindowPos Lib "user32" (ByVal hwnd As LongPtr, ByVal hWndInsertAfter As LongPtr, ByVal x As Long, ByVal Y As Long, _
ByVal cx As Long, ByVal cy As Long, ByVal wFlags As Long) As Long
Private Declare PtrSafe Function GetWindowRect Lib "user32" (ByVal hwnd As LongPtr, lpRect As RECT) As Long
Private Declare PtrSafe Function GetSysColor Lib "user32" (ByVal nIndex As Long) As Long
Private Declare PtrSafe Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hwnd As LongPtr, ByVal wMsg As Long, ByVal wParam As LongPtr, lParam As Any) As LongPtr
Private Declare PtrSafe Function GetWindowPlacement Lib "user32" (ByVal hwnd As LongPtr, lpwndpl As WINDOWPLACEMENT) As Long
Private Declare PtrSafe Function SetWindowPlacement Lib "user32" (ByVal hwnd As LongPtr, lpwndpl As WINDOWPLACEMENT) As Long
Private Declare PtrSafe Function GetDlgItem Lib "user32" (ByVal hDlg As LongPtr, ByVal nIDDlgItem As Long) As LongPtr
Private Declare PtrSafe Function SetWindowText Lib "user32" Alias "SetWindowTextA" (ByVal hwnd As LongPtr, ByVal lpString As String) As Long
Private Declare PtrSafe Function GetDC Lib "user32" (ByVal hwnd As LongPtr) As LongPtr
Private Declare PtrSafe Function ReleaseDC Lib "user32" (ByVal hwnd As LongPtr, ByVal hdc As LongPtr) As Long
Private Declare PtrSafe Function DrawTextEx Lib "user32" Alias "DrawTextExA" (ByVal hdc As LongPtr, ByVal lpsz As String, ByVal n As Long, _
lpRect As RECT, ByVal un As Long, lpDrawTextParams As Any) As Long
#Else
Private Declare Function FillRect Lib "user32" (ByVal hdc As Long, lpRect As RECT, ByVal hBrush As Long) As Long
Private Declare Function BeginPaint Lib "user32" (ByVal hwnd As Long, lpPaint As PAINTSTRUCT) As Long
Private Declare Function EndPaint Lib "user32" (ByVal hwnd As Long, lpPaint As PAINTSTRUCT) As Long
Private Declare Function GetUpdateRect Lib "user32" (ByVal hwnd As Long, lpRect As RECT, ByVal bErase As Long) As Long
' API pour menu
Private Declare Function CreatePopupMenu Lib "user32" () As Long
Private Declare Function TrackPopupMenuEx Lib "user32" _
(ByVal hMenu As Long, ByVal wFlags As Long, ByVal x As Long, _
ByVal Y As Long, ByVal hwnd As Long, ByVal lptpm As Any) As Long
Private Declare Function AppendMenu Lib "user32" Alias _
"AppendMenuA" (ByVal hMenu As Long, ByVal wFlags As Long, _
ByVal wIDNewItem As Long, ByVal lpNewItem As Any) As Long
Private Declare Function DestroyMenu Lib "user32" _
(ByVal hMenu As Long) As Long
Private Declare Function GetCursorPos Lib "user32" _
(lpPoint As PointAPI) As Long
Private Declare Function ShellExecute Lib "shell32.dll" Alias "ShellExecuteA" _
(ByVal hwnd As Long, ByVal lpszOp As String, _
ByVal lpszFile As String, ByVal lpszParams As String, _
ByVal LpszDir As String, ByVal FsShowCmd As Long) _
As Long
Private Declare Function GetFileSize Lib "kernel32" (ByVal hFile As Long, lpFileSizeHigh As Long) As Long
Private Declare Function CreateFile Lib "kernel32" Alias "CreateFileA" (ByVal lpFileName As String, ByVal dwDesiredAccess As Long, _
ByVal dwShareMode As Long, ByVal lpSecurityAttributes As Any, _
ByVal dwCreationDisposition As Long, ByVal dwFlagsAndAttributes As Long, _
ByVal hTemplateFile As Long) As Long
Private Declare Function ReadFile Lib "kernel32" (ByVal hFile As Long, lpBuffer As Any, ByVal nNumberOfBytesToRead As Long, lpNumberOfBytesRead As Long, _
ByVal lpOverlapped As Any) As Long
Private Declare Function CloseHandle Lib "kernel32" (ByVal hObject As Long) As Long
Private Declare Function LoadLibrary Lib "kernel32" Alias "LoadLibraryA" (ByVal lpLibFileName As String) As Long
Private Declare Function APISetTimer Lib "user32.dll" Alias "SetTimer" (ByVal hwnd As Long, ByVal nIDEvent As Long, ByVal uElapse As Long, ByVal lpTimerProc As Long) As Long
Private Declare Function APIKillTimer Lib "user32.dll" Alias "KillTimer" (ByVal hwnd As Long, ByVal uIDEvent As Long) As Long
Private Declare Sub RtlMoveMemory Lib "kernel32" (Destination As Any, Source As Any, ByVal length As Long)
Private Declare Function OleTranslateColor Lib "olepro32.dll" _
(ByVal OLE_COLOR As Long, _
ByVal hPalette As Long, _
pccolorref As Long) As Long
Private Declare Function GetFocus Lib "user32" () As Long
Private Declare Function GetDeviceCaps Lib "Gdi32" (ByVal hdc As Long, ByVal nIndex As Long) As Long
Private Declare Function GetSystemMetrics Lib "user32" (ByVal nIndex As Long) As Long
Private Declare Function CreateWindowEx Lib "user32" Alias _
"CreateWindowExA" (ByVal dwExStyle As Long, ByVal lpClassName As String _
, ByVal lpWindowName As String, ByVal dwStyle As Long, ByVal x As Long _
, ByVal Y As Long, ByVal nWidth As Long, ByVal nHeight As Long _
, ByVal hwndParent As Long, ByVal hMenu As Long, ByVal hInstance As Long _
, lpParam As Any) As Long
Private Declare Function CreateBrushIndirect Lib "Gdi32" (lpLogBrush As LOGBRUSH) As Long
Private Declare Function GetClientRect Lib "user32" (ByVal hwnd As Long, lpRect As RECT) As Long
Private Declare Function ShowWindow Lib "user32" (ByVal hwnd As Long, ByVal nCmdShow As Long) As Long
Private Declare Function DestroyWindow Lib "user32" (ByVal hwnd As Long) As Long
Private Declare Function GetCurrentThreadId Lib "kernel32" () As Long
Private Declare Function GetWindowLong Lib "user32" Alias "GetWindowLongA" (ByVal hwnd As Long, ByVal nIndex As Long) As Long
Private Declare Function GetForegroundWindow Lib "user32" () As Long
Private Declare Function SetWindowsHookEx Lib "user32" Alias "SetWindowsHookExA" (ByVal idHook As Long, ByVal lpfn As Long, ByVal hmod As Long, ByVal dwThreadId As Long) As Long
Private Declare Function CallNextHookEx Lib "user32" (ByVal hHook As Long, ByVal nCode As Long, ByVal wParam As Long, lParam As Any) As Long
Private Declare Function UnhookWindowsHookEx Lib "user32" (ByVal hHook As Long) As Long
Private Declare Function SetWindowLong Lib "user32" Alias "SetWindowLongA" (ByVal hwnd As Long, ByVal nIndex As Long, ByVal dwNewLong As Long) As Long
Private Declare Function CallWindowProc Lib "user32" Alias "CallWindowProcA" (ByVal lpPrevWndFunc As Long, ByVal hwnd As Long, ByVal Msg As Long, _
ByVal wParam As Long, ByVal lParam As Long) As Long
Private Declare Function GetClassName Lib "user32" Alias "GetClassNameA" (ByVal hwnd As Long, ByVal lpClassName As String, ByVal nMaxCount As Long) As Long
Private Declare Function SetBkColor Lib "Gdi32" (ByVal hdc As Long, ByVal crColor As Long) As Long
Private Declare Function SetWindowPos Lib "user32" (ByVal hwnd As Long, ByVal hWndInsertAfter As Long, ByVal x As Long, ByVal Y As Long, _
ByVal cx As Long, ByVal cy As Long, ByVal wFlags As Long) As Long
Private Declare Function GetWindowRect Lib "user32" (ByVal hwnd As Long, lpRect As RECT) As Long
Private Declare Function GetSysColor Lib "user32" (ByVal nIndex As Long) As Long
Private Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As Any) As Long
Private Declare Function GetWindowPlacement Lib "user32" (ByVal hwnd As Long, lpwndpl As WINDOWPLACEMENT) As Long
Private Declare Function SetWindowPlacement Lib "user32" (ByVal hwnd As Long, lpwndpl As WINDOWPLACEMENT) As Long
Private Declare Function GetDlgItem Lib "user32" _
(ByVal hDlg As Long, _
ByVal nIDDlgItem As Long) As Long
Private Declare Function SetWindowText Lib "user32" Alias "SetWindowTextA" (ByVal hwnd As Long, ByVal lpString As String) As Long
Private Declare Function GetDC Lib "user32" (ByVal hwnd As Long) As Long
Private Declare Function ReleaseDC Lib "user32" (ByVal hwnd As Long, ByVal hdc As Long) As Long
Private Declare Function DrawTextEx Lib "user32" Alias "DrawTextExA" _
(ByVal hdc As Long, ByVal lpsz As String, ByVal n As Long, _
lpRect As RECT, ByVal un As Long, lpDrawTextParams As Any) As Long
#End If
'***************************************************************************************
'* Types *
'***************************************************************************************
Private Type LOGBRUSH
lbStyle As Long
lbColor As Long
lbHatch As Long
End Type
' Type Point pour API
Private Type PointAPI
x As Long
Y As Long
End Type
Private Type RECT
Left As Long
Top As Long
Right As Long
Bottom As Long
End Type
Private Type PAINTSTRUCT
#If VBA7 Then
hdc As LongPtr
#Else
hdc As Long
#End If
fErase As Long
rcPaint As RECT
fRestore As Long
fIncUpdate As Long
rgbReserved(0 To 31) As Byte
End Type
' Placement d'une fenêtre
Private Type WINDOWPLACEMENT
length As Long
flags As Long
showCmd As Long
ptMinPosition As PointAPI
ptMaxPosition As PointAPI
rcNormalPosition As RECT
End Type
Private Type CWPSTRUCT
#If VBA7 Then
lParam As LongPtr
wParam As LongPtr
Message As Long
hwnd As LongPtr
#Else
lParam As Long
wParam As Long
Message As Long
hwnd As Long
#End If
End Type
Private Type CHARRANGE
cpMin As Long
cpMax As Long
End Type
Private Type FormatRange
#If VBA7 Then
hdc As LongPtr
hdcTarget As LongPtr
#Else
hdc As Long
hdcTarget As Long
#End If
rc As RECT
rcPage As RECT
chrg As CHARRANGE
End Type
'// notification structures
Private Type NMHDR
#If VBA7 Then
hwndFrom As LongPtr ' Window handle of control sending message
idFrom As LongPtr ' Identifier of control sending message
#Else
hwndFrom As Long
idFrom As Long
#End If
code As Long ' Specifies the notification code
End Type
Private Type ENLINK
NMHDR As NMHDR
Msg As Long
#If VBA7 Then
wParam As LongPtr
lParam As Long
#Else
wParam As Long
lParam As Long
#End If
chrg As CHARRANGE
End Type
'***************************************************************************************
'* Constantes *
'***************************************************************************************
Private Const gMarginLeft As Long = 10
Private Const gMarginRight As Long = 10
Private Const gMarginBottom As Long = 10
Private Const gMarginTop As Long = 10
Private Const WM_USER = &H400
Private Const FILE_SHARE_READ = &H1
Private Const OPEN_EXISTING = 3
Private Const GENERIC_READ = &H80000000
Private Const LOGPIXELSY = 90
Private Const LOGPIXELSX = 88
Private Const DT_CALCRECT = &H400
Private Const GWL_HINSTANCE = (-6)
Private Const GWL_WNDPROC = (-4)
Private Const WH_CALLWNDPROC = 4
Private Const SM_CXSCREEN = 0
Private Const SM_CYSCREEN = 1
Private Const EM_AUTOURLDETECT = (WM_USER + 91)
Private Const ES_MULTILINE = &H4&
Private Const ES_READONLY As Integer = &H800
Private Const EM_EXGETSEL = (WM_USER + 52)
Private Const EM_EXSETSEL = (WM_USER + 55)
Private Const EM_DISPLAYBAND = (WM_USER + 51)
Private Const EM_FORMATRANGE As Long = (WM_USER + 57)
Private Const EM_SETBKGNDCOLOR = (WM_USER + 67)
Private Const EM_SETEVENTMASK = (WM_USER + 69)
Private Const ENM_MOUSEEVENTS = &H20000
Private Const ENM_LINK = &H4000000
Private Const EN_MSGFILTER = &H700&
Private Const EN_LINK = &H70B&
Private Const BN_CLICKED = 0
Private Const COLOR_BTNFACE = 15
Private Const SWP_FRAMECHANGED = &H20
Private Const SWP_NOSIZE = &H1
Private Const SWP_NOMOVE As Long = &H2
Private Const SWP_NOZORDER = &H4
Private Const SW_HIDE = 0
Private Const SW_SHOW = 5
Private Const WM_ERASEBKGND = &H14
Private Const WM_PAINT = &HF
Private Const WS_VSCROLL = &H200000
Private Const WS_BORDER = &H800000
Private Const WS_CHILD = &H40000000
Private Const WS_VISIBLE = &H10000000
Private Const WM_COPY = &H301&
Private Const WM_LBUTTONUP = &H202
Private Const WM_RBUTTONDOWN = &H204
Private Const WM_CREATE = &H1
Private Const WM_CTLCOLORBTN = &H135
Private Const WM_CTLCOLORDLG = &H136
Private Const WM_CTLCOLORSTATIC = &H138
Private Const WM_DESTROY = &H2
Private Const WM_SHOWWINDOW = &H18
Private Const WM_COMMAND = &H111
Private Const WM_SETTEXT = &HC
Private Const WM_GETTEXT = &HD
Private Const WM_GETTEXTLENGTH = &HE
Private Const WM_NOTIFY = &H4E
Private Const WC_RICHEDIT1 = "RichEdit"
Private Const WC_RICHEDIT2 = "RichEdit20A"
Private Const MF_STRING = &H0&
Private Const TPM_LEFTALIGN = &H0&
Private Const TPM_RETURNCMD = &H100&
Private Const TPM_RIGHTBUTTON = &H2&
Private Const AURL_ENABLEURL = 1
Private Const AURL_ENABLEEMAILADDR = 2
Private Const AURL_ENABLEDRIVELETTERS = 16
Private Const cTimerText = "[Time]"
'***************************************************************************************
'* Variables *
'***************************************************************************************
' Variables de fonctionnement
Private MB_AppOldProc ' Procédure de gestion des messages de la fenêtre d'application
Private MB_OldProc ' Procédure de gestion des messages de la fenêtre de dialogue
Private MB_BackColor As Long ' Couleur de fond
Private MB_TimerId ' Id du timer = Handle de la zone static additonnelle
Private MB_TimerCpt As Integer ' Compteur pour timer
Private MB_Prompt As String
Private MB_TextWidth As Long
Private MB_IdDefault As Integer
Private MB_DefaultButtonText As String
Private MB_TimerText As String
Private MB_Blink As Boolean
Private MB_ButtonText(1 To 4) As String
'***************************************************************************************
'* FONCTIONS *
'***************************************************************************************
' MBCallback_Timer est appelé par les timers à intervalle régulier
Private Function MBCallback_Timer(ByVal hwnd, ByVal uMsg As Long, ByVal wParam, ByVal lParam) As Long
Dim ltext As String
Dim lButtonText As String
Dim lLen As Long
Static sCalcul As Integer
' Citation de l'aide de AddressOf :
'Étant donné que l'appelant d'un rappel ne se trouve pas dans votre programme,
'il est important qu'une erreur rencontrée dans la procédure de rappel ne se propage pas
'dans l'appelant. Pour ce faire, insérez l'instruction On Error Resume Next
'au début de la procédure de rappel.
' !! <-- Compiler le projet après chaque modification dans cette procédure --> !!
' !! <-- Une erreur de syntaxe dans cette procédure fera planter l'application --> !!
' !! <-- Ajouter <Option Explicit> en début de module pour éviter les erreurs de syntaxe --> !!
On Error Resume Next
Select Case wParam
Case MB_TimerId
' Si clignotement du bouton, on passe 4 fois par seconde dans cette procédure
sCalcul = (sCalcul + 1) Mod (1 - 3 * MB_Blink)
If sCalcul = 0 Then MB_TimerCpt = MB_TimerCpt - 1
lLen = InStr(MB_TimerText, cTimerText)
If lLen <> 0 Then
' Remplace [Time] par le temps restant
ltext = Left(MB_TimerText, lLen - 1) & Str(MB_TimerCpt) & Right(MB_TimerText, Len(MB_TimerText) - lLen - Len(cTimerText) + 1)
End If
' Affiche le texte
lButtonText = MB_DefaultButtonText & ltext
SetWindowText GetDlgItem(hwnd, MB_IdDefault), IIf(sCalcul <> 0 Or Not MB_Blink, lButtonText, "")
' Cick sur le bouton par défaut lorsque la minuterie est écoulée
If MB_TimerCpt = -1 Then
Call SendMessage(hwnd, WM_COMMAND, (BN_CLICKED * &H10000) Or (MB_IdDefault And &HFFFF&), ByVal hwnd)
End If
End Select
End Function
'------------------------------------------------------------------------------------------------
' Gestion des messages de la boîte de dialogue
'------------------------------------------------------------------------------------------------
' hwnd : Handle de la fenêtre
' Msg : Numéro du message
' wParam et lParam : Paramètres du message
'------------------------------------------------------------------------------------------------
Private Function MBProc(ByVal hwnd, ByVal Msg As Long, ByVal wParam, ByVal lParam)
Dim lRect As RECT, lTextRect As RECT, lClientRect As RECT
Dim lRichRect As RECT
Dim lItemPlcmt As WINDOWPLACEMENT, lImgPlcmt As WINDOWPLACEMENT
Dim lScrWidth As Single, lScrHeight As Single
Dim lCpt As Integer
Dim lPos As Long
Dim lStyle As Long
Dim lOldRect As RECT
Dim lFR As FormatRange
Dim lLB As LOGBRUSH
Dim ltext As String
Dim lLen As Long
Dim lClass As String
Dim lNMH As NMHDR
Dim lLink As ENLINK
Dim lMaxCellx As Long
Dim lcellx As Long
Dim lButtonLeft As Long, lButtonsWidth As Long, lNbButton As Integer
Dim lButtonText As String
Static lButtons(1 To 4) As Variant ' 4 boutons max par fenêtre MsgBox
Dim lDlgItem
Dim lCR As CHARRANGE, lOldCR As CHARRANGE
Dim lResult As Long, lhMenu, lPt As PointAPI
Dim lhDC
Static shwnd
Static sBrush
On Error Resume Next
' Initialisation structure nécessaire pour win98
lItemPlcmt.length = Len(lItemPlcmt)
lImgPlcmt.length = Len(lImgPlcmt)
Select Case Msg
' Notification
Case WM_NOTIFY
RtlMoveMemory lNMH, ByVal lParam, Len(lNMH)
Select Case lNMH.code
Case EN_MSGFILTER
' Click droit sur RichEdit --> Affiche menu contextuel
' Soruce : FAQ DVP : http://access.developpez.com/sources/?page=frms#ContextMenuAPI
RtlMoveMemory lLink, ByVal lParam, Len(lLink)
If (lLink.Msg = WM_RBUTTONDOWN) Then
'Creer le menu contextuel
lhMenu = CreatePopupMenu()
'Creer les items du menu contextuel
AppendMenu lhMenu, MF_STRING, 1, "&Copier tout le texte"
AppendMenu lhMenu, MF_STRING, 2, "Copier le texte &sélectionné"
'Récupere l'emplacement de la souris
GetCursorPos lPt
'Affiche le menu à l'emplacement de la souris
'Et récupere la valeur de l'item cliqué
lResult = TrackPopupMenuEx(lhMenu, TPM_LEFTALIGN Or TPM_RETURNCMD _
Or TPM_RIGHTBUTTON, lPt.x, lPt.Y, hwnd, ByVal 0&)
'Supprime le menu
DestroyMenu lhMenu
'Traite le resultat
Select Case lResult
Case 1
' Copie tout le texte
SendMessage shwnd, EM_EXGETSEL, 0, lOldCR
lCR.cpMin = 0
lCR.cpMax = -1
SendMessage shwnd, EM_EXSETSEL, 0, lCR
SendMessage shwnd, WM_COPY, 0, ByVal 0
SendMessage shwnd, EM_EXSETSEL, 0, lOldCR
Case 2
' Copie le texte sélectionné
SendMessage shwnd, WM_COPY, 0, ByVal 0
End Select
End If
Case EN_LINK
' Notification sur un lien hypertexte
#If VBA7 Then
RtlMoveMemory lLink, ByVal lParam, LenB(lLink)
#Else
RtlMoveMemory lLink, ByVal lParam, Len(lLink)
#End If
If (lLink.Msg = WM_LBUTTONUP) Then
' Click sur un lien
ltext = GetPlainText(shwnd)
ltext = Mid(ltext, lLink.chrg.cpMin + 1, lLink.chrg.cpMax - lLink.chrg.cpMin)
ShellExecute hwnd, "open", ltext, 0, vbNullString, 1
End If
End Select
Case WM_PAINT
' On ne peint pas le fond ici mais dans WM_ERASEBKGND
Dim lPaint As PAINTSTRUCT
BeginPaint hwnd, lPaint
EndPaint hwnd, lPaint
MBProc = 1
Exit Function
Case WM_ERASEBKGND
Dim lUpdateRect As RECT
Call GetUpdateRect(hwnd, lUpdateRect, 1)
FillRect wParam, lUpdateRect, sBrush
MBProc = 1
Exit Function
Case WM_CREATE
' Définition de la couleur
lLB.lbColor = MB_BackColor
' Crée une brosse de la couleur choisi
sBrush = CreateBrushIndirect(lLB)
' Affichage de la fenêtre de dialogue
Case WM_SHOWWINDOW
' Position de l'icône
Call GetWindowPlacement(GetDlgItem(hwnd, 20), lImgPlcmt)
' Lit la taille de l'écran
lScrWidth = GetSystemMetrics(SM_CXSCREEN)
lScrHeight = GetSystemMetrics(SM_CYSCREEN)
' Lit la taille de la fenêtre de dialogue
Call GetWindowRect(hwnd, lRect)
Call GetClientRect(hwnd, lClientRect)
' Sauvegarde la position d'origine
lOldRect = lRect
If LoadLibrary("RichEd32.Dll") > 32 Then
lClass = WC_RICHEDIT2
ElseIf LoadLibrary("RICHED20.DLL") > 32 Then
lClass = WC_RICHEDIT1
End If
' Style = Ascenseur vertical + Fenêtre fille + Visible +
' Multi-ligne + Lecture Seule
lStyle = WS_VSCROLL Or WS_CHILD Or WS_VISIBLE Or ES_MULTILINE Or ES_READONLY
' Crée une fenêtre avec editeur de texte
shwnd = CreateWindowEx(0, lClass, vbNullString, _
lStyle, 0, 0, 0, 0, hwnd, 0&, 0&, ByVal 0&)
' Auto-détection des hyperliens
SendMessage shwnd, EM_AUTOURLDETECT, AURL_ENABLEURL Or AURL_ENABLEEMAILADDR Or AURL_ENABLEDRIVELETTERS, ByVal 0
SendMessage shwnd, EM_SETEVENTMASK, 0, ByVal ENM_LINK Or ENM_MOUSEEVENTS
' Couleur de fond
SendMessage shwnd, EM_SETBKGNDCOLOR, 0, ByVal MB_BackColor
' Affiche le texte
SendMessage shwnd, WM_SETTEXT, Len(MB_Prompt), ByVal MB_Prompt
' Recherche la hauteur nécessaire pour afficher le texte
lFR.hdc = GetDC(shwnd)
lFR.hdcTarget = lFR.hdc
' Recherche d'un éventuel tableau (wordwrap ne fonctionne pas correctement)
' On recherche le mot-clé "\cellx" qui est suivi de la position de la cellule en twips
' Puis on utilisera cette position pour augmenter la taille de la fenêtre
lPos = 1
Do
On Error Resume Next
lPos = InStr(lPos, MB_Prompt, "\cellx")
If lPos = 0 Then Exit Do
lcellx = Mid(MB_Prompt, lPos + 6, InStr(lPos + 1, MB_Prompt, "\") - lPos - 6)
lPos = lPos + 1
If lcellx > lMaxCellx Then lMaxCellx = lcellx
' Sort de la boucle en cas d'erreur pour éviter une boucle infinie
If Err.Number <> 0 Then Exit Do
Loop
' Marge à gauche et en haut
lImgPlcmt.rcNormalPosition.Right = lImgPlcmt.rcNormalPosition.Right + gMarginLeft
lFR.rc.Top = lFR.rc.Top + PixelToTwipsY(gMarginTop)
' Largeur
lFR.rc.Right = PixelToTwipsX(lClientRect.Right - lImgPlcmt.rcNormalPosition.Right)
If lMaxCellx > lFR.rc.Right Then lFR.rc.Right = lMaxCellx * 1.05
If MB_TextWidth <> 0 Then lFR.rc.Right = PixelToTwipsX(MB_TextWidth)
' Heuteur maxi = 80% de la hauteur de l'écran (l'ascenseur s'affiche si nécessaire)
lFR.rc.Bottom = PixelToTwipsY(CLng(lScrHeight) * 0.8)
' Repositionne/Redimensionne le contrôle richedit
Call SetWindowPos(shwnd, 0, _
lImgPlcmt.rcNormalPosition.Right, _
TwipsToPixelY(lFR.rc.Top), _
TwipsToPixelX(lFR.rc.Right - lFR.rc.Left), _
TwipsToPixelY(lFR.rc.Bottom - lFR.rc.Top), _
SWP_NOZORDER Or SWP_FRAMECHANGED)
' Taille du contrôle (sans la barre de défilement)
GetClientRect shwnd, lRichRect
lFR.rc.Right = lFR.rc.Left + PixelToTwipsX(lRichRect.Right)
' Marge à droite
lFR.rc.Right = lFR.rc.Right + PixelToTwipsX(gMarginRight)
lRichRect.Right = lRichRect.Right + gMarginRight
' Mesure l'espace requis pour tout écrire
lFR.chrg.cpMin = 0
lFR.chrg.cpMax = -1
Call SendMessage(shwnd, EM_FORMATRANGE, False, lFR)
Call SendMessage(shwnd, EM_DISPLAYBAND, 0, lFR.rc)
' Largeur de la fenêtre de message
lRect.Right = lRect.Left + (lRect.Right - lRect.Left) - lClientRect.Right + lImgPlcmt.rcNormalPosition.Right + lRichRect.Right
' Redimensionne le contrôle richedit pour accueillir le texte en hauteur
Call SetWindowPos(shwnd, 0, _
0, _
0, _
TwipsToPixelX(lFR.rc.Right - lFR.rc.Left), _
TwipsToPixelY(lFR.rc.Bottom - lFR.rc.Top), _
SWP_NOMOVE Or SWP_NOZORDER Or SWP_FRAMECHANGED)
' Libère le contrôle et le DC
SendMessage shwnd, EM_FORMATRANGE, False, ByVal 0
ReleaseDC shwnd, lFR.hdc
' Marge en bas
lFR.rc.Bottom = lFR.rc.Bottom + PixelToTwipsY(gMarginBottom)
' Repositionne les boutons verticalement
If TwipsToPixelY(lFR.rc.Bottom) < lImgPlcmt.rcNormalPosition.Bottom Then
lFR.rc.Bottom = PixelToTwipsY(lImgPlcmt.rcNormalPosition.Bottom)
End If
lButtons(1) = Array(0, 0)
lButtons(2) = Array(0, 0)
lButtons(3) = Array(0, 0)
lButtons(4) = Array(0, 0)
For lCpt = 1 To 9
lDlgItem = GetDlgItem(hwnd, lCpt)
If lDlgItem <> 0 Then
Call GetWindowPlacement(lDlgItem, lItemPlcmt)
lItemPlcmt.rcNormalPosition.Left = lItemPlcmt.rcNormalPosition.Left - (lOldRect.Right - lRect.Right) / 2
lItemPlcmt.rcNormalPosition.Right = lItemPlcmt.rcNormalPosition.Right - (lOldRect.Right - lRect.Right) / 2
lItemPlcmt.rcNormalPosition.Bottom = 5 + TwipsToPixelY(lFR.rc.Bottom) + lItemPlcmt.rcNormalPosition.Bottom - lItemPlcmt.rcNormalPosition.Top
lItemPlcmt.rcNormalPosition.Top = 5 + TwipsToPixelY(lFR.rc.Bottom)
Call SetWindowPlacement(lDlgItem, lItemPlcmt)
' Stocke la position et le handle des boutons dans le tableau lButtons
' triés ascendant selon leur position de gauche à droite
If lButtons(3)(0) > 0 And lItemPlcmt.rcNormalPosition.Left > lButtons(3)(0) Then
lButtons(4) = Array(lItemPlcmt.rcNormalPosition.Left, lDlgItem)
ElseIf lButtons(2)(0) > 0 And lItemPlcmt.rcNormalPosition.Left > lButtons(2)(0) Then
lButtons(4) = lButtons(3)
lButtons(3) = Array(lItemPlcmt.rcNormalPosition.Left, lDlgItem)
ElseIf lButtons(1)(0) > 0 And lItemPlcmt.rcNormalPosition.Left > lButtons(1)(0) Then
lButtons(4) = lButtons(3)
lButtons(3) = lButtons(2)
lButtons(2) = Array(lItemPlcmt.rcNormalPosition.Left, lDlgItem)
Else
lButtons(4) = lButtons(3)
lButtons(3) = lButtons(2)
lButtons(2) = lButtons(1)
lButtons(1) = Array(lItemPlcmt.rcNormalPosition.Left, lDlgItem)
End If
End If
Next
' Redimensionne la fenêtre de dialogue
lRect.Bottom = 5 + lRect.Top + (lRect.Bottom - lRect.Top) - lClientRect.Bottom + lItemPlcmt.rcNormalPosition.Bottom
' Calcul la nouvelle position centrée
lOldRect = lRect
lRect.Left = (lScrWidth - (lRect.Right - lRect.Left)) / 2
lRect.Right = lRect.Right + lRect.Left - lOldRect.Left
lRect.Top = (lScrHeight - (lRect.Bottom - lRect.Top)) / 2
lRect.Bottom = lRect.Bottom + lRect.Top - lOldRect.Top
Call SetWindowPos(hwnd, 0, lRect.Left, lRect.Top, lRect.Right - lRect.Left, lRect.Bottom - lRect.Top, SWP_NOZORDER Or SWP_FRAMECHANGED)
' Modifie le texte des boutons et les ajuste à la taille du texte
For lCpt = 1 To 4
lButtonText = MB_ButtonText(lCpt)
If lButtonText <> "" Then
lDlgItem = lButtons(lCpt)(1)
If lDlgItem <> 0 Then
lhDC = GetDC(lDlgItem)
DrawTextEx GetDC(lDlgItem), lButtonText, _
Len(lButtonText), lTextRect, _
DT_CALCRECT, ByVal 0
ReleaseDC lDlgItem, lhDC
' Ajoute une marge
lTextRect.Right = lTextRect.Right * 1.2
Call GetWindowPlacement(lDlgItem, lItemPlcmt)
If lItemPlcmt.rcNormalPosition.Right - lItemPlcmt.rcNormalPosition.Left < lTextRect.Right Then
lItemPlcmt.rcNormalPosition.Right = lItemPlcmt.rcNormalPosition.Left + lTextRect.Right * 1.2
Call SetWindowPlacement(lDlgItem, lItemPlcmt)
End If
SetWindowText lDlgItem, lButtonText
End If
End If
Next
' Lance le timer
If MB_TimerCpt > 0 Then
MB_TimerId = shwnd
#If VBA6 Then
APISetTimer hwnd, MB_TimerId, 1000 + MB_Blink * 750, AddressOf MBCallback_Timer
#Else
APISetTimer hwnd, MB_TimerId, 1000 + MB_Blink * 750, AddrOf("MBCallback_Timer")
#End If
End If
' Couleur des boutons
Case WM_CTLCOLORBTN
If MB_IdDefault = 0 Then
' Lit la taille de la fenêtre de dialogue
Call GetClientRect(hwnd, lClientRect)
If lParam = GetFocus Then ' Bouton qui a le focus = bouton par défaut
For lCpt = 1 To 9
lDlgItem = GetDlgItem(hwnd, lCpt)
If lDlgItem = lParam And MB_TimerCpt > 0 Then
' Redimensionne le bouton par défaut pour accueillir le
' texte de la minuterie
MB_IdDefault = lCpt
MB_DefaultButtonText = GetPlainText(lParam)
DrawTextEx wParam, MB_DefaultButtonText & MB_TimerText, _
Len(MB_DefaultButtonText & MB_TimerText), lTextRect, _
DT_CALCRECT, ByVal 0
Call GetWindowPlacement(lParam, lItemPlcmt)
If lItemPlcmt.rcNormalPosition.Right - lItemPlcmt.rcNormalPosition.Left < lTextRect.Right Then
lItemPlcmt.rcNormalPosition.Right = lItemPlcmt.rcNormalPosition.Left + lTextRect.Right
Call SetWindowPlacement(lParam, lItemPlcmt)
End If
End If
If lDlgItem <> 0 Then
' Nombre de boutons
lNbButton = lNbButton + 1
Call GetWindowPlacement(lDlgItem, lItemPlcmt)
' Taille cumulée des boutons
lButtonsWidth = lButtonsWidth + lItemPlcmt.rcNormalPosition.Right - lItemPlcmt.rcNormalPosition.Left
End If
Next
' Vérifie qu'on a assez de place pour afficher tous les boutons
If lClientRect.Right < lButtonsWidth + (lNbButton + 1) * 10 Then
Call GetWindowRect(hwnd, lRect)
Call SetWindowPos(hwnd, 0, lRect.Left - (lButtonsWidth + (lNbButton + 1) * 10 - lClientRect.Right) / 2, _
lRect.Top, lRect.Right - lRect.Left + (lButtonsWidth + (lNbButton + 1) * 10 - lClientRect.Right), lRect.Bottom - lRect.Top, _
SWP_NOZORDER Or SWP_FRAMECHANGED)
' Redimensionne également le contrôle richedit
Call GetWindowPlacement(shwnd, lItemPlcmt)
lItemPlcmt.rcNormalPosition.Right = lItemPlcmt.rcNormalPosition.Right + (lButtonsWidth + (lNbButton + 1) * 10 - lClientRect.Right)
Call SetWindowPlacement(shwnd, lItemPlcmt)
End If
' Repositionne les boutons (10 pixels entre chaque bouton)
' à partir des infos stockées dans le tableau lButtons
Call GetClientRect(hwnd, lClientRect)
lButtonLeft = (lClientRect.Right - lButtonsWidth - (lNbButton - 1) * 10) / 2
For lCpt = 1 To 4
lDlgItem = lButtons(lCpt)(1)
If lDlgItem <> 0 Then
Call GetWindowPlacement(lDlgItem, lItemPlcmt)
lItemPlcmt.rcNormalPosition.Right = lItemPlcmt.rcNormalPosition.Right + lButtonLeft - lItemPlcmt.rcNormalPosition.Left
lItemPlcmt.rcNormalPosition.Left = lButtonLeft
Call SetWindowPlacement(lDlgItem, lItemPlcmt)
lButtonLeft = lButtonLeft + lItemPlcmt.rcNormalPosition.Right - lItemPlcmt.rcNormalPosition.Left + 10
End If
Next
If MB_TimerCpt > 0 Then
lLen = InStr(MB_TimerText, cTimerText)
If lLen <> 0 Then
' Remplace [Time] par le temps restant
ltext = Left(MB_TimerText, lLen - 1) & Str(MB_TimerCpt) & Right(MB_TimerText, Len(MB_TimerText) - lLen - Len(cTimerText) + 1)
End If
' Affiche le texte
lButtonText = MB_DefaultButtonText & ltext
SetWindowText lParam, lButtonText
End If
End If
End If
' COULEUR DES CONTROLES
Case WM_CTLCOLORDLG, WM_CTLCOLORSTATIC
' Masque le texte d'origine
If lParam = GetDlgItem(hwnd, 65535) Then
ShowWindow lParam, SW_HIDE
End If
' Change la couleur de fond du texte d'information
If MB_BackColor <> -1 Then Call SetBkColor(wParam, MB_BackColor)
' Affectation de la brosse
MBProc = sBrush
' On sort de la fonction pour éviter que le code standard rechange les couleurs
Exit Function
' FERMETURE DE LA FENETRE
Case WM_DESTROY
' Timer
APIKillTimer hwnd, MB_TimerId
MB_TimerId = 0
' Supprime le contrôle
DestroyWindow shwnd
' Stoppe la surveillance des messages de la fenêtre
Call SetWindowLong(hwnd, GWL_WNDPROC, MB_OldProc)
' Initialise les variables
shwnd = 0
sBrush = 0
MB_IdDefault = 0
End Select
' Appelle la fonction de gestion des messages d'origine
MBProc = CallWindowProc(MB_OldProc, hwnd, Msg, wParam, ByVal lParam)
End Function
'------------------------------------------------------------------------------------------------
' Gestion des messages de l'application en attente d'ouverture de la boîte de dialogue
'------------------------------------------------------------------------------------------------
' wParam et lParam : Paramètres du message
'------------------------------------------------------------------------------------------------
Private Function MBAppProc(ByVal nCode As Long, ByVal wParam, ByVal lParam)
Dim lCWP As CWPSTRUCT ' Structure pour paramètres des messages
Dim lClass As String ' Nom de la classe de la fenêtre
On Error Resume Next
' Copie les paramètres dans une structure
RtlMoveMemory lCWP, ByVal lParam, Len(lCWP)
' Si message de création
If lCWP.Message = WM_CREATE Then
' Lecture du nom de la classe
lClass = Space(255)
lClass = Left(lClass, GetClassName(lCWP.hwnd, ByVal lClass, 255))
' Les boîtes de dialogue ont comme classe : #32770
If lClass = "#32770" Then
' Renvoie les messages de la boîte de dialogue vers notre procédure
#If VBA6 Then
MB_OldProc = SetWindowLong(lCWP.hwnd, GWL_WNDPROC, AddressOf MBProc)
#Else
MB_OldProc = SetWindowLong(lCWP.hwnd, GWL_WNDPROC, AddrOf("MBProc"))
#End If
' Stoppe la surveillance des messages
Call UnhookWindowsHookEx(MB_AppOldProc)
End If
End If
' Appelle la fonction de gestion des messages d'origine
MBAppProc = CallNextHookEx(MB_AppOldProc, nCode, wParam, ByVal lParam)
End Function
'------------------------------------------------------------------------------------------------
' Fonction publique d'appel de la boîte de message
'------------------------------------------------------------------------------------------------
#If VBA6 Then
Public Function MsgBoxEx(ByVal Prompt As String, Optional Buttons As VbMsgBoxStyle = vbOKOnly, _
Optional ByVal Title As Variant, Optional ByVal HelpFile As String, _
Optional ByVal Context As Long, _
Optional ByVal BackColor As Long = -1, Optional pTexteWidth As Long, _
Optional pTimer As Integer, Optional pTimerText As String = " ([Time] s)", _
Optional pBlink As Boolean, Optional pButtonText1 As String, _
Optional pButtonText2 As String, Optional pButtonText3 As String, _
Optional pButtonText4 As String) As Integer
#Else
Public Function MsgBoxEx(ByVal Prompt As String, Optional Buttons As Long, _
Optional ByVal Title As Variant, Optional ByVal HelpFile As String, _
Optional ByVal Context As Long, _
Optional ByVal BackColor As Long = -1, Optional pTexteWidth As Long, _
Optional pTimer As Integer, Optional pTimerText As String = " ([Time] s)", _
Optional pBlink As Boolean, Optional pButtonText1 As String, _
Optional pButtonText2 As String, Optional pButtonText3 As String, _
Optional pButtonText4 As String) As Integer
#End If
On Error GoTo gestion_erreurs:
' Message
MB_Prompt = Prompt
' Couleur de fond
MB_BackColor = GetSysColor(COLOR_BTNFACE)
If BackColor <> -1 Then MB_BackColor = GetColor(BackColor)
' Timer
MB_TimerCpt = pTimer
' Largeur du texte
MB_TextWidth = pTexteWidth
' Texte minuterie
MB_TimerText = pTimerText
' Clignotement du bouton par défaut
MB_Blink = pBlink
' Texte des boutons
MB_ButtonText(1) = pButtonText1
MB_ButtonText(2) = pButtonText2
MB_ButtonText(3) = pButtonText3
MB_ButtonText(4) = pButtonText4
' Surveille tous les messages de l'application en attente d'ouverture de la boîte de dialogue
#If VBA6 Then
MB_AppOldProc = SetWindowsHookEx(WH_CALLWNDPROC, AddressOf MBAppProc, GetWindowLong(GetForegroundWindow, GWL_HINSTANCE), GetCurrentThreadId())
#Else
MB_AppOldProc = SetWindowsHookEx(WH_CALLWNDPROC, AddrOf("MBAppProc"), GetWindowLong(GetForegroundWindow, GWL_HINSTANCE), GetCurrentThreadId())
#End If
' Appel la boîte de message MsgBox standard
MsgBoxEx = MsgBox("", Buttons, Title, HelpFile, Context)
' Stoppe la surveillance des messages
Call UnhookWindowsHookEx(MB_AppOldProc)
gestion_erreurs:
If Err.Number <> 0 Then MsgBox Err.Description
End Function
'------------------------------------------------------------------------------------------------
' Récupère la couleur système si nécessaire
'------------------------------------------------------------------------------------------------
' pColor : Numéro de la couleur
' Renvoie la couleur dans un Long
'------------------------------------------------------------------------------------------------
Private Function GetColor(pColor As Long) As Long
If pColor < 0 Then
Call OleTranslateColor(pColor, 0, pColor)
End If
GetColor = pColor
End Function
'------------------------------------------------------------------------------------------------
' Remplacement de AddressOf Pour version 97
'------------------------------------------------------------------------------------------------
#If VBA6 Then
#Else
Private Function AddrOf(strFuncName As String) As Long
Dim hProject As Long
Dim lngResult As Long
Dim strID As String
Dim lpfn As Long
Dim strFuncNameUnicode As String
Const NO_ERROR = 0
strFuncNameUnicode = StrConv(strFuncName, vbUnicode)
Call GetCurrentVbaProject(hProject)
If hProject <> 0 Then
lngResult = GetFuncID( _
hProject, strFuncNameUnicode, strID)
If lngResult = NO_ERROR Then
lngResult = GetAddr(hProject, strID, lpfn)
If lngResult = NO_ERROR Then
AddrOf = lpfn
End If
End If
End If
End Function
#End If
'------------------------------------------------------------------------------------------------
' Converti les Twips en Pixels sur l'axe horizontal
'------------------------------------------------------------------------------------------------
' pTwipsX : Valeur à convertir en Twips
' Renvoie la valeur convertie en Pixels
'------------------------------------------------------------------------------------------------
Private Function TwipsToPixelX(pTwipsX As Long) As Long
Static Mult As Long
Dim hdc
If Mult = 0 Then
hdc = GetDC(0)
Mult = 1440 / GetDeviceCaps(hdc, LOGPIXELSX)
ReleaseDC 0, hdc
End If
TwipsToPixelX = CLng(pTwipsX / Mult)
End Function
'------------------------------------------------------------------------------------------------
' Converti les Twips en Pixels sur l'axe vertical
'------------------------------------------------------------------------------------------------
' pTwipsY : Valeur à convertir en Twips
' Renvoie la valeur convertie en Pixels
'------------------------------------------------------------------------------------------------
Private Function TwipsToPixelY(pTwipsY As Long) As Long
Static Mult As Long
Dim hdc
If Mult = 0 Then
hdc = GetDC(0)
Mult = 1440 / GetDeviceCaps(hdc, LOGPIXELSY)
ReleaseDC 0, hdc
End If
TwipsToPixelY = CLng(pTwipsY / Mult)
End Function
'------------------------------------------------------------------------------------------------
' Converti les Pixels en Twips sur l'axe horizontal
'------------------------------------------------------------------------------------------------
' pPixelsX : Valeur à convertir en Pixels
' Renvoie la valeur convertie en Twips
'------------------------------------------------------------------------------------------------
Private Function PixelToTwipsX(pPixelsX As Long) As Long
Static Mult As Long
Dim hdc
If Mult = 0 Then
hdc = GetDC(0)
Mult = 1440 / GetDeviceCaps(hdc, LOGPIXELSX)
ReleaseDC 0, hdc
End If
PixelToTwipsX = pPixelsX * Mult
End Function
'------------------------------------------------------------------------------------------------
' Converti les Pixels en Twips sur l'axe vertical
'------------------------------------------------------------------------------------------------
' pPixelsY : Valeur à convertir en Pixels
' Renvoie la valeur convertie en Twips
'------------------------------------------------------------------------------------------------
Private Function PixelToTwipsY(pPixelsY As Long) As Long
Static Mult As Single
Dim hdc
If Mult = 0 Then
hdc = GetDC(0)
Mult = 1440 / GetDeviceCaps(hdc, LOGPIXELSY)
ReleaseDC 0, hdc
End If
PixelToTwipsY = pPixelsY * Mult
End Function
'------------------------------------------------------------------------------------------------
' Charge le contenu d'un fichier dans une variable
'------------------------------------------------------------------------------------------------
Public Function LoadRTFFile(pFile As String) As String
Dim ltexte As String
Dim lFile
Dim lSize As Long
On Error GoTo gestion_erreurs
lFile = CreateFile(pFile, GENERIC_READ, FILE_SHARE_READ, ByVal 0&, OPEN_EXISTING, 0, 0)
lSize = GetFileSize(lFile, 0)
ltexte = Space(lSize)
ReadFile lFile, ByVal ltexte, lSize, 0, ByVal 0&
CloseHandle lFile
gestion_erreurs:
CloseHandle lFile
LoadRTFFile = ltexte
End Function
'------------------------------------------------------------------------------------------------
' Renvoit le texte non formaté du contrôle
'------------------------------------------------------------------------------------------------
Private Function GetPlainText(pHwnd) As String
Dim lLen
Dim ltext As String
lLen = SendMessage(pHwnd, WM_GETTEXTLENGTH, 0, ByVal 0)
ltext = Space(CLng(lLen) + 1)
ltext = Left(ltext, CLng(SendMessage(pHwnd, WM_GETTEXT, lLen + 1, ByVal ltext)))
#If VBA6 Then
ltext = Replace(ltext, vbCr, "")
#Else
ltext = Replace97(ltext, vbCr, "")
#End If
GetPlainText = ltext
End Function
#If VBA6 Then
#Else
'------------------------------------------------------------------------------------------------
' Remplacement de Replace Pour version 97
'------------------------------------------------------------------------------------------------
Public Function Replace97(ByVal sItem As String, ByVal sFindString As String, ByVal sReplaceString As String) As String
Dim lPos As Long
If InStr(sItem, sFindString) = 0 Then
Replace97 = sItem: Exit Function
End If
lPos = 1
Do
lPos = InStr(lPos, sItem, sFindString)
If lPos > 0 Then
sItem = Left(sItem, lPos - 1) & sReplaceString & _
Right(sItem, Len(sItem) - lPos - Len(sFindString) + 1)
Else
Exit Do
End If
Loop
Replace97 = sItem
End Function
#End If
'------------------------------------------------------------------------------------------------
Function RTFtoTEXT(pRTF As String) As String
'------------------------------------------------------------------------------------------------
Dim lLen As Long
Dim ltext As String
Dim lClass As String
Dim lHwnd As Long
On Error GoTo gestion_erreurs
' Chargement librairie
' cf http://msdn2.microsoft.com/en-us/library/bb787873(VS.85).aspx
If LoadLibrary("Riched20.dll") > 32 Then
lClass = WC_RICHEDIT2
ElseIf LoadLibrary("Riched32.dll") > 32 Then
lClass = WC_RICHEDIT1
End If
' Crée une fenêtre avec editeur de texte
lHwnd = CreateWindowEx(0, lClass, vbNullString, _
WS_CHILD Or ES_MULTILINE, 0, 0, 0, 0, Application.hwnd, 0&, 0&, ByVal 0&)
' Injecte le texte dans le contrôle
SendMessage lHwnd, WM_SETTEXT, Len(pRTF), ByVal pRTF
' Relit le texte sans balises RTF
lLen = SendMessage(lHwnd, WM_GETTEXTLENGTH, 0, ByVal 0)
ltext = Space(lLen + 1)
ltext = Left(ltext, SendMessage(lHwnd, WM_GETTEXT, lLen + 1, ByVal ltext))
RTFtoTEXT = ltext
gestion_erreurs:
' Supprime le contrôle
DestroyWindow lHwnd
End Function
'------------------------------------------------------------------------------------------------
'------------------------------------------------------------------------------------------------
'------------------------------------------------------------------------------------------------
Function MsgBoxRTF(ByVal FichierRTF As String, _
Optional ByVal Titre As String = "", _
Optional ByVal Largeur As Long = 0, _
Optional ByVal Bouton1 As String = "", _
Optional ByVal Bouton2 As String = "", _
Optional ByVal Bouton3 As String = "", _
Optional ByVal Compteur As Integer = 0, _
Optional AutoriseModifArguments As Byte = 2) As Integer
'------------------------------------------------------------------------------------------------
' FichierRTF : soit le fichier RTF (si pas de répertoire indiqué alors prend celui de l'application)
' soit le texte en dur.
' Titre : titre de la fenêtre.
' Largeur : largeur de la fenêtre en pixels (si pas assez grand étend automatiquement).
' Bouton1 : texte du bouton 1.
' Bouton2 : texte du bouton 2.
' Bouton3 : texte du bouton 3.
' Compteur : la durée du compte à rebours en secondes.
' AutoriseModifArguments : indique s'il est autorisé de modifier les arguments dans le fichier RTF.
' 0 = rien, 1 = tout sauf les boutons et le compte à rebours, 2 = tous.
'------------------------------------------------------------------------------------------------
' S'il y a un compte à rebours, alors le dernier bouton est utilisé.
' Si AutoriseModifArguments vaut True alors la largeur, le titre, l'icône et le texte des boutons peuvent
' être modifiés directement dans le message source en respectant cette syntaxe en début du message (exemples):
' [Largeur=480] [Titre=Fin de cession] [Icone=vbQuestion] [Bouton1=Oui] [Bouton2=Non] [Bouton3=Quitte dans (Time) seconde(s)] [Compteur=10]
' Il n'y a pas d'ordre précis à respecter pour indiquer ces arguments.
'------------------------------------------------------------------------------------------------
' Exemples d'appel:
' i = ModMsgBoxPlus.MsgBoxRTF("Message_1.rtf")
' i = ModMsgBoxPlus.MsgBoxRTF("[Icone=vbQuestion]" & vbCrLf & "Avez-vous compris cet exemple ?" & vbCrLf, "Coucou", 0, "Oui", "Non", "", 10)
'------------------------------------------------------------------------------------------------
' Retourne :
' 1 si le premier bouton est validé (ou croix de fermeture si 1 seul bouton existe).
' 2 si le deuxième bouton est validé.
' 3 si le troisième bouton est validé.
' 0 en cas d'erreur.
'------------------------------------------------------------------------------------------------
Dim i As Long, ii As Long, Icone As Integer
Dim Buttons As Integer, TexteCompteur As String
Dim ToTxt As String, Txt As String, NbArg As Integer, n As Integer
' Gestion des erreurs:
On Error GoTo Gest_Err
' S'il faut lire un fichier .RTF:
If UCase(Right(FichierRTF, 4)) = ".RTF" Then
' Si le répertoire du fichier RTF n'est pas indiqué alors prend le répertoire de l'application:
If InStr(1, FichierRTF, "\", vbTextCompare) = 0 Then FichierRTF = ThisWorkbook.Path & "\" & FichierRTF
' Lecture du corp du texte:
FichierRTF = LoadRTFFile(FichierRTF)
End If
' Icône par défaut:
Icone = vbCritical
' S'il est possible de modifier les arguments:
If AutoriseModifArguments > 0 Then
' Conversion du RTF en TXT:
ToTxt = RTFtoTEXT(FichierRTF)
' Recherche s'il y un titre d'indiqué:
Txt = ExtractionArgument(ToTxt, "Titre")
If Txt > "" Then
Titre = Txt
NbArg = NbArg + 1
End If
' Recherche s'il y a une largeur d'indiquée:
Txt = ExtractionArgument(ToTxt, "Largeur")
If Txt > "" Then
Largeur = Val(Txt)
NbArg = NbArg + 1
End If
' Recherche s'il y a une icône d'indiquée:
Txt = ExtractionArgument(ToTxt, "Icone")
If Txt > "" Then
Select Case Txt
Case "vbCritical": Icone = vbCritical
Case "vbQuestion": Icone = vbQuestion
Case "vbExclamation": Icone = vbExclamation
Case "vbInformation": Icone = vbInformation
End Select
NbArg = NbArg + 1
End If
' S'il est autorisé de modifier le compteur et les boutons:
If AutoriseModifArguments > 1 Then
' Recherche s'il faut modifier le compte à rebours:
Txt = ExtractionArgument(ToTxt, "Compteur")
If Txt > "" Then
Compteur = Val(Txt)
NbArg = NbArg + 1
End If
' Recherche s'il faut modifier le texte du bouton 1:
Txt = ExtractionArgument(ToTxt, "Bouton1")
If Txt > "" Then
Bouton1 = Txt
NbArg = NbArg + 1
End If
' Recherche s'il faut modifier le texte du bouton 2:
Txt = ExtractionArgument(ToTxt, "Bouton2")
If Txt > "" Then
Bouton2 = Txt
NbArg = NbArg + 1
End If
' Recherche s'il faut modifier le texte du bouton 3:
Txt = ExtractionArgument(ToTxt, "Bouton3")
If Txt > "" Then
Bouton3 = Txt
NbArg = NbArg + 1
End If
End If
' Supprime les arguments dans le format RTF:
If NbArg > 0 Then
i = InStr(1, FichierRTF, "[", vbTextCompare)
For n = 1 To NbArg
ii = InStr(i, FichierRTF, "]", vbTextCompare)
i = ii + 1
Next n
i = InStr(1, FichierRTF, "[", vbTextCompare)
Txt = Mid(FichierRTF, i, ii - i + 1)
FichierRTF = Replace(FichierRTF, Txt, "", , 1)
End If
End If
' Suivant le nombre de boutons à afficher:
If Bouton1 <> "" Then
Buttons = vbOKOnly + vbDefaultButton1
If Compteur > 0 Then
TexteCompteur = Bouton1
If Bouton2 = "" Then Bouton1 = ""
End If
End If
If Bouton2 <> "" Then
Buttons = vbYesNo + vbDefaultButton2
If Compteur > 0 Then
TexteCompteur = Bouton2
If Bouton3 = "" Then Bouton2 = ""
End If
End If
If Bouton3 <> "" Then
Buttons = vbAbortRetryIgnore + vbDefaultButton3
If Compteur > 0 Then TexteCompteur = Bouton3: Bouton3 = ""
End If
' Remplace (Time) par [Time] dans le texte du compteur et l'ajoute s'il manque:
If Compteur > 0 Then
TexteCompteur = Replace(TexteCompteur, "(Time)", "[Time]", , , vbTextCompare)
If InStr(1, TexteCompteur, "[Time]", vbTextCompare) = 0 Then TexteCompteur = TexteCompteur & " ([Time] )"
End If
' Affiche la fenêtre:
i = MsgBoxEx(FichierRTF, Icone + Buttons, Titre, , , _
pTexteWidth:=Largeur, _
pTimer:=Compteur, _
pTimerText:=TexteCompteur, _
pButtonText1:=IIf(Bouton1 <> "", Bouton1, " "), _
pButtonText2:=IIf(Bouton2 <> "", Bouton2, " "), _
pButtonText3:=IIf(Bouton3 <> "", Bouton3, " "))
' Retourne le bouton cliqué: 1er, 2ème, ou 3éme (et pas le code VbMsgBoxStyle):
Select Case i
Case vbOK: MsgBoxRTF = 1
Case vbYes: MsgBoxRTF = 1
Case vbAbort: MsgBoxRTF = 1
Case vbNo: MsgBoxRTF = 2
Case vbRetry: MsgBoxRTF = 2
Case vbIgnore: MsgBoxRTF = 3
End Select
Gest_Err:
Err.Clear
End Function
'------------------------------------------------------------------------------------------------
'------------------------------------------------------------------------------------------------
Private Function ExtractionArgument(StrTxt As String, StrArg As String) As String
'------------------------------------------------------------------------------------------------
' Fait l'extraction de la valeur de l'argument StrArg passé dans le texte StrTxt
'------------------------------------------------------------------------------------------------
Dim i As Long, ii As Long, Txt As String
' Gestion des erreurs:
On Error GoTo Gest_Err:
' Isole dans le texte StrTxt la valeur de l'argument comprise entre "=" et "]":
i = InStr(1, StrTxt, "[" & StrArg, vbTextCompare)
If i > 0 Then
ii = InStr(i, StrTxt, "]", vbTextCompare)
Txt = Mid(StrTxt, i, ii - i + 1)
i = 1 + InStr(1, Txt, "=", vbTextCompare)
ii = InStr(i, Txt, "]", vbTextCompare)
ExtractionArgument = Mid(Txt, i, ii - i)
End If
Gest_Err:
Err.Clear
End Function
'------------------------------------------------------------------------------------------------
'------------------------------------------------------------------------------------------------ |
Partager