Edit control is not showing focus rect

Windows specific questions.
Post Reply
kcvinu
Posts: 232
Joined: Oct 07, 2015 16:44
Location: Keralam, India

Edit control is not showing focus rect

Post by kcvinu »

Hi all,
I am trying to create an Edit control with CreateWindowEx function. But my edit control is not showing the blue focus rect when i click on it. Here the window styles i am using.

Code: Select all

TbStyle = WS_CHILD Or WS_VISIBLE Or ES_LEFT Or ES_AUTOHSCROLL Or WS_TABSTOP Or WS_BORDER
TbExSTyle = 0
How to fix it ?
Edit : - I have intitialized common controls with InitCommonControlsEx function and dwIcc field is set to ICC_STANDARD_CLASSES.
Note : After creation, I have subclassing this control after I created it.
aurelVZAB
Posts: 666
Joined: Jul 02, 2008 14:55
Contact:

Re: Edit control is not showing focus rect

Post by aurelVZAB »

You can try this :

Code: Select all

case WM_CREATE 
'hEdit = CreateWindowEx(0,"EDIT","", WS_CHILD Or WS_VISIBLE Or WS_TABSTOP Or WS_CLIPCHILDREN,rx,ry,rw,rh,hWnd,null, 0,0) 
aurelVZAB
Posts: 666
Joined: Jul 02, 2008 14:55
Contact:

Re: Edit control is not showing focus rect

Post by aurelVZAB »

Note : After creation, I have subclassing this control after I created it.
hmm ..ok but subclassing it to what
subclassing need special new sub-class procedure ..do you have it ?
dodicat
Posts: 7976
Joined: Jan 10, 2006 20:30
Location: Scotland

Re: Edit control is not showing focus rect

Post by dodicat »

Surely you must double click on it to show the blue rectangle incorporating any text.
A click sets the cursor position.
Example:

Code: Select all

#include "windows.bi"
Declare Function SetWindowTheme Lib "UxTheme.dll" Alias "SetWindowTheme"(As Any Ptr,As zstring Ptr,As zstring Ptr) As Long

Function fb_Set_Font (Font As String,Size As Integer,Bold As Integer=0,Italic As Integer=0,Underline As Integer=0,StrikeThru As Integer=0) As HFONT
    Dim As HDC hDC=GetDC(HWND_DESKTOP)
    Dim As Integer CyPixels=GetDeviceCaps(hDC,LOGPIXELSY)
    ReleaseDC(HWND_DESKTOP,hDC)
    Return CreateFont(0-(Size*CyPixels)/72,0,0,0,Bold,Italic,Underline,StrikeThru,ANSI_CHARSET _
    ,OUT_TT_PRECIS,CLIP_DEFAULT_PRECIS,DEFAULT_QUALITY,FF_DONTCARE,Font)
End Function

Function wndproc(hwnd As HWND, msg As Uinteger,_
    wparam As WPARAM, lparam As LPARAM) As Integer
    
    Static As Any Ptr edit
    Select Case msg
    Case WM_CREATE
        edit= CreateWindowEx( 0, "edit", "" , WS_VISIBLE Or WS_CHILD Or WS_BORDER Or ES_MULTILINE Or WS_VSCROLL Or WS_HSCROLL,100,100,300,300,hWnd,0,0,0 )
        SetWindowTheme(hwnd," "," ")
        Dim As HFONT   font
        Dim As String temp="ABCDEFGHIJKLMNOPQRSTTUVWXYZ "
        font=fb_Set_Font("arial",15,,TRUE)
        SendMessage(edit,WM_SETFONT,Cast(WPARAM,font),0)'<<--- optional font
        setwindowtext(edit,temp)
    Case WM_DESTROY
        PostQuitMessage(0)
    End Select
    Return DefWindowProc(hwnd,msg,wparam,lparam)
End Function


Function WinMain ( Byval hInstance As HINSTANCE, _
    Byval hPrevInstance As HINSTANCE, _
    Byval szCmdLine As Zstring Ptr, _
    Byval iCmdShow As Integer ) As Integer   
    
    Dim wMsg As MSG
    Dim wcls As WNDCLASS     
    Dim main As HWND
    
    Dim As hwnd button
    
    Function = 0
    
    With wcls
        .style         = CS_HREDRAW Or CS_VREDRAW
        .lpfnWndProc   = @WndProc
        .cbClsExtra    = 0
        .cbWndExtra    = 0
        .hInstance     = hInstance
        .hIcon         = LoadIcon( NULL, IDI_APPLICATION )
        .hCursor       = LoadCursor( NULL, IDC_ARROW )
        .hbrBackground = GetStockObject( WHITE_BRUSH )
        .lpszMenuName  = NULL
        .lpszClassName = @"MyWin"
    End With
    If( RegisterClass( @wcls ) = False ) Then
        MessageBox( null, "Failed To register wcls", "Error", MB_ICONERROR )
        Exit Function
    End If
    
    main = CreateWindowEx( 0, _
    @"MyWin", _
    "Hi", _
    WS_OVERLAPPEDWINDOW Or ws_visible, _
    50, _
    50, _
    600, _
    600, _
    NULL, _
    NULL, _
    hInstance , _
    NULL )
    
    ShowWindow( main, iCmdShow )
    UpdateWindow( main )
    
    While( GetMessage( @wMsg, NULL, 0, 0 ) <> False ) 
        TranslateMessage( @wMsg )
        DispatchMessage( @wMsg )
    Wend
    
    Function = wMsg.wParam
    
End Function 

WinMain( GetModuleHandle( null ), null, Command( ), SW_NORMAL ) 
kcvinu
Posts: 232
Joined: Oct 07, 2015 16:44
Location: Keralam, India

Re: Edit control is not showing focus rect

Post by kcvinu »

@aurelVZAB,
Thank you for the reply. I have no problems in CreateWindowEx and Subclassing it. The only problem I had is, the focus rectangle is not visible when I click on the text box. I can type anything, select anything, no probs.

@ dodicat,
Thank you for the reply. Sorry, but I can't use SetWindowTheme because, I need latest windows theme on my program.
dodicat
Posts: 7976
Joined: Jan 10, 2006 20:30
Location: Scotland

Re: Edit control is not showing focus rect

Post by dodicat »

You don't need SetWindowTheme, you can comment it out.
Post Reply