• Welcome to PlanetSquires Forums.
 
Main Menu

Recent posts

#21
hi all, hello paul, can you please fix this Notepad.bas example, doesn't work here
thanks, frank

Examples \Visual_Designer_Projects\Notepad\Notepad.bas

"afxRichEdit.inc"
error in line 1165

' // Loads the resource
   hResInfo = FindResourceW(hInstance, wszResourceName, RT_RCDATA) 'RT_RCDATA
   IF hResInfo = NULL THEN EXIT FUNCTION

warning 3(2) : passing diffeerent pointer types, at parameter 3 of FINDRESOURCEW()
#22
Quote from: Paul Squires on March 30, 2024, 01:03:40 PMHere is an ownerdrawn listbox with double buffered graphics and alternate line coloring.

Thank you, much appreciated. I was after changing the color of the text for each line, not so much the background but I think I can alter your code to suit my requirements. Again, thank you.
#23
Here is an ownerdrawn listbox with double buffered graphics and alternate line coloring.

' ########################################################################################
' Microsoft Windows
' File: CW_ScrollWindow.fbtpl
' Contents: Scrollable window
' Compiler: Free Basic
' Copyright (c) 2016 José Roca. Freeware. Use at your own risk.
' THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER
' EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED WARRANTIES OF
' MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR PURPOSE.
' ########################################################################################

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

#define IDC_LISTBOX 1001

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
   DIM hwndMain AS HWND = pWindow.Create(NULL, "Scrollable window", @WndProc)
   pWindow.ClassStyle = CS_DBLCLKS   ' // Change the window style to avoid flicker
   ' // Set a client size big enough to display all the controls
   pWindow.SetClientSize(320, 335)

   ' // Add a listbox
   DIM hListBox AS HWND
   dim as dword dwStyle = WS_VISIBLE OR WS_HSCROLL OR WS_VSCROLL OR WS_BORDER OR WS_TABSTOP OR LBS_HASSTRINGS OR LBS_NOTIFY OR LBS_OWNERDRAWFIXED
   dim as dword dwExStyle = WS_EX_CLIENTEDGE

   hListBox = pWindow.AddControl("ListBox", , IDC_LISTBOX, "", 0, 0, 0, 0, dwStyle, dwExStyle)
   pWindow.SetWindowPos hListBox, NULL, 8, 8, 300, 280, SWP_NOZORDER

   ' // Fill the list box
   DIM i AS LONG, wszText AS WSTRING * 260
   FOR i = 1 TO 50
      wszText = "Item " & RIGHT("00" & STR(i), 2)
      ListBox_AddString(hListBox, @wszText)
   NEXT
   ' // Select the first item
   ListBox_SetCursel(hListBox, 0)

   ' // Add a cancel button
   pWindow.AddControl("Button", , IDCANCEL, "&Cancel", 233, 298, 75, 23)

   ' // Create an instance of the CScrollWindow class and attach the main window to it
   DIM pScrollWindow AS CScrollWindow PTR = NEW CScrollWindow(hwndMain)
   ' // Store the pointer in the class of the parent window for later deletion
   pWindow.ScrollWindowPtr = pScrollWindow
   ' // Shrink the client size
   pWindow.SetClientSize(250, 260)
   ' // Center the window
   pWindow.Center

   

   ' // Dispatch windows messages
   FUNCTION = pWindow.DoEvents(nCmdShow)

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

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

   SELECT CASE uMsg

      case WM_MEASUREITEM
         dim lpmis As MEASUREITEMSTRUCT Ptr = cast( MEASUREITEMSTRUCT Ptr, lParam )
         if lpmis andalso (wParam = IDC_LISTBOX) then
             lpmis->itemHeight = AfxScaleY(20)
         end if
         return true

      case WM_DRAWITEM
         Dim memDC as HDC      ' Double buffering
         Dim hbit As HBITMAP   ' Double buffering
         Dim As RECT rc
         Dim wszText As WString * MAX_PATH

         dim lpdis As DRAWITEMSTRUCT Ptr = cast( DRAWITEMSTRUCT Ptr, lParam )
         if lpdis = 0 then exit function

         if ( lpdis->itemAction = ODA_DRAWENTIRE ) orelse _
            ( lpdis->itemAction = ODA_SELECT ) orelse _
            ( lpdis->itemAction = ODA_FOCUS ) then
             
            If lpdis->itemID = -1 Then return true
            if lpdis->itemAction = ODA_FOCUS then return true

            dim as COLORREF clrBack, clrFore
            dim as HBRUSH hBrushBack
             
            rc = lpdis->rcItem
            dim as long nWidth  = rc.right-rc.left
            dim as long nHeight = rc.bottom-rc.top

            SaveDC(lpdis->hDC)

            memDC = CreateCompatibleDC( lpdis->hDC )
            hbit  = CreateCompatibleBitmap( lpdis->hDC, nWidth, nHeight )
            If hbit Then hbit = SelectObject( memDC, hbit )

            dim as HFONT _hFont = AfxGetWindowFont( lpdis->hwndItem )
            SelectObject( memDC, _hFont )

            ' CLEAR BACKGROUND
            If (lpdis->itemState And ODS_SELECTED) Then     
               clrBack = BGR(0,0,255)       ' blue
               clrFore = BGR(255,255,255)   ' white
               hBrushBack = CreateSolidBrush(clrBack)
            else
               if (lpdis->itemID mod 2) then
                  clrBack = BGR(255,255,204)   ' light yellow
               else
                  clrBack = BGR(255,255,255)   ' white
               end if
               clrFore = BGR(0,0,0)         ' black
               hBrushBack = CreateSolidBrush(clrBack)
            end if
                     
            ' Paint the entire background
            ' Create our rect that works with the entire line
            SetRect(@rc, 0, 0, nWidth, nHeight)
            FillRect( memDC, @rc, hBrushBack )

            ' Prepare and paint the text coloring
            SetBkColor( memDC, clrBack )   
            SetTextColor( memDC, clrFore )

            ' pad the drawing rectangle to allow left and right margins
            dim as RECT rcText = rc
            rcText.left = rcText.left + AfxScaleX(4)
            rcText.right = rcText.right - AfxScaleX(4)

            dim as long lFormat = DT_SINGLELINE or DT_NOPREFIX
            wszText = AfxGetListBoxText( lpdis->hwndItem, lpdis->itemID )
            DrawText( memDC, wszText, -1, Cast(lpRect, @rcText), lFormat )

            ' Draw a focus rectangle around the item
            If (lpdis->itemState And ODS_SELECTED) Then     
               DrawFocusRect( lpdis->hDC, @lpdis->rcItem )
            end if
                     
            BitBlt lpdis->hDC, lpdis->rcItem.left, lpdis->rcItem.top, _
                   nWidth, nHeight, memDC, 0, 0, SRCCOPY

            ' Cleanup
            If hbit  Then DeleteObject SelectObject(memDC, hbit)
            If memDC Then DeleteDC memDC
            RestoreDC(lpdis->hDC, -1)
            DeleteObject(hBrushBack )
           
            return true
        end if
       
           
      CASE WM_COMMAND
         SELECT CASE GET_WM_COMMAND_ID(wParam, lParam)
            CASE IDCANCEL
               ' // If ESC key pressed, close the application by sending an WM_CLOSE message
               IF GET_WM_COMMAND_CMD(wParam, lParam) = BN_CLICKED THEN
                  SendMessageW hwnd, WM_CLOSE, 0, 0
                  EXIT FUNCTION
               END IF
         CASE IDC_LISTBOX
            SELECT CASE GET_WM_COMMAND_CMD(wParam, lParam)
               CASE LBN_DBLCLK
                  ' // Get the handle of the Listbox
                  DIM hListBox AS HWND = GetDlgItem(hwnd, IDC_LISTBOX)
                  ' // Get the current selection
                  DIM curSel AS LONG = ListBox_GetCursel(hListBox)
                  ' // Get the length of the ListBox item text
                  DIM nLen AS LONG = ListBox_GetTextLen(hListBox, curSel)
                  ' // Allocate memory for the buffer
                  DIM pwszText AS WSTRING PTR = CAllocate(nLen + 1, 2)
                  ' // Get the text and display it
                  ListBox_GetText(hListBox, curSel, pwszText)
                  MessageBoxW(hwnd, pwszText, "ListBox test", MB_OK)
                  ' // Deallocate the memory used by the buffer
                  DeAllocate pwszText
                  pwszText = NULL

                  ' *** Alternate way using CWSTR ***
'                  DIM cwsText AS CWSTR = ListBox_GetTextLen(hListBox, curSel) + 1
'                  ListBox_GetText(hListBox, curSel, *cwsText)
'                  MessageBoxW(hwnd, cwsText, "ListBox test", MB_OK)

                  EXIT FUNCTION
            END SELECT

         END SELECT

      CASE WM_SIZE
         DIM pScrollWindow AS CScrollWindow PTR = AfxScrollWindowPtr(hwnd)
         IF pScrollWindow THEN pScrollWindow->OnSize(wParam, lParam)
         EXIT FUNCTION

      CASE WM_VSCROLL
         DIM pScrollWindow AS CScrollWindow PTR = AfxScrollWindowPtr(hwnd)
         IF pScrollWindow THEN pScrollWindow->OnVScroll(wParam, lParam)
         EXIT FUNCTION

      CASE WM_HSCROLL
         DIM pScrollWindow AS CScrollWindow PTR = AfxScrollWindowPtr(hwnd)
         IF pScrollWindow THEN pScrollWindow->OnHScroll(wParam, lParam)
         EXIT FUNCTION

      CASE WM_DESTROY
         ' // End the application
         PostQuitMessage(0)
         EXIT FUNCTION

   END SELECT

   ' // Pass unprocessed messages to DefWindowProc
   FUNCTION = DefWindowProcW(hWnd, uMsg, wParam, lParam)

END FUNCTION
' ========================================================================================
#24
In the scrollable text window template, how does one go about to set each each line to different colors?

' ########################################################################################
' Microsoft Windows
' File: CW_ScrollWindow.fbtpl
' Contents: Scrollable window
' Compiler: Free Basic
' Copyright (c) 2016 José Roca. Freeware. Use at your own risk.
' THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER
' EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED WARRANTIES OF
' MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR PURPOSE.
' ########################################################################################

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

#define IDC_LISTBOX 1001

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
   DIM hwndMain AS HWND = pWindow.Create(NULL, "Scrollable window", @WndProc)
   pWindow.ClassStyle = CS_DBLCLKS   ' // Change the window style to avoid flicker
   ' // Set a client size big enough to display all the controls
   pWindow.SetClientSize(320, 335)

   ' // Add a listbox
   DIM hListBox AS HWND
   hListBox = pWindow.AddControl("ListBox", , IDC_LISTBOX)
   pWindow.SetWindowPos hListBox, NULL, 8, 8, 300, 280, SWP_NOZORDER

   ' // Fill the list box
   DIM i AS LONG, wszText AS WSTRING * 260
   FOR i = 1 TO 50
      wszText = "Item " & RIGHT("00" & STR(i), 2)
      ListBox_AddString(hListBox, @wszText)
   NEXT
   ' // Select the first item
   ListBox_SetCursel(hListBox, 0)

   ' // Add a cancel button
   pWindow.AddControl("Button", , IDCANCEL, "&Cancel", 233, 298, 75, 23)

   ' // Create an instance of the CScrollWindow class and attach the main window to it
   DIM pScrollWindow AS CScrollWindow PTR = NEW CScrollWindow(hwndMain)
   ' // Store the pointer in the class of the parent window for later deletion
   pWindow.ScrollWindowPtr = pScrollWindow
   ' // Shrink the client size
   pWindow.SetClientSize(250, 260)
   ' // Center the window
   pWindow.Center

   

   ' // Dispatch windows messages
   FUNCTION = pWindow.DoEvents(nCmdShow)

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

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

   SELECT CASE uMsg

      CASE WM_COMMAND
         SELECT CASE GET_WM_COMMAND_ID(wParam, lParam)
            CASE IDCANCEL
               ' // If ESC key pressed, close the application by sending an WM_CLOSE message
               IF GET_WM_COMMAND_CMD(wParam, lParam) = BN_CLICKED THEN
                  SendMessageW hwnd, WM_CLOSE, 0, 0
                  EXIT FUNCTION
               END IF
         CASE IDC_LISTBOX
            SELECT CASE GET_WM_COMMAND_CMD(wParam, lParam)
               CASE LBN_DBLCLK
                  ' // Get the handle of the Listbox
                  DIM hListBox AS HWND = GetDlgItem(hwnd, IDC_LISTBOX)
                  ' // Get the current selection
                  DIM curSel AS LONG = ListBox_GetCursel(hListBox)
                  ' // Get the length of the ListBox item text
                  DIM nLen AS LONG = ListBox_GetTextLen(hListBox, curSel)
                  ' // Allocate memory for the buffer
                  DIM pwszText AS WSTRING PTR = CAllocate(nLen + 1, 2)
                  ' // Get the text and display it
                  ListBox_GetText(hListBox, curSel, pwszText)
                  MessageBoxW(hwnd, pwszText, "ListBox test", MB_OK)
                  ' // Deallocate the memory used by the buffer
                  DeAllocate pwszText
                  pwszText = NULL

                  ' *** Alternate way using CWSTR ***
'                  DIM cwsText AS CWSTR = ListBox_GetTextLen(hListBox, curSel) + 1
'                  ListBox_GetText(hListBox, curSel, *cwsText)
'                  MessageBoxW(hwnd, cwsText, "ListBox test", MB_OK)

                  EXIT FUNCTION
            END SELECT

         END SELECT

      CASE WM_SIZE
         DIM pScrollWindow AS CScrollWindow PTR = AfxScrollWindowPtr(hwnd)
         IF pScrollWindow THEN pScrollWindow->OnSize(wParam, lParam)
         EXIT FUNCTION

      CASE WM_VSCROLL
         DIM pScrollWindow AS CScrollWindow PTR = AfxScrollWindowPtr(hwnd)
         IF pScrollWindow THEN pScrollWindow->OnVScroll(wParam, lParam)
         EXIT FUNCTION

      CASE WM_HSCROLL
         DIM pScrollWindow AS CScrollWindow PTR = AfxScrollWindowPtr(hwnd)
         IF pScrollWindow THEN pScrollWindow->OnHScroll(wParam, lParam)
         EXIT FUNCTION

      CASE WM_DESTROY
         ' // End the application
         PostQuitMessage(0)
         EXIT FUNCTION

   END SELECT

   ' // Pass unprocessed messages to DefWindowProc
   FUNCTION = DefWindowProcW(hWnd, uMsg, wParam, lParam)

END FUNCTION
' ========================================================================================
#25
Thank you for the Tip good to know that!

I have checked a Lot of example already very good Work Jose and Paul..

Only the "notepad.bas" (visual Designer Projects) its Not running...

AfxRichEdit.inc  Line 1166 Here Error passing different Pointer types...

Thx, Frank
#26
WinFBX - Windows Framework for FreeBASIC / Re: Listview Demo help
Last post by José Roca - March 19, 2024, 11:58:00 AM
In the examples folder are the examples that use resources. The templates are available directly from the editor clicking the button with an arrow in the top ledt corner.

#27
Hi jose...

I would have liked to do that too, but I couldn't find a current Listview example (using Afx) other than the treeview example in the examples sample projects of WinFBE Editor

I have downloaded WinFBE suite and your winfbx master files

Thanks for your Update

Regards Frank
#28
WinFBX - Windows Framework for FreeBASIC / Re: Listview Demo help
Last post by José Roca - March 19, 2024, 05:18:33 AM
Hi Frank,

Please use updated code, not code posted in the forum 8 or 9 years ago when I was writing the Afx framework and doing changes everyday.

If you had used the template available from the WinFBE editor, you wouldn't have had that problem.

This is the updated ListView example available from WinFBE:

' ########################################################################################
' Microsoft Windows
' File: CW_COMMCTRL_ListView.fbtpl
' Contents: CWindow with a ListView
' Compiler: Free Basic
' Copyright (c) 2016 José Roca. Freeware. Use at your own risk.
' THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER
' EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED WARRANTIES OF
' MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR PURPOSE.
' ########################################################################################

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

#define IDC_LISTVIEW 1001

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

   ' // Create the main window
   DIM pWindow AS CWindow
   pWindow.Create(NULL, "CWindow with a ListView", @WndProc)
   pWindow.ClassStyle = CS_DBLCLKS   ' // Change the window style to avoid flicker
   pWindow.SetClientSize(565, 320)
   pWindow.Center

   ' // Adds a listview
   DIM hListView AS HWND
   hListView = pWindow.AddControl("ListView", , IDC_LISTVIEW)

   ' // Add some extended styles
   DIM dwExStyle AS DWORD
   dwExStyle = ListView_GetExtendedListViewStyle(hListView)
   dwExStyle = dwExStyle OR LVS_EX_FULLROWSELECT OR LVS_EX_GRIDLINES
   ListView_SetExtendedListViewStyle(hListView, dwExStyle)

   ' // Add the header's column names
   DIM lvc AS LVCOLUMNW, wszText AS WSTRING * 260
   lvc.mask = LVCF_FMT OR LVCF_WIDTH OR LVCF_TEXT OR LVCF_SUBITEM
   FOR i AS LONG = 0 TO 4
      wszText = "Column " & STR(i)
      lvc.pszText = @wszText
      lvc.cx = pWindow.ScaleX(110)
      lvc.iSubItem = i
      ListView_InsertColumn(hListView, i, @lvc)
   NEXT

   ' // Populate the ListView with some data
   DIM lvi AS LVITEMW
   lvi.mask = LVIF_TEXT
   FOR i AS LONG = 0 to 29
      lvi.iItem = i
      lvi.iSubItem = 0
      wszText = "Column 0 Row" + WSTR(i)
      lvi.pszText = @wszText
      ListView_InsertItem(hListView, @lvi)
      FOR x AS LONG = 1 TO 4
         wszText = "Column " & WSTR(x) & " Row" + WSTR(i)
         ListView_SetItemText(hListView, i, x, @wszText)
      NEXT
   NEXT

   ' // Select the fist item (ListView items are zero based)
   ListView_SelectItem(hListView, 0)
   ' // Set the focus in the ListView
   SetFocus hListView

   

   ' // Dispatch Windows messages
   FUNCTION = pWindow.DoEvents(nCmdShow)

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

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

   SELECT CASE uMsg

      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_SIZE
         ' // Resize the ListView control and its header
         IF wParam <> SIZE_MINIMIZED THEN
            ' // Retrieve the handle of the ListView control
            DIM hListView AS HWND = GetDlgItem(hwnd, IDC_LISTVIEW)
            ' // Retrieve a pointer to the CWindow class
            DIM pWindow AS CWindow PTR = AfxCWindowPtr(hwnd)
            ' // Move the ListView control
            IF pWindow THEN pWindow->MoveWindow hListView, 5, 5, pWindow->ClientWidth - 10, pWindow->ClientHeight - 10, CTRUE
         END IF

    CASE WM_DESTROY
          ' // End the application
         PostQuitMessage(0)
         EXIT FUNCTION

   END SELECT

   ' // Pass unprocessed messages to DefWindowProc
   FUNCTION = DefWindowProcW(hWnd, uMsg, wParam, lParam)

END FUNCTION
' ========================================================================================
#29
How about this....

            '----------------- problem zone ---------------------------- //
            pWindow = AfxCWindowPtr(hwnd)
             if pWindow then
                pWindow->MoveWindow hListView, 5, 5, pWindow->ClientWidth - 10, pWindow->ClientHeight - 10, TRUE
             end if  
            '----------------- problem zone ---------------------------- //

QuotePS where U can find Infos about Control wrapper functions for Afx?

Check out all of the *.inc files in the \inc\Afx folder. Specifically, for ListView, look at AfxCtl.inc.
#30
I have Made Yesterday this example too you can load and save a File  did AS Basis an example from this Board some years ago (only save Dialog worked at that time)

' open + save dialog, afx demo test, frank bruebach, 18-03-2024
'
#define UNICODE
#define _WIN32_WINNT &h0602
#INCLUDE ONCE "Afx/CWindow.inc"
#INCLUDE ONCE "win/shobjidl.bi"
USING Afx

CONST IDC_OFD = 1001
CONST IDC_SFD = 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 declarations
DECLARE FUNCTION WndProc (BYVAL hwnd AS HWND, BYVAL uMsg AS UINT, BYVAL wParam AS WPARAM, BYVAL lParam AS LPARAM) AS LRESULT
DECLARE FUNCTION AfxIFileSaveDialog (BYVAL hwndOwner AS HWND, BYVAL pwszFileName AS WSTRING PTR, _
   BYVAL pwszDefExt AS WSTRING PTR, BYVAL sigdnName AS SIGDN = SIGDN_FILESYSPATH) AS WSTRING PTR

' ========================================================================================
' 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

   ' // Initialize the COM library
   CoInitialize(NULL)

   ' // Create the main window
   DIM pWindow AS CWindow
   pWindow.Create(NULL, "File Open+SaveDialog example", @WndProc)
   pWindow.SetClientSize(500, 320)
   pWindow.Center

   ' // Add a button
   pWindow.AddControl("Button", , IDC_SFD, "File &Save Dialog", 350, 250, 110, 23)

   pWindow.AddControl("Button", , IDC_OFD, "File &Open Dialog", 150, 250, 110, 23)
   ' // Dispatch messages
   FUNCTION = pWindow.DoEvents(nCmdShow)

   ' // Uninitialize the COM library
   CoUninitialize

END FUNCTION
' ========================================================================================
'FUNCTION AfxOpenFileDialog ( _
'BYVAL hwndOwner AS HWND, _
'BYREF wszTitle AS WSTRING, _
'BYREF wszFile AS WSTRING, _
'BYREF wszInitialDir AS WSTRING, _
'BYREF wszFilter AS WSTRING, _
'BYREF wszDefExt AS WSTRING, _
'BYVAL pdwFlags AS DWORD PTR = NULL, _
'BYVAL pdwBufLen AS DWORD PTR = NULL ) AS CWSTR


FUNCTION AfxIFileOpenDialog (BYVAL hwndOwner AS HWND, BYVAL pwszFileName AS WSTRING PTR, _
   BYVAL pwszDefExt AS WSTRING PTR, BYVAL sigdnName AS SIGDN = SIGDN_FILESYSPATH) AS WSTRING PTR

   ' // Create an instance of the IFileSaveDialog interface
   DIM hr AS LONG
   DIM psfd AS IFileOpenDialog PTR
   hr = CoCreateInstance(@CLSID_FileOpenDialog, NULL, CLSCTX_INPROC_SERVER, @IID_IFileOpenDialog, @psfd)
   IF psfd = NULL THEN RETURN NULL

   ' // Set the file types
   DIM rgFileTypes(1 TO 3) AS COMDLG_FILTERSPEC
   rgFileTypes(1).pszName = @WSTR("FB code files")
   rgFileTypes(2).pszName = @WSTR("Text files")
   rgFileTypes(3).pszName = @WSTR("All files")
   rgFileTypes(1).pszSpec = @WSTR("*.bas;*.inc;*.bi")
   rgFileTypes(2).pszSpec = @WSTR("*.txt")
   rgFileTypes(3).pszSpec = @WSTR("*.*")
   psfd->lpVtbl->SetFileTypes(psfd, 3, @rgFileTypes(1))

   ' // Set the title of the dialog
   hr = psfd->lpVtbl->SetTitle(psfd, "File Open Dialog")
   ' // Set the file name
   hr = psfd->lpVtbl->SetFileName(psfd, pwszFileName)
   ' // Set the extension
   hr = psfd->lpVtbl->SetDefaultExtension(psfd, pwszDefExt)
   ' // Display the dialog
   hr = psfd->lpVtbl->Show(psfd, hwndOwner)

 DIM pFolder AS IShellItem PTR
   dim as CWSTR wszFolder = "C:\myfolder\test"   ' <-- obviously change this to a valid folder
   SHCreateItemFromParsingName (wszFolder, NULL, @IID_IShellItem, @pFolder)
   IF pFolder THEN
      psfd->lpVtbl->SetDefaultFolder(psfd, pFolder)
      pFolder->lpVtbl->Release(pFolder)
   END IF

   ' // Get the result
   DIM pItem AS IShellItem PTR
   DIM pwszName AS WSTRING PTR
   IF SUCCEEDED(hr) THEN
      hr = psfd->lpVtbl->GetResult(psfd, @pItem)
      IF SUCCEEDED(hr) THEN
         hr = pItem->lpVtbl->GetDisplayName(pItem, sigdnName, @pwszName)
         FUNCTION = pwszName
      END IF
   END IF
' // Display the dialog
   hr = psfd->lpVtbl->Show(psfd, hwndOwner)

   ' // Cleanup
   IF pItem THEN pItem->lpVtbl->Release(pItem)
   IF psfd THEN psfd->lpVtbl->Release(psfd)

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
   SELECT CASE uMsg
      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
            CASE IDC_SFD
               IF GET_WM_COMMAND_CMD(wParam, lParam) = BN_CLICKED THEN
                  ' // Display the Save File Dialog
                  DIM pwszName AS WSTRING PTR = AfxIFileSaveDialog(hwnd, "test", "bas")
                  ' // Display the selected name
                  IF pwszName THEN
                     MessageBoxW(hwnd, *pwszName, "IFileSaveDialog", MB_OK)
                     CoTaskMemFree(pwszName)
                  END IF
                  EXIT FUNCTION
               END IF
               '------------------------------------------------------------------ //
            CASE IDC_OFD
               IF GET_WM_COMMAND_CMD(wParam, lParam) = BN_CLICKED THEN
                  ' // Display the Open File Dialog
                  '------------------ problem zone ---------------------------------- //
                  DIM pwszName AS WSTRING PTR = AfxIFileOpenDialog(hwnd, "test", "bas")
                  ' // Display the selected name
                  IF pwszName THEN
                     MessageBoxW(hwnd, *pwszName, "IFileOpenDialog", MB_OK)
                     CoTaskMemFree(pwszName)
                  END IF
                  EXIT FUNCTION
               END IF    
         END SELECT

        CASE WM_DESTROY
         ' // Quit the application
         PostQuitMessage(0)
         EXIT FUNCTION
   END SELECT

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

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

' ========================================================================================
' Displays the File Save Dialog
' The returned pointer must be freed with CoTaskMemFree
' ========================================================================================
FUNCTION AfxIFileSaveDialog (BYVAL hwndOwner AS HWND, BYVAL pwszFileName AS WSTRING PTR, _
   BYVAL pwszDefExt AS WSTRING PTR, BYVAL sigdnName AS SIGDN = SIGDN_FILESYSPATH) AS WSTRING PTR

   ' // Create an instance of the IFileSaveDialog interface
   DIM hr AS LONG
   DIM psfd AS IFileSaveDialog PTR
   hr = CoCreateInstance(@CLSID_FileSaveDialog, NULL, CLSCTX_INPROC_SERVER, @IID_IFileSaveDialog, @psfd)
   IF psfd = NULL THEN RETURN NULL

   ' // Set the file types
   DIM rgFileTypes(1 TO 3) AS COMDLG_FILTERSPEC
   rgFileTypes(1).pszName = @WSTR("FB code files")
   rgFileTypes(2).pszName = @WSTR("Text files")
   rgFileTypes(3).pszName = @WSTR("All files")
   rgFileTypes(1).pszSpec = @WSTR("*.bas;*.inc;*.bi")
   rgFileTypes(2).pszSpec = @WSTR("*.txt")
   rgFileTypes(3).pszSpec = @WSTR("*.*")
   psfd->lpVtbl->SetFileTypes(psfd, 3, @rgFileTypes(1))

   ' // Set the title of the dialog
   hr = psfd->lpVtbl->SetTitle(psfd, "File Save Dialog")
   ' // Set the file name
   hr = psfd->lpVtbl->SetFileName(psfd, pwszFileName)
   ' // Set the extension
   hr = psfd->lpVtbl->SetDefaultExtension(psfd, pwszDefExt)
   ' // Display the dialog
   hr = psfd->lpVtbl->Show(psfd, hwndOwner)

 DIM pFolder AS IShellItem PTR
   dim as CWSTR wszFolder = "C:\myfolder\test"   ' <-- obviously change this to a valid folder
   SHCreateItemFromParsingName (wszFolder, NULL, @IID_IShellItem, @pFolder)
   IF pFolder THEN
      psfd->lpVtbl->SetDefaultFolder(psfd, pFolder)
      pFolder->lpVtbl->Release(pFolder)
   END IF

   ' // Get the result
   DIM pItem AS IShellItem PTR
   DIM pwszName AS WSTRING PTR
   IF SUCCEEDED(hr) THEN
      hr = psfd->lpVtbl->GetResult(psfd, @pItem)
      IF SUCCEEDED(hr) THEN
         hr = pItem->lpVtbl->GetDisplayName(pItem, sigdnName, @pwszName)
         FUNCTION = pwszName
      END IF
   END IF
' // Display the dialog
   hr = psfd->lpVtbl->Show(psfd, hwndOwner)

   ' // Cleanup
   IF pItem THEN pItem->lpVtbl->Release(pItem)
   IF psfd THEN psfd->lpVtbl->Release(psfd)

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

[,/Code]