SetFocus ..how to?

Started by Zlatko Vid, April 05, 2023, 10:16:11 AM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

Theo Gottwald

Quote from: Zlatko Vid on May 23, 2023, 07:10:15 AM// micro(A) code //
while wp ! 27  ' means NOT
'do nothing
wend

and that small empty loop enable use of arrow keys  ;)

You not even insert an "DOEVENTS()" or a "SLEEP"?
If so this looks to me like an endless loop which is not a construct that should be used - is it?

Charles Pegge

Thanks Pierre,

I'll include your IsDialog example in demos\wingui\, (some changes to the includes)

'uses rtl32
uses corewin

sys hEdit

%Edit                    101
%GWLP_WNDPROC             -4
%DEFAULT_GUI_FONT         17
%WM_GETDLGCODE        0x0087
%DLGC_WANTARROWS      0x0001 // Direction keys.
%DLGC_WANTTAB         0x0002 // TAB key.
%DLGC_WANTALLKEYS     0x0004 // All keyboard input.
%DLGC_WANTMESSAGE     0x0004 // All keyboard input (the application passes this message in the MSG structure to the control).
%DLGC_HASSETSEL       0x0008 // EM_SETSEL messages.
%DLGC_DEFPUSHBUTTON   0x0010 // Default push button.
%DLGC_UNDEFPUSHBUTTON 0x0020 // Non-default push button.
%DLGC_RADIOBUTTON     0x0040 // Radio button.
%DLGC_WANTCHARS       0x0080 // WM_CHAR messages.
%DLGC_STATIC          0x0100 // Static control.
%DLGC_BUTTON          0x2000 // Button.
'____________________________________________________________________________

function WinMain() as sys
 WndClass WindowClass
 MSG      WindowMessage
 long     WindowWidth, WindowHeight, WindowPosX, WindowPosY
 sys      hWnd
 sys      inst = GetModuleHandle(0)

 WindowClass.style         = CS_HREDRAW | CS_VREDRAW
 WindowClass.lpfnWndProc   = &WndProc
 WindowClass.cbClsExtra    = 0
 WindowClass.cbWndExtra    = 0
 WindowClass.hInstance     = GetModuleHandle(0)
 WindowClass.hIcon         = LoadIcon(0, IDI_APPLICATION)
 WindowClass.hCursor       = LoadCursor(0,IDC_ARROW)
 WindowClass.hbrBackground = 16
 WindowClass.lpszMenuName  = 0
 WindowClass.lpszClassName = @"OXYGEN BASIC"
 RegisterClass (WindowClass)

 WindowWidth  = 320
 WindowHeight = 100
 WindowPosX   = (GetSystemMetrics(SM_CXSCREEN) - WindowWidth)  / 2
 WindowPosY   = (GetSystemMetrics(SM_CYSCREEN) - WindowHeight) / 2
 hWnd = CreateWindowEx(WS_EX_STATICEDGE, WindowClass.lpszClassName,
                       "WM_GETDLGCODE demo", WS_OVERLAPPEDWINDOW,
                       WindowPosX, WindowPosY, WindowWidth, WindowHeight, 0, 0, inst, 0)

 hEdit = CreateWindowEx(WS_EX_CLIENTEDGE, "Edit", "Try [tab] [arrows] [enter]",
                        WS_CHILD OR WS_VISIBLE OR WS_TABSTOP,
                        20, 30, 270, 20,
                        hWnd, Edit, inst, 0)
 SendMessage(hEdit, WM_SETFONT, GetStockObject(DEFAULT_GUI_FONT), TRUE)
 SetWindowSubclass(hEdit, &EditSubclassProc, Edit, 0)
 SetFocus(hEdit)

 ShowWindow(hWnd, SW_SHOW)
 UpdateWindow(hWnd)

 while GetMessage(&WindowMessage, 0, 0, 0) > 0
   if IsDialogMessage(hWnd, &WindowMessage) = 0
     'if IsDialogMessage() return zero the message has not been processed
     'so use TranslateMessage/DispatchMessage
     TranslateMessage(&WindowMessage)
     DispatchMessage(&WindowMessage)
   end if
 wend

end function
'____________________________________________________________________________

function WndProc(sys hWnd, uint wMsg, sys wParam, sys lparam) as sys callback

 select wMsg

   case WM_DESTROY
     RemoveWindowSubclass(hEdit, &EditSubclassProc, Edit) 'unsubclass
     PostQuitMessage(0)

 end select

 function = DefWindowProc(hWnd, wMsg, wParam, lParam)

end function
'____________________________________________________________________________

function EditSubclassProc(sys hEdit, uint wMsg, sys wParam, sys lparam, uIdSubclass, dwRefData) as sys callback

 select case wMsg

   case WM_GETDLGCODE
     'DLGC_WANTARROWS      0x0001 Direction keys.
     'DLGC_WANTTAB         0x0002 TAB key.
     'DLGC_WANTALLKEYS     0x0004 All keyboard input.
     'DLGC_WANTMESSAGE     0x0004 All keyboard input (the application passes this message in the MSG structure to the control).
     'DLGC_HASSETSEL       0x0008 EM_SETSEL messages.
     'DLGC_DEFPUSHBUTTON   0x0010 Default push button.
     'DLGC_UNDEFPUSHBUTTON 0x0020 Non-default push button.
     'DLGC_RADIOBUTTON     0x0040 Radio button.
     'DLGC_WANTCHARS       0x0080 WM_CHAR messages.
     'DLGC_STATIC          0x0100 Static control.
     'DLGC_BUTTON          0x2000 Button.
     return DLGC_WANTALLKEYS

   case WM_CHAR
     SetWindowText(GetParent(hEdit), "WM_CHAR " & str(wParam))
     select case wParam

       case 1 'control-a
         SendMessage(hEdit, %EM_SETSEL, 0, -1) 'select everything
         return(0) 'do not forward Control-A

       case 48 TO 57, 45, 46  '0 to 9, minus, dot
         return(0)            'do not forward numbers, minus, dot

       case 65 TO 90          'A to Z
         'return(0)           'do not forward uppercase A to Z

       case 97 TO 122         'a to z
         'return(0)           'do not forward lowercase a to z

       case 9                 'TAB
         SetWindowText(hEdit, "tab key pressed")
         return(0)            'do not forward TAB

       case 13                'ENTER
         SetWindowText(hEdit, "enter key pressed")
         return(0)            'do not forward ENTER

       case 27                'ESC
         SendMessage(GetParent(hEdit), WM_CLOSE, 0, 0)
         return(0)

     end select

   case WM_KEYDOWN, WM_KEYUP
     SetWindowText(GetParent(hEdit), "WM_KEY " & str(wParam))
     select case wParam

       case 37 'left arrow
         SendMessage(hEdit, %EM_SETSEL, 0, 1) 'select first char
         return(0) 'rem to accept left arrow key, use up and down

       case 39 'right arrow
         SendMessage(hEdit, %EM_SETSEL, 1, 2) 'select second char
         return(0) 'rem to accept right arrow key, use up and down

     end select

 end select

 function = DefSubclassProc(hEdit, wMsg, wParam, lParam) 'forward message to edit control

end function
'
WinMain()

Zlatko Vid

QuoteYou not even insert an "DOEVENTS()" or a "SLEEP"?
If so this looks to me like an endless loop which is not a construct that should be used - is it?

Theo
This loop is just executed when key is pressed not all the time

here is whole block of micro(A) code :

WinMsg wmKEYDOWN

hWparam wp
'vkLEFT ?
if wp = 37
   if freq > 1
   freq = freq - 1 : length = cons/freq : dlen = int(length*5)
        if dx > 0
           dx = ox - (dlen/2)
           DisplayUpdate() : DrawDipol()
        endif
   endif
endif

'vkRIGHT ?
if wp = 39
    if freq < 2500
    freq = freq + 1 : length = cons/freq : dlen = int(length*5)
       if dx < 400
          dx = ox - (dlen/2)
          DisplayUpdate() : DrawDipol()
       endif
    endif
endif

'select mode
while wp ! 27
'wait
wend

EndWm
  •  

Zlatko Vid

QuoteAurel, the message will be proceed by either IsDialogMessage or TranslateMessage/DispatchMessage, not both.

Hi Piere

I understand that part now but not first time i try ..
I really never used this API function before
Also thanks on explanation and on example .
And also you must understand that i need it for my interpreter
or in another words this events execute interpreter loop.

here is that part ..of course i will add more events but for now it is...as is :
processing windows messages by Interpreter..................................................
CASE WM_MOUSEMOVE
'hMouseX = LoWord(lParam)
'hMouseY = HiWord(lParam)
         'call block winMsg
         if pos_wmMouseMove > 0
            hMouseX = LoWord(lParam)
   hMouseY = HiWord(lParam)
            tc = pos_wmMouseMove : tokInterpreter()
            tc = 0         
        end if
'keybord event...............................................................................
CASE WM_KEYDOWN
         hWParam = wParam
         'call block winMsg
         if pos_wmKeyDown > 0
            'print "KEYDOWN:" + str(pos_wmKeyDown)
            tc = pos_wmKeyDown : tokInterpreter()
            tc = 0
         end if
'...........................................................................................
CASE WM_KEYUP
         hWParam = wParam
         'call block winMsg
         if pos_wmKeyUp > 0
            'print "KEYDOWN:" + str(pos_wmKeyDown)
            tc = pos_wmKeyUp : tokInterpreter()
            tc = 0
         end if

'............................................................................................
    CASE WM_COMMAND
         controlID = LoWord(wParam)  'get control ID
         notifyCode = HiWord(wParam) 'get notification message
         'hWParam = wParam
         Select controlID
         hwParam = controlID

            CASE IDOK
            'call block winMsg
            if notifycode = BN_CLICKED           
              if pos_wmCommand > 0
                 tc = pos_wmCommand : tokInterpreter()
                 tc = 0
              end if
            end if

           CASE IDCANCEL
           'call block winMsg
            if notifycode = BN_CLICKED           
              if pos_wmCommand > 0
                 tc = pos_wmCommand : tokInterpreter()
                 tc = 0
              end if
            end if
 
  •