
The Enter key moves the focus and focused entry field is outlined.
This example was done in PowerBasic code and I would like to
duplicate it using PureBasic. It uses a Windows Callback and I just
don't understand how to convert it.
Anybody care to try it?
Here is the PowerBasic code as an example.
Code: Select all
'¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤
' Small sample of data input form. Textbox in focus is framed.
' Enter-key moves focus to next textbox, and closes dialog if
' Exit button has focus. Just to show some useful API tricks..
' Public Domain by Borje Hagsten, May 2003.
'¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤
' Declares
'--------------------------------------------------------------------
#COMPILE EXE
#INCLUDE "WIN32API.INC"
'--------------------------------------------------------------------
%IDC_LABEL1   = 140
%IDC_TEXT1    = 141
%IDC_LABEL2   = 142
%IDC_TEXT2    = 143
%IDC_LABEL3   = 144
%IDC_TEXT3    = 145
'--------------------------------------------------------------------
DECLARE CALLBACK FUNCTION DlgProc() AS LONG
DECLARE SUB FrameControlInFocus (BYVAL hDlg AS DWORD, BYVAL hWnd AS DWORD, _
                                 BYVAL clr AS DWORD)
'¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤
' Program entrance
'--------------------------------------------------------------------
FUNCTION WINMAIN (BYVAL hInst AS DWORD, BYVAL hPrevInstance AS DWORD, _
                  BYVAL lpszCmdLine AS ASCIIZ PTR, BYVAL nCmdShow AS LONG) AS LONG
  LOCAL hDlg AS DWORD
  DIALOG NEW 0, "Data Input",,, 220, 120, _
                %WS_CAPTION OR %WS_SYSMENU, 0 TO hDlg
  CONTROL ADD LABEL, hDlg, %IDC_LABEL1, "&Name",  6,  7,  50,  9
  CONTROL ADD TEXTBOX, hDlg, %IDC_TEXT1, "",      5, 17, 100, 13
  CONTROL ADD LABEL, hDlg, %IDC_LABEL2, "&City",  6, 34,  50,  9
  CONTROL ADD TEXTBOX, hDlg, %IDC_TEXT2, "",      5, 44, 100, 13
  CONTROL ADD LABEL, hDlg, %IDC_LABEL3, "&Phone", 6, 61,  50,  9
  CONTROL ADD TEXTBOX, hDlg, %IDC_TEXT3, "",      5, 71, 100, 13
  CONTROL ADD BUTTON, hDlg, %IDCANCEL, "E&xit", 164, 101, 50, 14
  DIALOG SHOW MODAL hDlg, CALL DlgProc
END FUNCTION
'¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤
' Main Dialog procedure
'--------------------------------------------------------------------
CALLBACK FUNCTION DlgProc() AS LONG
  SELECT CASE CBMSG
     CASE %WM_INITDIALOG
        STATIC sthText AS DWORD, stCol AS LONG 'to store handle and color for %WM_PAINT
     CASE %WM_PAINT       'must be able to repaint if dialog has
        IF sthText THEN   'been covered/uncovered by something else.
           FrameControlInFocus CBHNDL, sthText, stCol
        END IF
     CASE %WM_COMMAND
        SELECT CASE CBCTL
           CASE %IDC_TEXT1 TO %IDC_TEXT3   'textboxes only
              SELECT CASE CBCTLMSG
                 CASE %EN_SETFOCUS         'a textbox has got focus, draw frame
                    stCol   = RGB(255,0,0) 'store color and handle for eventual %WM_PAINT
                    sthText = CBLPARAM
                    FrameControlInFocus CBHNDL, sthText, stCol
                 CASE %EN_KILLFOCUS        'we are leaving a textbox, so wipe out drawn rect
                    FrameControlInFocus CBHNDL, CBLPARAM, GetSysColor(%COLOR_3DFACE)
                    sthText = 0  'reset handle, we don't need to repeat this under WM_PAINT
               END SELECT
           CASE %IDOK 'Enter key triggers IDOK in dialogs - let's use that fact..
              IF GetDlgCtrlId(GetFocus) = %IDCANCEL THEN 'if exit button
                 DIALOG END CBHNDL, 0 'whatever..
              ELSE 'else textbox - move to next
                 SetFocus GetNextDlgTabItem(CBHNDL, GetFocus, 0)
              END IF
           CASE %IDCANCEL
              IF CBCTLMSG = %BN_CLICKED OR CBCTLMSG = 1 THEN
                 DIALOG END CBHNDL, 0
              END IF
        END SELECT
  END SELECT
END FUNCTION
'¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤
' Draw a rectangle around any given control
'--------------------------------------------------------------------
SUB FrameControlInFocus (BYVAL hDlg AS DWORD, BYVAL hWnd AS DWORD, _
                         BYVAL clr AS DWORD)
  LOCAL hDC AS DWORD, hBrush AS DWORD, hPen AS DWORD, rc AS RECT
  GetWindowRect hWnd, rc            'get control's pos and size on screen
    MapWindowPoints 0, hDlg, rc, 2  'map rect to dialog
    InflateRect rc, 2, 2            'increase slightly to draw around control
  hDC = GetDc(hDlg)                      'use dialog's DC since we want to paint on dialog
     hPen = CreatePen(%PS_SOLID, 1, clr) 'create a pen for given color
     hPen = SelectObject(hDC, hPen)      'select the new pen into the DC
     hBrush = SelectObject(hDC, GetStockObject(%NULL_BRUSH)) 'use stock null brush for hollow rect
     Rectangle hDC, rc.nLeft, rc.nTop, rc.nRight, rc.nBottom 'draw the rectangle
     SelectObject hDC, hBrush 'return original pen and brush, then release DC
     DeleteObject SelectObject(hDC, hPen)
  ReleaseDc hDlg, hDC
END SUB
Terry








 
  Maybe I should write a program to send to them that shocks
  Maybe I should write a program to send to them that shocks And I promise not to buy your Inventory X application unless it can
 And I promise not to buy your Inventory X application unless it can