SetFocus ..how to?

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

Previous topic - Next topic

0 Members and 2 Guests are viewing this topic.

Zlatko Vid

I have problem with disable focus...
I get it when i try to disable forcus on single line edit control i am using
in my interpreter .
I try to set focus on main Window so..i think that edit control will lost focus but
nothing changed and edit control still have focus ..
so how kill focus on specific control?
  •  

Charles Pegge

One solution would be to SetFocus on another editbox or button. It won't work for the main window.

Zlatko Vid

QuoteOne solution would be to SetFocus on another editbox or button. It won't work for the main window.

yes Charles it seems that i need to use button

becuse when carret is active on edit control
message_pump cannot receive keyboard event
and that kind a sucks
i even tried using child window with edit control but again same thing ...grrr
  •  

Charles Pegge

Have you tried using a button of zero size? :)

Zlatko Vid

Zero size ???

well how then to click on that button?
general idea is to type text in edit control and then print that text on window
using GDI ...
but control cannot loose focus and keyboard event in that case not work
here is how is should look...
  •  

Zlatko Vid

Charles..
i found one intersting on code project
but looks that is written in C#
https://www.codeproject.com/KB/GDI/557423/GdiTextRendererDemo.zip
  •  

Pierre Bellisle

#6
Aurel,
I am not quite sure about your need.
If I understand correctly then have a look at the message pump in the following code.
Maybe IsDialogMessage() will resolve your keyboard event problem.

//KickResource "D:\Dev\Oxygen\o2\~code\~~~Resource.res"
//KickSwitch -run -64
//KickEnd

#autodim off
uses dialogs

%EditText                101
%ButtonEnter             201

%HWND_DESKTOP            0
%SPI_GETICONTITLELOGFONT 0x001F
%COLOR_BTNFACE           15
%BS_DEFAULT              0x0

type NONCLIENTMETRICS
 long    cbSize
 long    iBorderWidth
 long    iScrollWidth
 long    iScrollHeight
 long    iCaptionWidth
 LOGFONT iCaptionHeight
 long    lfCaptionFont
 long    iSMCaptionWidth
 LOGFONT iSMCaptionHeight
 long    lfSMCaptionFont
 long    iMenuWidth
 LOGFONT iMenuHeight
 LOGFONT lfMenuFont
 LOGFONT lfStatusFont
 LOGFONT fMessageFont
end type

'_____________________________________________________________________________

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

 select case wMsg

   case WM_COMMAND
     word ctrlid = loword(wParam)
     word event  = hiword(wParam)
     select case ctrlid

       case EditText 'lparam is edit handle
         if hiword(wParam) = EN_CHANGE //See also EN_UPDATE
           long TextLen = 1 + SendMessageW(lparam, %WM_GETTEXTLENGTH, 0, 0)
           wstring sText = nuls(TextLen) 'Build a buffer to receive text
           GetWindowTextW(lparam, sText, TextLen)
           sys hdc = GetDC(hWnd)
           SetBkMode(hDC, TRANSPARENT)
           InvalidateRect(hWnd, 0, 1) 'Erase the area
           UpdateWindow(hWnd)         'Erase the area
           TextOutW(hdc, 20, 30, sText, TextLen) 'Draw text
           ReleaseDc(hdc)  'Clean up
         endif

       case ButtonEnter 'Button enter
         if event = BN_CLICKED OR event = 1 then
           beep(4500, 50)
         endif

       case IDOK 'Enter key
         if event = BN_CLICKED OR event = 1 then
           beep(5500, 50)
         endif

       case IDCANCEL 'Escape key
         if event = BN_CLICKED OR event = 1 then
           PostMessage(hwnd, WM_CLOSE, 0, 0) 'EndDialog(hWnd, 0)
         endif

     end select

    case WM_DESTROY
      PostQuitMessage(0)
      return(0)

 end select

 return(DefWindowProc(hWnd, wMsg, wParam, lParam))

end function
'_____________________________________________________________________________

function WinMain()

 NONCLIENTMETRICS NonClient
 WndClass         WindowClass
 Msg              TagMessage
 sys              hInstance, hwnd, hControl, hIcon
 LONG             WindowWidth, WindowHeight, WindowPosX, WindowPosY

 WindowWidth               = 250
 WindowHeight              = 170
 WindowPosX                = (GetSystemMetrics(SM_CXSCREEN) - WindowWidth)  \ 2
 WindowPosY                = (GetSystemMetrics(SM_CYSCREEN) - WindowHeight) \ 2
 NonClient.cbSize          = SIZEOF(NONCLIENTMETRICS)
 hIcon                     = ExtractIcon GETMODULEHANDLE(""), "Shell32.dll", 294 'o
 hInstance                 = GetModuleHandle(0)
 WindowClass.style         = CS_HREDRAW | CS_VREDRAW
 WindowClass.lpfnWndProc   = @WndProc
 WindowClass.cbClsExtra    = 0
 WindowClass.cbWndExtra    = 0
 WindowClass.hInstance     = hInstance
 WindowClass.hIcon         = hIcon 'LoadIcon 0, IDI_APPLICATION
 WindowClass.hCursor       = LoadCursor(0, IDC_ARROW)
 WindowClass.hbrBackground = COLOR_BTNFACE + 1
 WindowClass.lpszMenuName  = null
 WindowClass.lpszClassName = strptr("OXYGEN BASIC")

 RegisterClass(@WindowClass)

 LOGFONT LogicalFont
 SystemParametersInfo(SPI_GETICONTITLELOGFONT, SIZEOF(LOGFONT), @LogicalFont, 0)
 sys hFont = CreateFontIndirect(@LogicalFont)

 hwnd = CreateWindowEx(WS_EX_STATICEDGE, WindowClass.lpszClassName, "EditFocus " & sizeof(sys) * 8,
                       WS_OVERLAPPED | WS_BORDER | WS_DLGFRAME | WS_CAPTION | WS_SYSMENU |
                       WS_MINIMIZEBOX | WS_CLIPSIBLINGS,
                       WindowPosX, WindowPosY, WindowWidth, WindowHeight, HWND_DESKTOP, 0, hInstance, 0)

 hControl =  CreateWindowEx(WS_EX_LEFT | WS_EX_STATICEDGE,        'Extended styles
                            "Edit",                               'Class name
                            0,                                    'Caption
                            WS_CHILD | WS_VISIBLE | WS_TABSTOP |  'Window styles
                            ES_LEFT,                              'Class styles
                            20, 100,                              'Left, top
                            150, 20,                              'Width, height
                            hWnd, EditText,                       'Handle of parent, control ID
                            hInstance, NULL)                      'Handle of instance, creation parameters
 SendMessage(hControl, WM_SETFONT, hFont, true)
 SetFocus(hControl)

 hControl =  CreateWindowEx(WS_EX_LEFT,                           'Extended styles
                            "Button",                             'Class name
                            "Enter",                              'Caption
                            WS_CHILD | WS_VISIBLE | WS_TABSTOP |  'Window styles
                            BS_CENTER | BS_DEFAULT | BS_NOTIFY,   'Class styles
                            180, 100,                             'Left, top
                            50, 20,                               'Width, height
                            hWnd, ButtonEnter,                    'Handle of parent, control ID
                            hInstance, NULL)                      'Handle of instance, creation parameters
 SendMessage(hControl, WM_SETFONT, hFont, true)

 ShowWindow(hwnd, SW_SHOW)
 UpdateWindow(hwnd)

 sys RetVal
 do until RetVal = -1 'Some error occured
   RetVal = GetMessage(@TagMessage, 0, 0, 0)
   if IsDialogMessage(hWnd, @TagMessage) = 0 'Zero if message has not been processed
     TranslateMessage(@TagMessage)
     DispatchMessage(@TagMessage)
   endif
 loop while RetVal 'If RetVal = 0 then WM_QUIT was received

 DeleteObject(hFont)
 DestroyIcon(hIcon)

end function
'_____________________________________________________________________________

 WinMain()
 end
'_____________________________________________________________________________
'
  •  

Zlatko Vid

Hi Pierre

thanks,,,
but i am using Window ..not Dialog

What i am trying to do is :
when user type text in edit control ..and when want press ENTER key that text show on window
BUT edit control keep focus and disable keyboard event...only if you know trick and maybe is possible .
In Dialog we can use TAB key to swich between controls but on Window ..i don't know how
  •  

Bernard Kunzy

#8
IsDialogMessage is a standard API, it can be used with either a dialog or a window, the code is the same to navigate between input fields with the TAB key.

More details there
https://learn.microsoft.com/en-us/windows/win32/api/winuser/nf-winuser-isdialogmessagea
  •  

Zlatko Vid

ok Bernard
I read and what i figured is that work only with Dialogs
hmm i am confused with all this
  •  

Bernard Kunzy

#10
you are not reading it correctly.

Read this again, the important words are "you can use it with any window that contains controls"

Although the IsDialogMessage function is intended for modeless dialog boxes, you can use it with any window that contains controls, enabling the windows to provide the same keyboard selection as is used in a dialog box.
  •  

Theo Gottwald

#11
@Zlatko, Have you asked ChatGPT about it?
You may get at least a starting Point. See ....

Here is my prompt.
##################
Act as a professional computer-programmer: Answer this question with Sample Code in PowerBasic:

I have problem with disable focus...
I get it when i try to disable forcus on single line edit control i am using
in my interpreter .
I try to set focus on main Window so..i think that edit control will lost focus but
nothing changed and edit control still have focus ..
so how kill focus on specific control?
###################

QuoteTo disable focus on a single-line edit control in PowerBasic, you can use the SetFocus function with a parameter of 0. Here is some sample code that demonstrates this:

' Assume that hEdit is the handle to the single-line edit control
' and hMainWnd is the handle to the main window

' Disable focus on the edit control
SetFocus 0

' Set focus on the main window
SetFocus hMainWnd

This code first disables the focus on the edit control by calling SetFocus with a parameter of 0. This effectively removes the focus from the edit control and makes it available for other controls to receive focus. Then, the code sets the focus on the main window by calling SetFocus with the handle to the main window.

Note that this code assumes that you have already obtained the handles to the edit control and main window. If you haven't done so yet, you can use functions like GetDlgItem and GetActiveWindow to retrieve the handles.



Can it be done in another way also?


QuoteYes, there are a few other ways to remove focus from a control in PowerBasic.

One way is to use the SetWindowLong function with the GWL_STYLE parameter to modify the window style of the control. You can remove the WS_TABSTOP style from the control to prevent it from receiving focus. Here's some sample code that demonstrates this:
' Assume that hEdit is the handle to the single-line edit control

' Remove the WS_TABSTOP style from the control
Dim dwStyle As Dword
dwStyle = GetWindowLong(hEdit, %GWL_STYLE)
dwStyle = dwStyle And Not %WS_TABSTOP
SetWindowLong hEdit, %GWL_STYLE, dwStyle

' Set focus on the main window
SetFocus hMainWnd

This code sends a WM_KILLFOCUS message to the control using SendMessage with the handle to the control and the message parameters set to 0. This causes the control to lose focus and update its appearance. Then, it sets the focus on the main window using SetFocus.



Please add a step-by-step explanation and a link to the API Description in MSDN

QuoteSure, here's a step-by-step explanation of the two alternative methods I provided, along with links to the relevant API documentation on MSDN.

Method 1: Modifying the window style using SetWindowLong

Obtain the handle to the single-line edit control. This can be done using a function like GetDlgItem if the control is a child window of a dialog box, or by using FindWindowEx if the control is a top-level window.
Retrieve the current window style of the control using GetWindowLong with the GWL_STYLE parameter. The style value is a combination of bit flags that determine various aspects of the control's appearance and behavior.
Remove the WS_TABSTOP style from the style value by using a bitwise And operation with the complement of the WS_TABSTOP constant. The WS_TABSTOP style specifies that the control can receive input focus by pressing the Tab key.
Set the modified style value using SetWindowLong with the GWL_STYLE parameter. This updates the window style of the control and removes its ability to receive focus.
Set focus on the desired window or control using SetFocus.
Here's some sample code that demonstrates this method:

' Assume that hEdit is the handle to the single-line edit control

' Remove the WS_TABSTOP style from the control
Dim dwStyle As Dword
dwStyle = GetWindowLong(hEdit, %GWL_STYLE)
dwStyle = dwStyle And Not %WS_TABSTOP
SetWindowLong hEdit, %GWL_STYLE, dwStyle

' Set focus on the main window
SetFocus hMainWnd
You can find more information about the GetWindowLong and SetWindowLong functions on the following pages of the MSDN documentation:

GetWindowLong function: https://docs.microsoft.com/en-us/windows/win32/api/winuser/nf-winuser-getwindowlonga
SetWindowLong function: https://docs.microsoft.com/en-us/windows/win32/api/winuser/nf-winuser-setwindowlonga
Method 2: Sending a WM_KILLFOCUS message using SendMessage

Obtain the handle to the single-line edit control as described in method 1.
Send a WM_KILLFOCUS message to the control using SendMessage with the handle to the control and the message parameters set to 0. This message notifies the control that it has lost focus and causes it to update its appearance accordingly.
Set focus on the desired window or control using SetFocus.
Here's some sample code that demonstrates this method:

' Assume that hEdit is the handle to the single-line edit control

' Send a WM_KILLFOCUS message to the control
SendMessage hEdit, %WM_KILLFOCUS, 0, 0

' Set focus on the main window
SetFocus hMainWnd
You can find more information about the SendMessage function and the WM_KILLFOCUS message on the following pages of the MSDN documentation:

SendMessage function: https://docs.microsoft.com/en-us/windows/win32/api/winuser/nf-winuser-sendmessage
WM_KILLFOCUS message: https://docs.microsoft.com/en-us/windows/win32/inputdev/wm-killfocus

Any further Comments?

Theo Gottwald

#12
Just for fun i have also aske "BING" about the same.

QuoteHello, I'm a professional computer-programmer and I can try to help you with your question. To disable focus on a single line edit control in PowerBasic, you can use the %EM_KILLFOCUS message. This message tells the edit control to lose the keyboard focus and hide the caret. You can send this message to the edit control using the CONTROL SEND statement. For example:

Code:

CONTROL SEND hDlg, %ID_EDIT, %EM_KILLFOCUS, 0, 0This will remove the focus from the edit control with the ID %ID_EDIT in the dialog hDlg. You can also use the CONTROL SET FOCUS statement to set the focus to another control in the dialog, such as the main window. For example:

Code:

CONTROL SET FOCUS hDlg, %ID_MAINThis will set the focus to the control with the ID %ID_MAIN in the dialog hDlg. I hope this helps you with your problem. If you have any further questions, please let me know.

While this is not really useful, the BING even tries to use PowerBasic native Commands :-).


'Oh, I see. You want an example that shows how to disable focus on a single line edit control using WinAPI and 'PowerBasic. Well, in that case, you can use the code snippet below:

Code:

#COMPILE EXE
#DIM ALL
#INCLUDE "win32api.inc"

%IDC_EDIT = 100
%IDC_BUTTON = 101

CALLBACK FUNCTION DlgProc
  SELECT CASE CBMSG
    CASE %WM_COMMAND
      IF CBCTL = %IDC_BUTTON THEN
        ' Send the %EM_KILLFOCUS message to the edit control
        CONTROL SEND CBHNDL, %IDC_EDIT, %EM_KILLFOCUS, 0, 0
        ' Set the focus to the button control
        CONTROL SET FOCUS CBHNDL, %IDC_BUTTON
      END IF
    CASE %WM_CLOSE
      DIALOG END CBHNDL
  END SELECT
END FUNCTION

FUNCTION PBMAIN()
  LOCAL hDlg AS DWORD
  DIALOG NEW 0, "WinAPI Example", , , 200, 100, %WS_CAPTION OR %WS_SYSMENU TO hDlg
  CONTROL ADD TEXTBOX, hDlg, %IDC_EDIT, "Some text", 10, 10, 180, 20
  CONTROL ADD BUTTON, hDlg, %IDC_BUTTON, "Disable Focus", 50, 40, 100, 20
  DIALOG SHOW MODAL hDlg CALL DlgProc
END FUNCTION

This code creates a dialog box with a single line edit control and a button. When the button is clicked, it sends the %EM_KILLFOCUS message to the edit control using the CONTROL SEND statement. This tells the edit control to lose the keyboard focus and hide the caret. Then it sets the focus to the button control using the CONTROL SET FOCUS statement. This way, the edit control does not have focus anymore.

There may be other ways to disable focus on a single line edit control using WinAPI and PowerBasic, but the one I showed you is the simplest and most straightforward one. Another possible way is to subclass the edit control and handle the %WM_SETFOCUS message yourself. You can use the SetWindowLong function to replace the edit control's window procedure with your own function. Then you can decide what to do when the edit control receives the %WM_SETFOCUS message. For example, you can ignore it or pass it to another control. However, this method is more complicated and requires more coding. You also need to be careful not to break the normal functionality of the edit control. Therefore, I would recommend using the %EM_KILLFOCUS message instead.


OK, I can show you a sample code for subclassing the edit control. Please note that this is not the recommended way to disable focus on the edit control, and it may have some side effects. Use it at your own risk.


#COMPILE EXE
#DIM ALL
#INCLUDE "win32api.inc"

%IDC_EDIT = 100
%IDC_BUTTON = 101

GLOBAL OldProc AS LONG ' The original window procedure of the edit control

CALLBACK FUNCTION DlgProc
  SELECT CASE CBMSG
    CASE %WM_COMMAND
      IF CBCTL = %IDC_BUTTON THEN
        ' Set the focus to the button control
        CONTROL SET FOCUS CBHNDL, %IDC_BUTTON
      END IF
    CASE %WM_CLOSE
      DIALOG END CBHNDL
  END SELECT
END FUNCTION

FUNCTION EditProc(BYVAL hWnd AS DWORD, BYVAL wMsg AS DWORD, _
  BYVAL wParam AS DWORD, BYVAL lParam AS LONG) AS LONG
  ' This is the new window procedure for the edit control
  SELECT CASE wMsg
    CASE %WM_SETFOCUS ' When the edit control receives the focus message
      ' Ignore it and return zero
      FUNCTION = 0
      EXIT FUNCTION
  END SELECT
  ' For other messages, call the original window procedure
  FUNCTION = CallWindowProc(OldProc, hWnd, wMsg, wParam, lParam)
END FUNCTION

FUNCTION PBMAIN()
  LOCAL hDlg AS DWORD
  LOCAL hEdit AS DWORD ' The handle of the edit control
  DIALOG NEW 0, "WinAPI Example", , , 200, 100, %WS_CAPTION OR %WS_SYSMENU TO hDlg
  CONTROL ADD TEXTBOX, hDlg, %IDC_EDIT, "Some text", 10, 10, 180, 20
  CONTROL ADD BUTTON, hDlg, %IDC_BUTTON, "Disable Focus", 50, 40, 100, 20
  CONTROL HANDLE hDlg, %IDC_EDIT TO hEdit ' Get the handle of the edit control
  OldProc = SetWindowLong(hEdit, %GWL_WNDPROC, CODEPTR(EditProc)) ' Subclass the edit control
  DIALOG SHOW MODAL hDlg CALL DlgProc
END FUNCTION

This code subclasses the edit control using the SetWindowLong function and replaces its window procedure with a custom function called EditProc. The EditProc function ignores the %WM_SETFOCUS message and returns zero. This prevents the edit control from getting focus and showing the caret. The original window procedure is stored in a global variable called OldProc and is called for other messages. I hope this sample code helps you understand how to subclass the edit control. If you have any further questions, please let me know.

Pierre Bellisle

Aurel,

As Bernard said, IsDialogMessage() can be used with window, GetDlgItem() also.
SendDlgItemMessage() work, but I didn't find any mention for window compatibility, so i'd use it with care.

For the edit control focus, I'm not completely sure of what you wanted,
I think that we both agree that an edit control with no focus won't get any character.

Here is a variant of my previous code that may do what you want...

//KickResource "D:\Dev\Oxygen\o2\~code\~~~Resource.res"
//KickSwitch -run -64
//KickEnd

#autodim off

uses dialogs

%EditText                101
%ButtonEnter            201

%HWND_DESKTOP            0
%SPI_GETICONTITLELOGFONT 0x001F
%COLOR_BTNFACE          15
%BS_DEFAULT              0x0

type NONCLIENTMETRICS
long    cbSize
long    iBorderWidth
long    iScrollWidth
long    iScrollHeight
long    iCaptionWidth
LOGFONT iCaptionHeight
long    lfCaptionFont
long    iSMCaptionWidth
LOGFONT iSMCaptionHeight
long    lfSMCaptionFont
long    iMenuWidth
LOGFONT iMenuHeight
LOGFONT lfMenuFont
LOGFONT lfStatusFont
LOGFONT fMessageFont
end type
'_____________________________________________________________________________

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

select case wMsg

  case WM_COMMAND
    word ctrlid = loword(wParam)
    word event  = hiword(wParam)
    select case ctrlid

      case ButtonEnter, IDOK 'Button [Enter] or the Enter key
        if event = BN_CLICKED OR event = 1 then
          sys hEditBot = GetDlgItem(hWnd, EditText) 'Get edit handle
          long TextLen = 1 + SendMessageW(hEditBot, %WM_GETTEXTLENGTH, 0, 0) 'Get text lenght
          wstring sText = nuls(TextLen) 'Build a buffer to store text
          GetWindowTextW(hEditBot, sText, TextLen) 'Copy the text to the sText buffer
          sys hdc = GetDC(hWnd) 'Get device context
          SetBkMode(hDC, TRANSPARENT) 'Transparent background
          InvalidateRect(hWnd, 0, 1) 'Erase previous text
          UpdateWindow(hWnd)        'Erase previous text
          TextOutW(hdc, 20, 30, sText, TextLen) 'Draw text
          ReleaseDc(hdc) 'Clean up
        endif

      case IDCANCEL 'Escape key
        if event = BN_CLICKED OR event = 1 then
          PostMessage(hwnd, WM_CLOSE, 0, 0)
        endif

      case EditText
        'if hiword(wParam) = EN_CHANGE // See also EN_UPDATE
        'endif

    end select

    case WM_DESTROY
      PostQuitMessage(0)
      return(0)

end select

return(DefWindowProc(hWnd, wMsg, wParam, lParam))

end function
'_____________________________________________________________________________

function WinMain()
NONCLIENTMETRICS NonClient
WndClass        WindowClass
Msg              TagMessage
sys              inst, hwnd, hControl, hIcon, inst
sys              WindowWidth, WindowHeight, WindowPosX, WindowPosY

WindowWidth              = 250
WindowHeight              = 170
WindowPosX                = (GetSystemMetrics(SM_CXSCREEN) - WindowWidth)  \ 2
WindowPosY                = (GetSystemMetrics(SM_CYSCREEN) - WindowHeight) \ 2
NonClient.cbSize          = SIZEOF(NONCLIENTMETRICS)
hIcon                    = ExtractIcon GETMODULEHANDLE(""), "Shell32.dll", 294 'o
inst                      = GetModuleHandle(0)
WindowClass.style        = CS_HREDRAW | CS_VREDRAW
WindowClass.lpfnWndProc  = @WndProc
WindowClass.cbClsExtra    = 0
WindowClass.cbWndExtra    = 0
WindowClass.hInstance    = inst
WindowClass.hIcon        = hIcon 'LoadIcon(0, IDI_APPLICATION) can be used
WindowClass.hCursor      = LoadCursor(0, IDC_ARROW)
WindowClass.hbrBackground = COLOR_BTNFACE + 1
WindowClass.lpszMenuName  = null
WindowClass.lpszClassName = strptr("OXYGEN BASIC")

RegisterClass(@WindowClass)

LOGFONT LogicalFont
SystemParametersInfo(SPI_GETICONTITLELOGFONT, SIZEOF(LOGFONT), @LogicalFont, 0)
sys hFont = CreateFontIndirect(@LogicalFont)

hwnd = CreateWindowEx(WS_EX_STATICEDGE, WindowClass.lpszClassName, "EditFocus " & sizeof(sys) * 8,
                      WS_OVERLAPPED | WS_BORDER | WS_DLGFRAME | WS_CAPTION | WS_SYSMENU |
                      WS_MINIMIZEBOX | WS_CLIPSIBLINGS,
                      WindowPosX, WindowPosY, WindowWidth, WindowHeight, HWND_DESKTOP, 0, inst, 0)

hControl = CreateWindowEx(WS_EX_LEFT | WS_EX_STATICEDGE,        'Extended styles
                          "Edit",                              'Class name
                          0,                                    'Caption
                          WS_CHILD | WS_VISIBLE | WS_TABSTOP |  'Window styles
                          ES_LEFT,                              'Class styles
                          20, 100,                              'Left, top
                          150, 20,                              'Width, height
                          hWnd, EditText,                      'Handle of parent, control ID
                          inst, NULL)                          'Handle of instance, creation parameters
SendMessage(hControl, WM_SETFONT, hFont, true)
SetFocus(hControl)

hControl = CreateWindowEx(WS_EX_LEFT,                          'Extended styles
                          "Button",                            'Class name
                          "Enter",                              'Caption
                          WS_CHILD | WS_VISIBLE | WS_TABSTOP |  'Window styles
                          BS_CENTER | BS_DEFAULT | BS_NOTIFY,  'Class styles
                          180, 100,                            'Left, top
                          50, 20,                              'Width, height
                          hWnd, ButtonEnter,                    'Handle of parent, control ID
                          inst, NULL)                          'Handle of instance, creation parameters
SendMessage(hControl, WM_SETFONT, hFont, true)

ShowWindow(hwnd, SW_SHOW)
UpdateWindow(hwnd)

sys RetVal
do until RetVal = -1 'Some error occured
  RetVal = GetMessage(@TagMessage, 0, 0, 0)
  if IsDialogMessage(hWnd, @TagMessage) = 0 'Zero if message has not been processed
    TranslateMessage(@TagMessage)
    DispatchMessage(@TagMessage)
  endif
loop while RetVal 'If RetVal = 0 then WM_QUIT was received

DeleteObject(hFont)
DestroyIcon(hIcon)

end function
'_____________________________________________________________________________

WinMain()
end
'_____________________________________________________________________________
'
  •  

Zlatko Vid

Pierre
it is simple what i want :

after i type text in edit control and when i press ENTER key i want that edit control lost focus

BUT when I do that , carret is still in edit control and disable WM_KEYDOWN event ..message

i hope that you guys understand it now...yes looks simple but is not and not work...

I can try IsDialogMessage that is not problem.
  •