• Welcome to PlanetSquires Forums.
 

Intellisense-Listbox not drawn correctly

Started by jermy, April 10, 2021, 02:39:46 PM

Previous topic - Next topic

jermy

Dear people,

The intention is that if you hit a dot on your keyboard that the list box will appear
Why is the listbox only half displayed ?.


#define UNICODE
#INCLUDE ONCE "Afx/CWindow.inc"
#INCLUDE ONCE "Afx/AfxRichEdit.inc"
USING Afx

#define IDC_RICHEDIT 1001
#define IDC_LISTBOX   1002

DECLARE FUNCTION WinMain (BYVAL hInstance AS HINSTANCE, _
                          BYVAL hPrevInstance AS HINSTANCE, _
                          BYVAL szCmdLine AS ZSTRING PTR, _
                          BYVAL nCmdShow AS LONG) AS LONG

   END WinMain(GetModuleHandleW(NULL), NULL, COMMAND(), SW_NORMAL)

' // Forward declaration
DECLARE FUNCTION WndProc (BYVAL hwnd AS HWND, BYVAL uMsg AS UINT, BYVAL wParam AS WPARAM, BYVAL lParam AS LPARAM) AS LRESULT

' ========================================================================================
' Main
' ========================================================================================
FUNCTION WinMain (BYVAL hInstance AS HINSTANCE, _
                  BYVAL hPrevInstance AS HINSTANCE, _
                  BYVAL szCmdLine AS ZSTRING PTR, _
                  BYVAL nCmdShow AS LONG) AS LONG

   ' // Set process DPI aware
   AfxSetProcessDPIAware

   DIM pWindow AS CWindow
   pWindow.Create( NULL, "CWindow with a Rich Edit control", @WndProc )
   pWindow.SetClientSize(600, 420)
   pWindow.Center

   ' // Add a rich edit control without coordinates (it will be resized in WM_SIZE)
   DIM hRichEdit AS HWND = pWindow.AddControl( "RichEdit", , IDC_RICHEDIT, "RichEdit box" )
 
      ' // Enable EN_MSGFILTER notifications for keyboard events.
   RichEdit_SetEventMask( hRichEdit, ENM_KEYEVENTS or ENM_MOUSEEVENTS )
   SetFocus hRichEdit

Dim as long  dwStyle     =  WS_VSCROLL  'WS_CHILD OR WS_VISIBLE OR WS_HSCROLL OR WS_VSCROLL OR WS_BORDER OR WS_TABSTOP OR LBS_STANDARD OR LBS_HASSTRINGS OR LBS_SORT OR LBS_NOTIFY
Dim as long  dwExStyle = 0 'WS_EX_CLIENTEDGE 'or WS_EX_TOPMOST
   ' // Adds a listbox
   DIM hListBox AS HWND = pWindow.AddControl("ListBox", Null, IDC_LISTBOX, "", 400, 8, 100, 40, dwStyle, dwExStyle, 0, Null, &HFFFFFFFF, Null)

   ' // Fill the list box
   DIM wszText AS WSTRING * 260
   FOR i AS LONG = 1 TO 5
      wszText = "Item " & RIGHT("00" & WSTR(i), 2)
      ListBox_AddString(hListBox, @wszText)
   NEXT i
   
   ' // Select the first item
   ListBox_SetCursel(hListBox, 0)
   updateWindow hListBox
   ' // Dispatch Windows messages
   FUNCTION = pWindow.DoEvents(nCmdShow)

END FUNCTION
' ========================================================================================

' ========================================================================================
' Main window callback procedure
' ========================================================================================
FUNCTION WndProc (BYVAL hwnd AS HWND, BYVAL uMsg AS UINT, BYVAL wParam AS WPARAM, BYVAL lParam AS LPARAM) AS LRESULT

Static pWindow as Cwindow ptr
dim as LPNMHDR pnm
  dim as MSGFILTER ptr pmf

   SELECT CASE uMsg
      CASE WM_CREATE
                 pWindow = AfxCWindowPtr(lParam)
      CASE WM_COMMAND
         SELECT CASE GET_WM_COMMAND_ID(wParam, lParam)
            ' // If ESC key pressed, close the application sending an WM_CLOSE message
            CASE IDCANCEL
               IF GET_WM_COMMAND_CMD(wParam, lParam) = BN_CLICKED THEN
                  SendMessageW hwnd, WM_CLOSE, 0, 0
                  EXIT FUNCTION
               END IF
         END SELECT

        Case WM_NOTIFY
               pnm = cast(LPNMHDR, lParam)
            if pnm->hwndFrom = GetDlgItem(hwnd, IDC_RICHEDIT) then
                select case pnm->code
                    case EN_MSGFILTER
                           pmf = cast(MSGFILTER ptr, pnm)
                        select case   pmf->msg
                              Case WM_KEYDOWN
                                  if pmf->wParam = 190 then         ' 190 = dot              ' GetPositionFromCharIndex
         
         ' get the cursor position in the rich edit box
         Dim as DWORD CursorPos
         SendMessage( pnm->hwndFrom, EM_GETSEL, NULL, cast(LPARAM, @CursorPos) )
       
         ' get the x and y coordinates from the cursor
         Dim pt As point
          SendMessage( pnm->hwndFrom, EM_POSFROMCHAR, cast(WPARAM,@pt), CursorPos )
         ' show the listbox
          pWindow->SetWindowPos GetDlgItem(hwnd, IDC_LISTBOX), Null, pWindow->UnScaleX(pt.x) + 15, pWindow->UnScaleY(pt.y) + 10, 100, 40, SWP_SHOWWINDOW

          updatewindow   pnm->hwndFrom
          SetFocus GetDlgItem(hwnd, IDC_LISTBOX)
                                 end if

                        end select
                End Select   
            end if       
 

      CASE WM_SIZE
         ' // If the window isn't minimized, resize it
         IF wParam <> SIZE_MINIMIZED THEN
            ' // Resize the controls
            DIM pWindow AS CWindow PTR = AfxCWindowPtr(hwnd)
            IF pWindow THEN
               pWindow->MoveWindow GetDlgItem(hwnd, IDC_RICHEDIT), 10, 10, pWindow->ClientWidth - 220, pWindow->ClientHeight - 220, CTRUE
            END IF
         END IF

    CASE WM_DESTROY
         ' // End the application by sending an WM_QUIT message
         PostQuitMessage(0)
         EXIT FUNCTION

   END SELECT

   ' // Default processing of Windows messages
   FUNCTION = DefWindowProcW(hWnd, uMsg, wParam, lParam)

END FUNCTION
' ========================================================================================



I've already tried everything that came to my mind, anyone else have an idea?

José Roca

> Why is the listbox only half displayed ?.

You only have made it 40 pixels tall. Make it bigger.

jermy

I tried that, then the first item is not visible.

José Roca

It is being overwritten by the RichEdit control. Change the position of the ListBox.

jermy

#4
Quote from: José Roca on April 10, 2021, 03:31:10 PM
It is being overwritten by the RichEdit control. Change the position of the ListBox.

yes that's it, thanks.

How can I be so blind? It must be because of corona.

          pWindow->SetWindowPos GetDlgItem(hwnd, IDC_LISTBOX), Null, pWindow->UnScaleX(pt.x) + 15, pWindow->UnScaleY(pt.y) + 27, 100, 80, SWP_SHOWWINDOW