Announcement

Collapse

Forum Guidelines

This forum is for finished source code that is working properly. If you have questions about this or any other source code, please post it in one of the Discussion Forums, not here.
See more
See less

Button with border after click

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

  • Button with border after click

    My favorite method of marking an additional button after last click.

    Code:
    #COMPILER PBWIN
    #DIM ALL
    #COMPILE EXE
    
    #INCLUDE "Win32API.inc"
    
    
    FUNCTION WINMAIN ( _
                      BYVAL hInstance AS DWORD, _
                      BYVAL hPrevInstance AS DWORD, _
                      BYVAL lpCmdLine AS ASCIIZ PTR, _
                      BYVAL iCmdShow AS LONG _
                     ) _
                      AS LONG
    
      LOCAL hWnd _
            AS DWORD
    
      LOCAL Msg _
            AS tagMsg
    
      LOCAL wce _
            AS WndClassEx
    
      LOCAL szClassName _
            AS ASCIIZ * 80
    
      szClassName       = "Example: Button-Frame"
    
      wce.cbSize        = SIZEOF(wce)
      wce.STYLE         = %CS_HREDRAW OR %CS_VREDRAW
      wce.lpfnWndProc   = CODEPTR(WndProc)
      wce.cbClsExtra    = 0
      wce.cbWndExtra    = 0
      wce.hInstance     = hInstance
      wce.hIcon         = LoadIcon(hInstance, "PROGRAM")
      wce.hCursor       = LoadCursor(%NULL, BYVAL %IDC_ARROW)
      wce.hbrBackground = GetStockObject(%WHITE_BRUSH)
      wce.lpszMenuName  = %NULL
      wce.lpszClassName = VARPTR(szClassName)
      wce.hIconSm       = LoadIcon(hInstance, BYVAL %IDI_APPLICATION)
    
      RegisterClassEx wce
    
      hWnd = CreateWindowEx( _
                            0, _                    
                            szClassName, _            
                            szClassName, _            
                            %WS_OVERLAPPEDWINDOW, _  
                            500, _        
                            300, _        
                            500, _        
                            300, _        
                            %HWND_DESKTOP, _          
                            BYVAL %NULL, _            
                            hInstance, _              
                            BYVAL %NULL _
                           )              
    
      ShowWindow hWnd, iCmdShow
      UpdateWindow hWnd
    
      DO WHILE GetMessage(Msg, %NULL, 0, 0)
    
          TranslateMessage Msg
          DispatchMessage Msg
    
      LOOP
    
      FUNCTION = msg.wParam
    
    END FUNCTION
    
    
    FUNCTION WndProc ( _
                      BYVAL hWnd AS DWORD, _
                      BYVAL wMsg AS DWORD, _
                      BYVAL wParam AS DWORD, _
                      BYVAL lParam AS LONG _
                     ) _
                      AS LONG
    
      LOCAL hCtl, _
            wStyle _
            AS DWORD
    
      LOCAL tRect _
            AS RECT
    
      STATIC IDC_BUTTON_1, _
             IDC_BUTTON_2 _
             AS DWORD
    
      SELECT CASE wMsg
    
        CASE %WM_CREATE
    
          IDC_BUTTON_1 = %WM_USER + 1
          IDC_BUTTON_2 = %WM_USER + 2
    
          wStyle = %WS_CHILD OR %WS_VISIBLE OR %WS_TABSTOP OR %WS_BORDER
    
          ': Create Button 1
          hCtl = CreateWindowEx( _
                                0, _
                                "Button", _
                                "Button 1", _
                                wStyle, _
                                50, _
                                50, _
                                150, _
                                50, _                              
                                hWnd, _
                                IDC_BUTTON_1, _    
                                GetModuleHandle(""), _
                                BYVAL %NULL _
                               )
    
          CALL SetWindowLong(hCtl, %GWL_STYLE, wStyle XOR %WS_BORDER)
    
          ': Create Button 2
          hCtl = CreateWindowEx( _
                                0, _
                                "Button", _
                                "Button 2", _
                                wStyle, _
                                250, _
                                50, _
                                150, _
                                50, _                              
                                hWnd, _
                                IDC_BUTTON_2, _    
                                GetModuleHandle(""), _
                                BYVAL %NULL _
                               )
    
          CALL SetWindowLong(hCtl, %GWL_STYLE, wStyle XOR %WS_BORDER)
    
          EXIT FUNCTION
    
        CASE %WM_COMMAND
    
          SELECT CASE LOWRD(wParam)
    
            CASE IDC_BUTTON_1    
    
              ': Set Border Button 1
              hCtl = GetDlgItem(hWnd, IDC_BUTTON_1)
    
              wStyle = GetWindowLong(hCtl, %GWL_STYLE)  
    
              CALL SetWindowLong(hCtl, %GWL_STYLE, wStyle OR %WS_BORDER)
              CALL GetWindowRect(hCtl, tRect)
              CALL MapWindowPoints(GetDesktopWindow(), GetParent(hCtl), tRect, 2)
    
              InvalidateRect GetParent(hCtl), tRect, %TRUE
              UpdateWindow GetParent(hCtl)
    
              ': Kill Border Button 2
              hCtl = GetDlgItem(hWnd, IDC_BUTTON_2)
    
              wStyle = GetWindowLong(hCtl, %GWL_STYLE)  
    
              CALL SetWindowLong(hCtl, %GWL_STYLE, wStyle AND NOT %WS_BORDER)
              CALL GetWindowRect(hCtl, tRect)
              CALL MapWindowPoints(GetDesktopWindow(), GetParent(hCtl), tRect, 2)
    
              InvalidateRect GetParent(hCtl), tRect, %TRUE
              UpdateWindow GetParent(hCtl)
    
              EXIT FUNCTION
    
            CASE IDC_BUTTON_2    
    
              ': Set Border Button 2
              hCtl = GetDlgItem(hWnd, IDC_BUTTON_2)
    
              wStyle = GetWindowLong(hCtl, %GWL_STYLE)  
    
              CALL SetWindowLong(hCtl, %GWL_STYLE, wStyle OR %WS_BORDER)
              CALL GetWindowRect(hCtl, tRect)
              CALL MapWindowPoints(GetDesktopWindow(), GetParent(hCtl), tRect, 2)
    
              InvalidateRect GetParent(hCtl), tRect, %TRUE
              UpdateWindow GetParent(hCtl)
    
              ': Kill Border Button 1
              hCtl = GetDlgItem(hWnd, IDC_BUTTON_1)
    
              wStyle = GetWindowLong(hCtl, %GWL_STYLE)  
    
              CALL SetWindowLong(hCtl, %GWL_STYLE, wStyle AND NOT %WS_BORDER)
              CALL GetWindowRect(hCtl, tRect)
              CALL MapWindowPoints(GetDesktopWindow(), GetParent(hCtl), tRect, 2)
    
              InvalidateRect GetParent(hCtl), tRect, %TRUE
              UpdateWindow GetParent(hCtl)          
    
              EXIT FUNCTION
    
            END SELECT  
    
        CASE %WM_DESTROY
    
          PostQuitMessage 0
    
          EXIT FUNCTION
    
      END SELECT
    
      FUNCTION = DefWindowProc(hWnd, wMsg, wParam, lParam)
    
    END FUNCTION

  • #2
    Two corrections

    Title: Button with additional border after click

    Comment: My favorite method of marking a button after last click.

    Comment

    Working...
    X