Announcement

Collapse
No announcement yet.

Loading icons with LoadImage function

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Loading icons with LoadImage function

    I know this is probably simple BUT NOT FOR ME.

    Why does i being numbered 101,102,103,104 work for the LoadImage function. For example %MB_ICONQUESTION has a decimal value of 32, so why does 102 work for the loading. And also how did he come up with these numbers 101,102,103 and 104.

    Thanks for any help


    Code:
    h = lStyle AND &H000000F0                                      ' Isolate Icon portion
    IF h = 0 THEN h = %MB_USERICON                                 ' Provide a default
    IF h = %MB_USERICON THEN                                       ' The user version?
          CONTROL ADD IMAGEX, hMsg, %MMB_Icon, "a", 10, 8, 32, 32, %SS_ICON
     ELSE                                                           ' Do the standard Icons
         CONTROL ADD LABEL,  hMsg, %MMB_Icon, "",  1, 1, 0, 0, %SS_ICON
          i = 0: j = %MB_OK                                           '
         SELECT CASE AS LONG h                                       '
              CASE %MB_ICONERROR, %MB_ICONHAND, %MB_ICONSTOP           '
                     i = 103: j = %MB_ICONHAND                             '
              CASE %MB_ICONQUESTION                                    '
                     i = 102: j = %MB_ICONQUESTION                         '
              CASE %MB_ICONWARNING, %MB_ICONEXCLAMATION                '
                     i = 101: j = %MB_ICONEXCLAMATION                      '
              CASE %MB_ICONINFORMATION, %MB_ICONASTERISK               '
                    i = 104: j = %MB_ICONASTERISK                         '
         END SELECT
    
         hIcon = LoadImage(BYVAL 0, BYVAL i, %IMAGE_ICON, 32, 32, 0)
        SendDlgItemMessage hMsg, %MMB_Icon, %STM_SETIMAGE, %IMAGE_ICON, hIcon
     END IF

  • #2
    LoadIimage has a first parameter of byVAL 0: "To load an OEM image, set this parameter to NULL.". In that case, they are loaded from user32.dll

    102 etc are the Icon Group IDs in user32.dll

    You can find then using something like Resource Hacker:

    Click image for larger version  Name:	SystemIcons.jpg Views:	0 Size:	26.3 KB ID:	796290

    Comment


    • #3
      Stuart:

      Thanks a million, I download Resource Hacker and was able to look at the icons and their numbers. You said when the first parameter of LoadImage is set to NULL the icons are loaded from user32.dll, is there another way of loading them and are they located in any other files.

      Again I want to thank you for clearing that up for me.

      Comment


      • #4
        Thre are icons, bitmaps and cursors in lots of DLLs and EXEs, both WIndows system dlls and files that come with various applications. Resource hacker will let you examine any of them. How about using the 256x256 pixel icon in Icon Group #2 in Notepad.exe

        Click image for larger version  Name:	reshack2.jpg Views:	1 Size:	28.4 KB ID:	796310
        '
        Code:
        #COMPILE EXE
        #DIM ALL
        #INCLUDE ONCE "WIN32API.INC"
        
        FUNCTION PBMAIN () AS LONG
            LOCAL hDlg,hLib,hIcon AS DWORD
        
            DIALOG NEW 0, "Icon Demo",100,100,300,300, %WS_POPUP OR _
                %WS_BORDER OR %WS_DLGFRAME OR %WS_CAPTION OR %WS_SYSMENU OR _
                %WS_CLIPSIBLINGS OR %WS_VISIBLE OR %DS_MODALFRAME OR %DS_3DLOOK OR _
                %DS_NOFAILCREATE OR %DS_SETFONT, %WS_EX_CONTROLPARENT OR %WS_EX_LEFT _
                OR %WS_EX_LTRREADING OR %WS_EX_RIGHTSCROLLBAR, TO hDlg
        
              CONTROL ADD IMAGEX, hDlg, 1001, "a", 10, 8, 256, 256, %SS_ICON
              hLib = LoadLibrary("notepad.exe")
              hIcon = LoadImage(hLib,BYVAL 2 , %IMAGE_ICON, 256, 256,0)
              SendDlgItemMessage hDlg, 1001, %STM_SETIMAGE, %IMAGE_ICON, hIcon
              freelibrary hLib
           DIALOG SHOW MODAL hDlg
        
        END FUNCTION
        '
        Click image for larger version  Name:	npicon.jpg Views:	1 Size:	7.6 KB ID:	796311

        Comment


        • #5
          I don't like magic numbers. MS says: If hinst is NULL and LR_LOADFROMFILE is not specified, the low-order word of this parameter must be the identifier of the OEM image to load. The OEM image identifiers are defined in WINUSER.H and have the following prefixes:
          '
          Code:
          '  Prefix   Meaning
          '  OBM_     OEM bitmaps
          '  OIC_     OEM icons
          '  OCR_     OEM cursors
          '
          Of course, system icons exist in many places, but is safer to use the following equates for those system icons defined in Windows API headers:
          '
          Code:
          %OIC_HAND        = 32513   ' icon equates to use with LoadImage
          %OIC_QUES        = 32514
          %OIC_BANG        = 32515
          %OIC_NOTE        = 32516
          %OIC_WINLOGO     = 32517
          %OIC_WARNING     = %OIC_BANG
          %OIC_ERROR       = %OIC_HAND
          %OIC_INFORMATION = %OIC_NOTE
          %OIC_SHIELD      = 32518
          '

          Comment


          • #6
            Originally posted by Borje Hagsten View Post
            I don't like magic numbers. MS says: If hinst is NULL and LR_LOADFROMFILE is not specified, the low-order word of this parameter must be the identifier of the OEM image to load. The OEM image identifiers are defined in WINUSER.H and have the following prefixes:
            That's from the old Win32.hlp file. That's not what is current at https://docs.microsoft.com/en-us/win...ser-loadimagea

            If the hinst parameter is NULL and the fuLoad parameter omits the LR_LOADFROMFILE value, the lpszName specifies the OEM image to load. The OEM image identifiers are defined in Winuser.h and have the following prefixes.
            ...
            To pass these constants to the LoadImage function, use the MAKEINTRESOURCE macro. For example, to load the OCR_NORMAL cursor, pass MAKEINTRESOURCE(OCR_NORMAL) as the lpszName parameter, NULL as the hinst parameter, and LR_SHARED as one of the flags to the fuLoad parameter.

            MakeIntResource s not actually required but %LR_SHARED is. This works:
            Code:
            hIcon = LoadImage(BYVAL 0, BYVAL %OIC_WARNING, %IMAGE_ICON, 32, 32,%LR_SHARED)

            Comment


            • #7
              STUART:
              Yes siree that works fine, Thanks Borje and Stuart it is just like going to a class when I ask a question on here. I learn sooooo much from you guys. Many thanks I will never be able to repay ya'll.

              Comment

              Working...
              X