⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 control.bas

📁 Powerbasic 对GDI 的操作 很漂亮的代码!
💻 BAS
📖 第 1 页 / 共 4 页
字号:
                             BYVAL 0)                 ' creation parameters

          CALL ZI_SetProperty(GetDlgItem(hMain, %ID_THUMBCTRL), %ZI_GradientTop, RGB(0,32,64))
          CALL ZI_SetProperty(GetDlgItem(hMain, %ID_THUMBCTRL), %ZI_GradientBottom, RGB(0,128,200))
          CALL ZI_SetProperty(GetDlgItem(hMain, %ID_THUMBCTRL), %ZI_FitToWindow, 1)
          CALL ZI_SetFromFile(GetDlgItem(hMain, %ID_THUMBCTRL), "avalon.jpg")
        ' ******************************************************************************

        ' This window display an animated GIF file.
        ' ******************************************************************************
        ' Alternate methode to create a GDImage control
        ' We read first the size of the image to create
        ' window with client rectangle matching exactly
        ' the image size.
        ' ------------------------------------------------------------------------------
          FullPathName$ = "pingo2.gif"
          CALL ZI_GetImageSizeFromFile((FullPathName$), imgWidth&, imgHeight&)
          UseW& = imgWidth&  ' Use this to preserve the size of the picture
          UseH& = imgHeight& ' Use this to preserve the size of the picture
          Style& = %WS_CHILD OR %WS_VISIBLE 'OR %WS_HSCROLL OR %WS_VSCROLL
          StyleEx& = 0 ' %WS_EX_STATICEDGE
          CALL ZI_AdjustWindowRect(StyleEx&, UseW&, UseH&, Style&)
          CALL CreateWindowEx(StyleEx&, _
                             "ZIMAGECTRL", _            ' GDImage class name
                             "pingo2.gif", _            ' Optional full path name to picture
                             Style&, _                  ' window style
                             740 - (10 + UseW& + 50), _ ' initial x position
                             550 - (useH& + 24), _      ' initial y position
                             useW&, _                   ' Calculate Window Width
                             useH&, _                   ' Calculate Window Height
                             hMain, _                   ' parent window handle
                             %ID_ANIM, _                ' ControlID
                             zInstance, _               ' program instance handle
                             BYVAL 0)                   ' creation parameters
        ' ******************************************************************************

        ' Use a Layered child window
        ' ******************************************************************************
        ' This type of window MUST BE a POPUP window!
        ' ------------------------------------------------------------------------------
          FullPathName$ = "genus.jpg"
          CALL ZI_GetImageSizeFromFile((FullPathName$), imgWidth&, imgHeight&)
          UseW& = imgWidth&  ' Use this to preserve the size of the picture
          UseH& = imgHeight& ' Use this to preserve the size of the picture
          Style& = %WS_POPUP OR %WS_BORDER OR %WS_VISIBLE OR %WS_CAPTION
          StyleEx& = %WS_EX_TOOLWINDOW
          CALL ZI_AdjustWindowRect(StyleEx&, UseW&, UseH&, Style&)
          ghLayered& = CreateWindowEx(StyleEx&, _       ' Window extended style
                             "ZIMAGECTRL", _            ' GDImage class name
                             (FullPathName$), _         ' Optional full path name to picture
                             Style&, _                  ' window style
                             -9990, _                   ' initial x position
                             -9990, _                   ' initial y position
                             useW&, _                   ' Calculate Window Width
                             useH&, _                   ' Calculate Window Height
                             hMain, _                   ' Parent window handle
                             0, _ ' <-------------------- Must be %NULL
                             zInstance, _               ' program instance handle
                             BYVAL 0)                   ' creation parameters
'          CALL ZI_SetProperty(h&, %ZI_GradientTop, RGB(64,0,0))
'          CALL ZI_SetProperty(h&, %ZI_GradientBottom, RGB(200,0,0))
'          CALL ZI_SetFromFile(h&, FullPathName$)
          AlphaChannel? = 200 ' This value must range between 0-255 (0 = full translucency, 255 opaque mode)
          CALL ZI_SetLayeredAlpha(ghLayered&, AlphaChannel?)

        ' ******************************************************************************

        ' Create a "Child window Region"
        ' ******************************************************************************
        ' Can be either a CHILD or POPUP window
        ' ------------------------------------------------------------------------------
          FullPathName$ = "seiko.png"
          CALL ZI_GetImageSizeFromFile((FullPathName$), imgW&, imgH&)
          CALL GetWindowRect(hMain, rc)
          x = rc.nLeft - (imgW& \ 2): y = rc.nTop + rc.nBottom - rc.nTop - imgH&
          Style& = %WS_POPUP: StyleEx& = 0
          ghRegion = ZI_CreateWindowFromImage (Style&, _         ' Window style
                                              (FullPathName$), _ ' Full path name to picture
                                               x, _              ' initial x position
                                               y, _              ' initial y position
                                               hMain, _          ' Parent window handle
                                               0, _ ' <----------- Must be %NULL when using %WS_POPUP style
                                               StyleEx&, _       ' Window extended style
                                               %ZD_TOPLEFTCOLOR) ' Use pixel color at location 0,0 as transparent color
        ' To make it a layered window UNREM the comment below
         'AlphaChannel? = 220 ' This value must range between 0-255 (0 = full translucency, 255 opaque mode)
         'CALL ZI_SetLayeredAlpha(ghRegion, AlphaChannel?)
        ' ******************************************************************************

        ' Draw text using a GDImage DC
        ' ******************************************************************************
        ' Require the use of True Type Font name (TTF)
        ' ------------------------------------------------------------------------------
          UseFontSize& = 50
          ShowThisText$ = "GDImage plugin"
        ' Compute the bounding rectangle for the provided text
          CALL ZD_GetTextBound((ShowThisText$), _           ' The text being used
                               $Times_New_Roman, _          ' "Times New Roman"
                               UseFontSize&, _              ' The size for the font to use in pixel
                               RectWidth&, _                ' Get the bounding width
                               RectHeight&, _               ' Get the bounding height
                               %ZD_TextHorzUp)              ' We use horizontal orientation
        ' Show it centered
          x = (imgWidth& - RectWidth&) \ 2                  ' Compute X location
          y = (imgHeight& - RectHeight&) \ 2                ' Compute Y location
          Use3Doffset& = 1                                  ' The shadow offset
          UseARGB& = ZD_ColorARGB(255, RGB(255,0,0))        ' Compute the ARGB color
          CALL ZD_DrawTextToDC(ZI_GetDC(ghLayered&), _      ' Draw in this DC
                               (ShowThisText$), _           ' The text to draw
                               x, _                         ' X coordinate
                               y, _                         ' Y coordinate
                               UseARGB&, _                  ' Must be a valid ARGB color
                               $Times_New_Roman, _          ' "Times New Roman"
                               UseFontSize&, _              ' The size for the font to use in pixel
                               Use3Doffset&, _              ' Offset (in pixel) of the 3D shadow effect
                               %ZD_TextHorzUp)              ' Use horizontal orientation

          UseARGB& = ZD_ColorARGB(255, RGB(255,255,255))    ' Compute the ARGB color
          CALL ZD_DrawTextToDC(ZI_GetDC(ghLayered&), _      ' Draw in this DC
                               ("Version " + ZI_Version), _ ' The text to draw
                               imgWidth& - 50, _            ' X coordinate
                               y, _                         ' Y coordinate
                               UseARGB&, _                  ' Must be a valid ARGB color
                               $Times_New_Roman, _          ' "Times New Roman"
                               40, _                        ' The size for the font to use in pixel
                               Use3Doffset&, _              ' Offset (in pixel) of the 3D shadow effect
                               %ZD_TextVertUp)              ' Use vertical orientation

          UseARGB& = ZD_ColorARGB(255, RGB(255,255,0))      ' Compute the ARGB color
          CALL ZD_DrawTextToDC(ZI_GetDC(ghLayered&), _      ' Draw in this DC
                               ("Version " + ZI_Version), _ ' The text to draw
                               0, _                         ' X coordinate
                               40, _                        ' Y coordinate
                               UseARGB&, _                  ' Must be a valid ARGB color
                               $Times_New_Roman, _          ' "Times New Roman"
                               40, _                        ' The size for the font to use in pixel
                               Use3Doffset&, _              ' Offset (in pixel) of the 3D shadow effect
                               %ZD_TextVertDn)              ' Use vertical orientation

        ' Draw overlayed text in a GDImage Control
        ' ******************************************************************************
        ' Require the use of True Type Font name (TTF)
        ' This type of overlay doesn't alter the image shown in the background
        ' ------------------------------------------------------------------------------
        ' Draw text overlay above the GIF animated %ID_ANIM
          CALL ZD_DrawTextToCtrl(GetDlgItem(hMain, %ID_ANIM), _       ' The GDImage control handle
                                 "Hello", _                           ' The text to be displayed
                                 -3, _                                ' X coordinate
                                 70, _                                ' Y coordinate
                                 ZD_ColorARGB(128,RGB(255,0,0)), _    ' The ARGB color to use
                                 $Arial_Black, _                      ' The True Type Font to use
                                 20, _                                ' The font size in pixel
                                 %ID_TEXT_HELL0, _                    ' The unique object ID
                                 %ZS_VISIBLE)                         ' Show overlay
        ' Draw text overlay above the main GDImage control %ID_CTRL
          ShadowOffset& = 3
          CALL ZD_DrawTextToCtrl(GetDlgItem(hMain, %ID_CTRL), _       ' The GDImage control handle
                                 "Text Overlay is great", _           ' The text to be displayed
                                 150, _                               ' X coordinate
                                 400, _                               ' Y coordinate
                                 ZD_ColorARGB(200,RGB(255,0,0)), _    ' The ARGB color to use
                                 $Times_New_Roman, _                  ' The True Type Font to use
                                 40, _                                ' The font size in pixel
                                 %ID_TEXT_GREAT, _                    ' The unique object ID
                                 %ZS_VISIBLE, _                       ' Show overlay
                                 ShadowOffset&)                       ' Optional shadow effect (offset in pixel)
          ShadowOffset& = 1
          CALL ZD_DrawTextToCtrl(GetDlgItem(hMain, %ID_CTRL), _       ' The GDImage control handle
                                 "To create Watermark", _             ' The text to be displayed
                                 150, _                               ' X coordinate
                                 450, _                               ' Y coordinate
                                 ZD_ColorARGB(60,RGB(255,255,255)), _ ' The ARGB color to use
                                 $Times_New_Roman, _                  ' The True Type Font to use
                                 40, _                                ' The font size in pixel
                                 %ID_TEXT_WATERMARK, _                ' The unique object ID
                                 %ZS_VISIBLE, _                       ' Overlay visible at startup
                                 ShadowOffset&)                       ' Optional shadow effect (offset in pixel)

        ' Note:
        ' Using %ZS_SCROLL in ZS_STYLE allows you to link the object to the image.
        ' It seems to be part of the image when you scroll it.
          CALL ZD_DrawRectangleToCtrl(GetDlgItem(hMain, %ID_CTRL), _  ' The GDImage control handle
                                 50, _                                ' X coordinate
                                 50, _                                ' Y coordinate
                                 450, _                               ' The width
                                 300, _                               ' The height
                                 ZD_ColorARGB(255,RGB(250,250,255)), _ ' The ARGB color to use
                                 10, _                                ' The border size
                                 %ID_RECT_1, _                        ' The unique object ID
                                 %ZS_HIDDEN OR %ZS_SCROLL, _          ' Overlay is hidden at startup
                                 %ZD_DRAW_3DIN, _                     ' Drawing mode
                                 0)                                   ' Optional shadow effect (offset in pixel)

        ' Show the main window
          CALL ShowWindow(hMain, iCmdShow)
          CALL SetForegroundWindow(hMain)                  ' Slightly Higher Priority
          CALL SetFocus(hMain)                             ' Sets Keyboard Focus To The Window

          WHILE GetMessage(Msg, %NULL, 0, 0)
              IF IsDialogMessage(hMain, Msg) = %FALSE THEN
                 CALL TranslateMessage(msg)                ' Translate The Message
                 CALL DispatchMessage(msg)                 ' Dispatch The Message
              END IF
          WEND
          
          FUNCTION = msg.wParam

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -