Announcement

Collapse
No announcement yet.

Help with 2 SDK controls

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Help with 2 SDK controls

    I have recently posted some code here on the PB forum that uses PBCC to display some output. I feel like these demos would be better served with a GUI.

    So as I started thinking about what I wanted to do... I want users of both PBWIN and PBCC to be able to compile and use the demo code...so SDK it is. My initial needs for controls are VERY simple. I need the main window, a status bar, list view, edit control and a button. I have working code for main window, and status bar. I’ve found several SDK code examples for a list view. But I’m confused about the edit control and the button... Online documentation from MS indicates using CreateWindow for both of these. I could use some help understanding how to properly add an edit control and “Search” button to my window.

    My overall app design is simple... Input what you are searching for in the edit control and click “Search” and the results appear in the listview... Click red X in corner to exit app. Super simple design.

    I’m really inexperienced creating GUI applications, so I could use some help understanding. I appreciate any help that can be provided.

    Thanks!!
    Michael

  • #2
    An small example using my headers and my CWindow class:

    Code:
    #COMPILE EXE
    #DIM ALL
    #CONSOLE OFF ' // remove it to compile with PBWIN
    %UNICODE = 1
    
    #INCLUDE ONCE "CWindow.inc" ' // CWindow class
    #INCLUDE ONCE "ListViewCtrl.inc" ' // ListView control wrapper functions
    
    %IDC_STATUSBAR = 1001
    %IDC_BUTON = 1002
    %IDC_EDIT = 1003
    %IDC_LISTVIEW = 1004
    
    ' ========================================================================================
    ' Main
    ' ========================================================================================
    FUNCTION WinMain (BYVAL hInstance AS DWORD, BYVAL hPrevInstance AS DWORD, BYVAL lpszCmdLine AS WSTRINGZ PTR, BYVAL nCmdShow AS LONG) AS LONG
    
    ' // Set process DPI aware
    AfxSetProcessDPIAware
    
    ' // Create an instance of the class
    LOCAL pWindow AS IWindow
    pWindow = CLASS "CWindow"
    IF ISNOTHING(pWindow) THEN EXIT FUNCTION
    
    ' // Create the main window
    pWindow.CreateWindow(%NULL, "PBCC GUI example", 0, 0, 400, 300, 0, 0, CODEPTR(WindowProc))
    
    ' // Center the window
    pWindow.CenterWindow
    
    ' // Add a status bar
    LOCAL hStatusbar AS DWORD
    hStatusbar = pWindow.AddStatusBar(pWindow.hwnd, %IDC_STATUSBAR, "", 0, 0, 0, 0)
    pWindow.SetStatusbarPartsBySize(hStatusbar, "160, -1")
    
    ' // Add an edit control
    pWindow.AddTextBox(pWindow.hwnd, %IDC_EDIT, "Edit me", 20, 200, 200, 23)
    
    ' // Add a button
    pWindow.AddButton(pWindow.hwnd, %IDC_BUTON, "Click me", 293, 200, 75, 23)
    
    ' // Add a ListView control
    LOCAL hListView AS DWORD
    hListView = pWindow.AddListView(pWindow.hwnd, %IDC_LISTVIEW, "", 20, 20, 350, 150)
    ' // Add the header's column names
    LOCAL i AS LONG
    FOR i = 0 TO 4
    ListView_AddColumn(hListView, i, "Column" & STR$(i), pWindow.ScaleX(110))
    NEXT
    ' // Add some extended styles
    LOCAL dwExStyle AS DWORD
    dwExStyle = ListView_GetExtendedListViewStyle(hListView)
    dwExStyle = dwExStyle OR %LVS_EX_FULLROWSELECT OR %LVS_EX_GRIDLINES
    ListView_SetExtendedListViewStyle(hListView, dwExStyle)
    ' // Populate the ListView with some data
    FOR i = 0 to 29
    ListView_AddItem(hListView, i, 0, "Column 0 Row" + STR$(i))
    ListView_SetItemText(hListView, i, 1, "Column 1 Row" + STR$(i))
    ListView_SetItemText(hListView, i, 2, "Column 2 Row" + STR$(i))
    ListView_SetItemText(hListView, i, 3, "Column 3 Row" + STR$(i))
    ListView_SetItemText(hListView, i, 4, "Column 4 Row" + STR$(i))
    NEXT
    
    ' // Select the fist item
    ListView_SelectItem hListView, 0
    ' // Set the focus in the ListView
    SetFocus hListView
    
    ' // Default message pump (you can replace it with your own)
    FUNCTION = pWindow.DoEvents(nCmdShow)
    
    END FUNCTION
    ' ========================================================================================
    
    ' ========================================================================================
    ' Main callback function.
    ' ========================================================================================
    FUNCTION WindowProc (BYVAL hwnd AS DWORD, BYVAL uMsg AS DWORD, BYVAL wParam AS DWORD, BYVAL lParam AS LONG) AS LONG
    
    STATIC pWindow AS IWindow ' // Reference to the IWindow interface
    
    SELECT CASE uMsg
    
    CASE %WM_CREATE
    ' // Get a reference to the IWindow interface from the CREATESTRUCT structure
    pWindow = CWindow_GetObjectFromCreateStruct(lParam)
    EXIT FUNCTION
    
    CASE %WM_COMMAND
    SELECT CASE LO(WORD, wParam)
    CASE %IDCANCEL
    ' // If the Escape key has been pressed...
    IF HI(WORD, wParam) = %BN_CLICKED THEN
    ' // ... close the application by sending a WM_CLOSE message
    SendMessage hwnd, %WM_CLOSE, 0, 0
    EXIT FUNCTION
    END IF
    CASE %IDC_BUTON
    ' // Put your code here
    MessageBoxW(hwnd, "Click", "Message", %MB_OK)
    END SELECT
    
    CASE %WM_SIZE
    ' // Gets the handle of the status bar
    LOCAL hStatusBar AS DWORD
    hStatusBar = GetDlgItem(hwnd, %IDC_STATUSBAR)
    ' // Resizes it
    SendMessage hStatusBar, %WM_SIZE, wParam, lParam
    ' // Redraws it
    InvalidateRect hStatusBar, BYVAL %NULL, %TRUE
    EXIT FUNCTION
    
    CASE %WM_DESTROY
    ' // End the application
    PostQuitMessage 0
    EXIT FUNCTION
    
    END SELECT
    
    ' // Pass unprocessed messages to Windows
    FUNCTION = DefWindowProc(hwnd, uMsg, wParam, lParam)
    
    END FUNCTION
    ' ========================================================================================
    Last edited by José Roca; 22 Aug 2020, 09:18 PM.
    Forum: http://www.jose.it-berater.org/smfforum/index.php

    Comment


    • #3
      Ah, José beat me to it. Ah well, here small example using plain API and PB/CC includes. Program does nothing - it's just designer code:
      '
      Code:
      '======================================================================
      #COMPILE EXE
      #DIM ALL
      #IF %DEF(%PB_CC32)
        #CONSOLE OFF   ' <- if PBCC and you don't want/need consol
      #ENDIF
      '----------------------------------------------------------------------
      '%UNICODE = 1
      #INCLUDE "WIN32API.INC"
      #INCLUDE "COMMCTRL.INC"
      '----------------------------------------------------------------------
      %IDC_STATIC     = 101
      %IDC_BUTTON     = 120
      %IDC_EDIT       = 140
      %IDC_LISTVIEW   = 160
      %IDC_STATUSBAR  = 180
      
      '======================================================================
      FUNCTION WINMAIN (BYVAL hInst AS DWORD, BYVAL hPrevInstance AS DWORD, _
                        BYVAL lpszCmdLine AS ASCIIZ PTR, BYVAL nCmdShow AS LONG) AS LONG
      '----------------------------------------------------------------------
      ' Program entrance
      '----------------------------------------------------------------------
        LOCAL hDlg AS DWORD, hCtl AS DWORD, hFont AS DWORD, _
              wc AS WndClassEx, szClassName AS ASCIIZ * 80
      
        hFont = GetStockObject(%DEFAULT_GUI_FONT)
      
        szClassName      = "MyClassName"
        wc.cbSize        = SIZEOF(wc)
        wc.style         = %CS_HREDRAW OR %CS_VREDRAW
        wc.lpfnWndProc   = CODEPTR(WndProc)
        wc.cbClsExtra    = 0
        wc.cbWndExtra    = 0
        wc.hInstance     = hInst
        wc.hIcon         = LoadIcon  (%NULL, BYVAL %IDI_APPLICATION)
        wc.hCursor       = LoadCursor(%NULL, BYVAL %IDC_ARROW)
        wc.hbrBackground = %COLOR_3DFACE + 1
        wc.lpszMenuName  = %NULL
        wc.lpszClassName = VARPTR(szClassName)
        wc.hIconSm       = LoadIcon  (%NULL, BYVAL %IDI_APPLICATION)
        CALL RegisterClassEx (wc)
      
        hDlg = CreateWindowEx(%WS_EX_CONTROLPARENT OR %WS_EX_WINDOWEDGE, szClassName, "Example", _
                    %WS_VISIBLE OR %WS_CLIPSIBLINGS OR %WS_CAPTION OR %WS_SYSMENU, _
                    (GetSystemMetrics(%SM_CXSCREEN) - 346) / 2, _
                    (GetSystemMetrics(%SM_CYSCREEN) - 239) / 2, _
                     346, 239, 0, 0, GetModuleHandle(""), BYVAL %NULL)
      
        '--------------------------------------------------------------------
        hCtl = CreateWindowEx(0, "Static", "&Search:", _
                    %WS_CHILD OR %WS_VISIBLE OR %WS_CLIPSIBLINGS OR %WS_TABSTOP OR _
                    %SS_NOTIFY OR %SS_RIGHT, _
                     8, 11, 40, 16, _
                     hDlg, %IDC_STATIC, GetModuleHandle(""), BYVAL %NULL)
        IF hFont THEN SendMessage hCtl, %WM_SETFONT, hFont, 0
      
        hCtl = CreateWindowEx(%WS_EX_CLIENTEDGE, "Edit", BYVAL %NULL, _
                    %WS_CHILD OR %WS_VISIBLE OR %WS_CLIPSIBLINGS OR %WS_TABSTOP, _
                     53, 8, 188, 21, _
                     hDlg, %IDC_EDIT, GetModuleHandle(""), BYVAL %NULL)
        IF hFont THEN SendMessage hCtl, %WM_SETFONT, hFont, 0
      
        hCtl = CreateWindowEx(0, "Button", "&Search", _
                    %WS_CHILD OR %WS_VISIBLE OR %WS_CLIPSIBLINGS OR %WS_TABSTOP, _
                     248, 6, 75, 22, _
                     hDlg, %IDOK, GetModuleHandle(""), BYVAL %NULL)
        IF hFont THEN SendMessage hCtl, %WM_SETFONT, hFont, 0
        '--------------------------------------------------------------------
      
        InitCommonControls
      
        hCtl = CreateWindowEx(%WS_EX_CLIENTEDGE, "SysListView32", BYVAL %NULL, _
                    %WS_CHILD OR %WS_VISIBLE OR %WS_VSCROLL OR %WS_TABSTOP OR _
                    %LVS_REPORT OR %LVS_SHOWSELALWAYS, _
                     0, 34, 346, 158, _
                     hDlg, %IDC_LISTVIEW, GetModuleHandle(""), BYVAL %NULL)
        IF hFont THEN SendMessage hCtl, %WM_SETFONT, hFont, 0
      
        SendMessage hCtl, %LVM_SETEXTENDEDLISTVIEWSTYLE, 0, _
                          %LVS_EX_FULLROWSELECT OR %LVS_EX_GRIDLINES
      
        '--------------------------------------------------------------------
        hCtl = CreateWindowEx(0, "msctls_statusbar32", " Part 1", _
                    %WS_CHILD OR %WS_VISIBLE OR %CCS_BOTTOM, _
                     0, 179, 330, 20, _
                     hDlg, %IDC_STATUSBAR, GetModuleHandle(""), BYVAL %NULL)
        IF hFont THEN SendMessage hCtl, %WM_SETFONT, hFont, 0
      
        '--------------------------------------------------------------------
        ShowWindow hDlg, nCmdShow
        UpdateWindow hDlg
      
        LOCAL Msg AS tagMsg
        WHILE GetMessage(Msg, %NULL, 0, 0)
            TranslateMessage Msg
            DispatchMessage Msg
        WEND
      
        FUNCTION = msg.wParam
      END FUNCTION
      
      '======================================================================
      FUNCTION WndProc (BYVAL hWnd AS DWORD,  BYVAL wMsg AS DWORD, _
                        BYVAL wParam AS DWORD, BYVAL lParam AS LONG) AS DWORD
        SELECT CASE wMsg
        CASE %WM_CREATE
      
        CASE %WM_COMMAND
            SELECT CASE LOWRD(wParam)
            CASE %IDOK
                IF HIWRD(wParam) = %BN_CLICKED THEN
                    'Trigger search code..
                END IF
      
            CASE %IDC_EDIT
                IF HIWRD(wParam) = %EN_UPDATE THEN
                    ' Do something on Edit control change?
                END IF
            END SELECT
      
        CASE %WM_DESTROY
            PostQuitMessage 0
            EXIT FUNCTION
      
        END SELECT
      
        FUNCTION = DefWindowProc(hWnd, wMsg, wParam, lParam)
      END FUNCTION
      '

      Comment


      • #4
        Thank you José!! That's the exact type of window I was looking for. Not only did you give me examples of the two controls I requested help with...but every single control that I listed. I'll integrate this with my demo code and hopefully have some better looking demos to share.

        Thank you too Borje!! While I was replying to José when your example also came in. Lots to choose from.

        Comment


        • #5
          My CWindow class is 100% SDK compatible. It is a wapper to simplify some things and it is unicode and DPI aware. Using plain SDK without wrappers will take you more work. Now you have two ways to do it. It is up to you what you use.

          Forum: http://www.jose.it-berater.org/smfforum/index.php

          Comment


          • #6
            It's always good to have options. I will study both to understand how they work. Understanding the longer route will help me to appreciate the work that went into CWindow and the amount of work it can save me. Thanks again to both of you!!
            Last edited by Michael Rice; 22 Aug 2020, 08:11 PM.

            Comment


            • #7
              Directory List with Non-ASCII (Unicode) characters in file names 5-31-08 for PB/WIN or PB/CC

              Compiles 'as is' with either PB/CC or PB/WIN (versions in code).

              It would be kind of useless today, since all the Windows header files are different and you don't need to get cute to handle non-ASCII unicode characters in filenames, but hell, it's an example.
              .
              About all you can do with PB/Windows you cannot do with PB/CC is #COMPILE DLL.
              Michael Mattias
              Tal Systems Inc. (retired)
              Racine WI USA
              [email protected]
              http://www.talsystems.com

              Comment


              • #8
                SDK Progress Update 1

                First thank you Michael for your example as well. I'll add it to my "study this code" list.

                Thanks to the example code provided, I've been able to make some progress toward giving my demo code a GUI. This isn't completed code yet, just an update along the journey...

                Thanks again to everyone for helping me get this far!!

                Things I still need to do:
                Convert the LoadListView function into a thread function. The window freezes while the query runs and loads the listview control.
                Make the edit control work!! LOL I don't currently know how to read what the user has input. See my list of things to learn below.
                Convert post date from UCT to local user time and better format it for display...
                Add RadioButtons to select Remote or Local database ...I would like to place in I believe it's called a group control. Once again see the growing list of things to learn.
                Make the window a fixed size or learn to resize/position the controls when the window changes sizes.

                CWindow Things I need to learn for my demo:
                Enable/Disable Button
                Read user input from the edit control
                How to manually size listview column
                How to automatically size listview column based on column data width
                How to left/center/right justify column data
                How to add group control to wrap around the radiobuttons
                How to add radiobuttons and how to get selected button

                For a later demo:
                Add DropDownCombo control to the main window and get user selections. Might as well learn that now.

                Demo GUI so far
                Click image for larger version  Name:	Progress1.jpg Views:	0 Size:	225.6 KB ID:	798557


                Source Code so far:
                Code:
                #COMPILE EXE
                #DIM ALL
                #CONSOLE OFF ' // remove it to compile with PBWIN
                %UNICODE = 1
                
                #INCLUDE ONCE "CWindow.inc" ' // CWindow class
                #INCLUDE ONCE "ListViewCtrl.inc" ' // ListView control wrapper functions
                #INCLUDE ONCE "C:\SQLitening\inc\SQLitening.inc"
                
                %IDC_STATUSBAR = 1001
                %IDC_BUTON     = 1002
                %IDC_EDIT      = 1003
                %IDC_LISTVIEW  = 1004
                
                ' ========================================================================================
                ' Main
                ' ========================================================================================
                FUNCTION WinMain (BYVAL hInstance AS DWORD, BYVAL hPrevInstance AS DWORD, BYVAL lpszCmdLine AS WSTRINGZ PTR, BYVAL nCmdShow AS LONG) AS LONG
                
                   ' // Set process DPI aware
                   AfxSetProcessDPIAware
                
                   ' // Create an instance of the class
                   LOCAL pWindow AS IWindow
                   pWindow = CLASS "CWindow"
                   IF ISNOTHING(pWindow) THEN EXIT FUNCTION
                
                   ' // Create the main window
                   pWindow.CreateWindow(%NULL, "PBforum.db Search Demo", 0, 0, 800, 600, 0, 0, CODEPTR(WindowProc))
                
                   ' // Center the window
                   pWindow.CenterWindow
                
                   ' // Add a status bar
                   LOCAL hStatusbar AS DWORD
                   hStatusbar = pWindow.AddStatusBar(pWindow.hwnd, %IDC_STATUSBAR, "", 0, 0, 0, 0)
                   pWindow.SetStatusbarPartsBySize(hStatusbar, "160, -1")
                
                   ' // Add an edit control
                   LOCAL hTextBox AS DWORD
                   hTextBox = pWindow.AddTextBox(pWindow.hwnd, %IDC_EDIT, "", 5, 500, 600, 23)
                
                   ' // Add a button
                   pWindow.AddButton(pWindow.hwnd, %IDC_BUTON, "Search", 625, 500, 75, 23)
                
                   ' // Add a ListView control
                   LOCAL hListView AS DWORD
                   hListView = pWindow.AddListView(pWindow.hwnd, %IDC_LISTVIEW, "", 5, 5, 775, 475)
                   ' // Add the header's column names
                   LOCAL i AS LONG
                   'FOR i = 0 TO 4
                   '   ListView_AddColumn(hListView, i, "Column" & STR$(i), pWindow.ScaleX(110))
                   'NEXT
                   ListView_AddColumn(hListView, 0, "Thread Number", pWindow.ScaleX(110))
                   ListView_AddColumn(hListView, 1, "Post Number", pWindow.ScaleX(110))
                   ListView_AddColumn(hListView, 2, "Forum", pWindow.ScaleX(110))
                   ListView_AddColumn(hListView, 3, "Author", pWindow.ScaleX(110))
                   ListView_AddColumn(hListView, 4, "Post Date", pWindow.ScaleX(110))
                   ListView_AddColumn(hListView, 5, "Title", pWindow.ScaleX(110))
                   ' // Add some extended styles
                   LOCAL dwExStyle AS DWORD
                   dwExStyle = ListView_GetExtendedListViewStyle(hListView)
                   dwExStyle = dwExStyle OR %LVS_EX_FULLROWSELECT OR %LVS_EX_GRIDLINES
                   ListView_SetExtendedListViewStyle(hListView, dwExStyle)
                
                   ' // Set the focus in the hTextBox
                   SetFocus hTextBox
                
                   ' // Default message pump (you can replace it with your own)
                   FUNCTION = pWindow.DoEvents(nCmdShow)
                
                END FUNCTION
                ' ========================================================================================
                
                FUNCTION LoadListView(BYVAL hwnd AS DWORD, sSearchText AS STRING) AS DWORD
                
                   LOCAL swWork AS WSTRING
                   LOCAL i AS LONG
                   LOCAL hListView AS DWORD
                   LOCAL hStatusBar AS DWORD
                
                   hListView = GetDlgItem(hwnd, %IDC_LISTVIEW)
                   hStatusBar = GetDlgItem(hwnd, %IDC_STATUSBAR)
                
                   LOCAL sSQL AS STRING
                   LOCAL sForumName AS STRING
                   LOCAL sTitle AS STRING
                   LOCAL sAuthor AS STRING
                   LOCAL sPostDate AS STRING
                   LOCAL dwRowCount AS DWORD
                   LOCAL dwThread_Link AS DWORD
                   LOCAL dwPostNumber  AS DWORD
                
                   swWork = "Searching..."
                   SendMessage hStatusBar,%SB_SETTEXT,0,BYVAL STRPTR(swWork)
                   swWork = "Searching for " + $DQ + sSearchText + $DQ
                   SendMessage hStatusBar,%SB_SETTEXT,1,BYVAL STRPTR(swWork)
                
                   sSQL = "SELECT T1.Thread_Link, "                                          + _
                          "       T1.PostNumber, "                                           + _
                          "       T3.Name, "                                                 + _
                          "       T3.ForumURL, "                                             + _
                          "       T2.ThreadURL, "                                            + _
                          "       T2.ThreadTitle, "                                          + _
                          "       T4.Author, "                                               + _
                          "       T1.PostDate, "                                             + _
                          "       T1.PostContent "                                           + _
                          "  FROM ThreadContent T1 "                                         + _
                          "       LEFT OUTER JOIN Threads T2 "                               + _
                          "                    ON T2.ThreadNumber = T1.Thread_Link "         + _
                          "       LEFT OUTER JOIN Forums T3 "                                + _
                          "                    ON T2.ThreadNumber = T1.Thread_Link "         + _
                          "                   AND T2.Forum_Link = T3.RowID "                 + _
                          "       LEFT OUTER JOIN ForumAuthors T4 "                          + _
                          "                    ON T1.Author_Link = T4.RowID "                + _
                          "WHERE T2.ThreadTitle LIKE '%" + sSearchText + "%' "               + _
                          "   OR T1.PostContent LIKE '%" + sSearchText + "%' "               + _
                          "ORDER BY T1.Thread_Link ASC, T1.PostNumber ASC;"
                
                   slConnect "38.17.54.213",51234
                   slOpen "PBforum\PBforum.db" + $BS + "Read%Only", "R"  '1 open with read-only password
                   slSel sSQL
                
                   DO WHILE slGetRow
                
                      INCR dwRowCount
                      dwThread_Link = VAL(slF(1))
                      dwPostNumber  = VAL(slF(2))
                      sForumName    = slF(3)
                      sTitle        = slF(6)
                      sAuthor       = slF(7)
                      sPostDate     = slF(8)
                
                      ListView_AddItem(hListView, dwRowCount - 1, 0, FORMAT$(dwThread_Link))
                      ListView_SetItemText(hListView, dwRowCount - 1, 1, FORMAT$(dwPostNumber))
                      ListView_SetItemText(hListView, dwRowCount - 1, 2, sForumName)
                      ListView_SetItemText(hListView, dwRowCount - 1, 3, sAuthor)
                      ListView_SetItemText(hListView, dwRowCount - 1, 4, sPostDate)
                      ListView_SetItemText(hListView, dwRowCount - 1, 5, sTitle)
                
                   LOOP
                
                   'CON.STDOUT "Rows returned: " + FORMAT$(dwRowCount)
                   swWork = "Rows returned: " + FORMAT$(dwRowCount,"#,")
                   SendMessage hStatusBar,%SB_SETTEXT,0,BYVAL STRPTR(swWork)
                
                   slClose
                   slDisconnect
                
                   ' // Select the fist item
                   ListView_SelectItem hListView, 0
                   ' // Set the focus in the ListView
                   SetFocus hListView
                
                END FUNCTION
                ' ========================================================================================
                ' Main callback function.
                ' ========================================================================================
                FUNCTION WindowProc (BYVAL hwnd AS DWORD, BYVAL uMsg AS DWORD, BYVAL wParam AS DWORD, BYVAL lParam AS LONG) AS LONG
                
                   STATIC pWindow AS IWindow ' // Reference to the IWindow interface
                
                   SELECT CASE uMsg
                
                      CASE %WM_CREATE
                         ' // Get a reference to the IWindow interface from the CREATESTRUCT structure
                         pWindow = CWindow_GetObjectFromCreateStruct(lParam)
                         EXIT FUNCTION
                
                      CASE %WM_COMMAND
                         SELECT CASE LO(WORD, wParam)
                            CASE %IDCANCEL
                               ' // If the Escape key has been pressed...
                               IF HI(WORD, wParam) = %BN_CLICKED THEN
                                  ' // ... close the application by sending a WM_CLOSE message
                                  SendMessage hwnd, %WM_CLOSE, 0, 0
                                  EXIT FUNCTION
                               END IF
                            CASE %IDC_BUTON
                               ' // Put your code here
                               'MessageBoxW(hwnd, "Click", "Message", %MB_OK)
                               LoadListView(hwnd,"CWindow")
                               'LoadListView(hwnd,"Structured Storage")
                               'LoadListView(hwnd,"PowerBASIC")
                         END SELECT
                
                      CASE %WM_SIZE
                         ' // Gets the handle of the status bar
                         LOCAL hStatusBar AS DWORD
                         hStatusBar = GetDlgItem(hwnd, %IDC_STATUSBAR)
                         ' // Resizes it
                         SendMessage hStatusBar, %WM_SIZE, wParam, lParam
                         ' // Redraws it
                         InvalidateRect hStatusBar, BYVAL %NULL, %TRUE
                         EXIT FUNCTION
                
                      CASE %WM_DESTROY
                         ' // End the application
                         PostQuitMessage 0
                         EXIT FUNCTION
                
                   END SELECT
                
                   ' // Pass unprocessed messages to Windows
                   FUNCTION = DefWindowProc(hwnd, uMsg, wParam, lParam)
                
                END FUNCTION
                ' ========================================================================================

                Comment


                • #9
                  > Read user input from the edit control

                  Add at the top:

                  Code:
                  #INCLUDE ONCE "EditCtrl.inc" ' // Edit control wrapper functions
                  Code:
                  CASE %IDC_BUTON
                  ' // Put your code here
                  DIM wsText AS WSTRING
                  wsText = Edit_GetText(GetDlgItem(hwnd, %IDC_EDIT))
                  MessageBoxW(hwnd, BYCOPY(wsText), "Message", %MB_OK)
                  Forum: http://www.jose.it-berater.org/smfforum/index.php

                  Comment


                  • #10
                    > Enable/Disable Button

                    Code:
                    EnableWindow(hButton, %TRUE)   ' enable
                    EnableWindow(hButton, %FALSE)   ' disable
                    Where hButton is the handle of the button control that you can retrieve with GetDlgItem(<handle of the main window>, %ID_BUTTON)
                    Forum: http://www.jose.it-berater.org/smfforum/index.php

                    Comment


                    • #11
                      > How to automatically size listview column based on column data width

                      Code:
                      ListView_AutoSizeColumns(hListView)
                      Forum: http://www.jose.it-berater.org/smfforum/index.php

                      Comment


                      • #12
                        > How to left/center/right justify column data

                        The ListView_AddColumn wrapper function has an optional parameter to set the text alignment, e.g.

                        Code:
                        ListView_AddColumn(hListView, 1, "Post Number", pWindow.ScaleX(110), %LVCFMT_LEFT)    ' Left aligned, which is the default value
                        ListView_AddColumn(hListView, 1, "Post Number", pWindow.ScaleX(110), %LVCFMT_CENTER)    ' Center aligned
                        ListView_AddColumn(hListView, 1, "Post Number", pWindow.ScaleX(110), %LVCFMT_RIGHT)    ' Right aligned
                        Note that column 0 will be always left aligned.
                        Forum: http://www.jose.it-berater.org/smfforum/index.php

                        Comment


                        • #13
                          > How to manually size listview column

                          I'm not sure what do you mean.

                          In pWindow.ScaleX(110), 110 is the number of pixels. Just change it.
                          Forum: http://www.jose.it-berater.org/smfforum/index.php

                          Comment


                          • #14
                            Originally posted by José Roca View Post
                            > How to manually size listview column

                            I'm not sure what do you mean.
                            Sadly that was me asking a really dumb question on a public forum!! Thank you for pointing out what should have been obvious to me.

                            Comment


                            • #15
                              > Add RadioButtons to select Remote or Local database ...I would like to place in I believe it's called a group control. Once again see the growing list of things to learn.

                              Code:
                              #COMPILE EXE
                              #DIM ALL
                              #IF %DEF(%PB_CC32)
                                #CONSOLE OFF   ' <- if PBCC and you don't want/need console
                              #ENDIF
                              %UNICODE = 1
                              
                              #INCLUDE ONCE "CWindow.inc"        ' // CWindow class
                              
                              %IDC_BUTTON = 1001
                              %IDC_GROUPBOX = 1002
                              %IDC_OPTION1 = 1003
                              %IDC_OPTION2 = 1004
                              %IDC_OPTION3 = 1005
                              
                              ' ========================================================================================
                              ' Main
                              ' ========================================================================================
                              FUNCTION WinMain (BYVAL hInstance AS DWORD, BYVAL hPrevInstance AS DWORD, BYVAL lpszCmdLine AS WSTRINGZ PTR, BYVAL nCmdShow AS LONG) AS LONG
                              
                                 ' // Set process DPI aware
                                 AfxSetProcessDPIAware
                              
                                 ' // Create an instance of the class
                                 LOCAL pWindow AS IWindow
                                 pWindow = CLASS "CWindow"
                                 IF ISNOTHING(pWindow) THEN EXIT FUNCTION
                              
                                 ' // Create the main window
                                 pWindow.CreateWindow(%NULL, "PBCC GUI example", 0, 0, 400, 300, 0, 0, CODEPTR(WindowProc))
                              
                                 ' // Center the window
                                 pWindow.CenterWindow
                              
                                 ' // Add a button
                                 pWindow.AddButton(pWindow.hwnd, %IDC_BUTTON, "Get check", 293, 200, 75, 23)
                              
                                 ' // Add a group box control
                                 pWindow.AddGroupBox(pWindow.hwnd, %IDC_GROUPBOX, "Options", 10, 10, 325, 120)
                                 ' // Add three radio buttons (the first one should have the %WS_GROUP style)
                                 pWindow.AddRadioButton(pWindow.hwnd, %IDC_OPTION1, "Option 1", 60, 40, 75, 23, %WS_GROUP)
                                 pWindow.AddRadioButton(pWindow.hwnd, %IDC_OPTION2, "Option 2", 60, 60, 75, 23)
                                 pWindow.AddRadioButton(pWindow.hwnd, %IDC_OPTION3, "Option 3", 60, 80, 75, 23)
                                 ' // Chec the first radio button
                                 CheckDlgButton pWindow.hwnd, %IDC_OPTION1, %BST_CHECKED
                              
                              
                                 ' // Default message pump (you can replace it with your own)
                                 FUNCTION = pWindow.DoEvents(nCmdShow)
                              
                              END FUNCTION
                              ' ========================================================================================
                              
                              ' ========================================================================================
                              ' Main callback function.
                              ' ========================================================================================
                              FUNCTION WindowProc (BYVAL hwnd AS DWORD, BYVAL uMsg AS DWORD, BYVAL wParam AS DWORD, BYVAL lParam AS LONG) AS LONG
                              
                                 SELECT CASE uMsg
                              
                                    CASE %WM_COMMAND
                                       SELECT CASE LO(WORD, wParam)
                                          CASE %IDCANCEL
                                             ' // If the Escape key has been pressed...
                                             IF HI(WORD, wParam) = %BN_CLICKED THEN
                                                ' // ... close the application by sending a WM_CLOSE message
                                                SendMessage hwnd, %WM_CLOSE, 0, 0
                                                EXIT FUNCTION
                                             END IF
                                          CASE %IDC_BUTTON
                                             ' // Get the checked radio button
                                             LOCAL i AS LONG, nCheck AS LONG
                                             FOR i = %IDC_OPTION1 TO %IDC_OPTION3
                                                nCheck = SendMessage(GetDlgItem(hwnd, i), %BM_GETCHECK, 0, 0)
                                                IF nCheck = %BST_CHECKED THEN
                                                   MessageBox(hwnd, "Button " & STR$(i - %IDC_OPTION1 + 1) & " checked", "Message", %MB_OK)
                                                   EXIT FOR
                                                END IF
                                             NEXT
                                       END SELECT
                              
                                    CASE %WM_DESTROY
                                       ' // End the application
                                       PostQuitMessage 0
                                       EXIT FUNCTION
                              
                                 END SELECT
                              
                                 ' // Pass unprocessed messages to Windows
                                 FUNCTION = DefWindowProc(hwnd, uMsg, wParam, lParam)
                              
                              END FUNCTION
                              ' ========================================================================================
                              Forum: http://www.jose.it-berater.org/smfforum/index.php

                              Comment


                              • #16
                                > Make the window a fixed size or learn to resize/position the controls when the window changes sizes.

                                Check the code under the %WM_SIZE message.

                                Code:
                                #COMPILE EXE
                                #DIM ALL
                                #IF %DEF(%PB_CC32)
                                  #CONSOLE OFF   ' <- if PBCC and you don't want/need console
                                #ENDIF
                                %UNICODE = 1
                                
                                #INCLUDE ONCE "CWindow.inc"        ' // CWindow class
                                #INCLUDE ONCE "ListViewCtrl.inc"   ' // ListView control wrapper functions
                                #INCLUDE ONCE "EditCtrl.inc"       ' // Edit control wrapper functions
                                
                                %IDC_STATUSBAR = 1001
                                %IDC_BUTTON = 1002
                                %IDC_EDIT = 1003
                                %IDC_LISTVIEW = 1004
                                
                                ' ========================================================================================
                                ' Main
                                ' ========================================================================================
                                FUNCTION WinMain (BYVAL hInstance AS DWORD, BYVAL hPrevInstance AS DWORD, BYVAL lpszCmdLine AS WSTRINGZ PTR, BYVAL nCmdShow AS LONG) AS LONG
                                
                                   ' // Set process DPI aware
                                   AfxSetProcessDPIAware
                                
                                   ' // Create an instance of the class
                                   LOCAL pWindow AS IWindow
                                   pWindow = CLASS "CWindow"
                                   IF ISNOTHING(pWindow) THEN EXIT FUNCTION
                                
                                   ' // Create the main window
                                   pWindow.CreateWindow(%NULL, "PBCC GUI example", 0, 0, 400, 300, 0, 0, CODEPTR(WindowProc))
                                
                                   ' // Center the window
                                   pWindow.CenterWindow
                                
                                   ' // Add a status bar
                                   LOCAL hStatusbar AS DWORD
                                   hStatusbar = pWindow.AddStatusBar(pWindow.hwnd, %IDC_STATUSBAR, "", 0, 0, 0, 0)
                                   pWindow.SetStatusbarPartsBySize(hStatusbar, "160, -1")
                                
                                   ' // Add an edit control
                                   pWindow.AddTextBox(pWindow.hwnd, %IDC_EDIT, "Edit me", 0, 0, 200, 23)
                                
                                   ' // Add a button
                                   pWindow.AddButton(pWindow.hwnd, %IDC_BUTTON, "Click me", 0, 0, 75, 23)
                                
                                   ' // Add a ListView control
                                   LOCAL hListView AS DWORD
                                   hListView = pWindow.AddListView(pWindow.hwnd, %IDC_LISTVIEW, "", 20, 20, 350, 150)
                                   ' // Add the header's column names
                                   LOCAL i AS LONG
                                   ' // Add some extended styles
                                   LOCAL 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
                                   FOR i = 0 TO 4
                                      ListView_AddColumn(hListView, i, "Column" & STR$(i), pWindow.ScaleX(110))
                                   NEXT
                                   ' // Populate the ListView with some data
                                   FOR i = 0 to 29
                                      ListView_AddItem(hListView, i, 0, "Column 0 Row" + STR$(i))
                                      ListView_SetItemText(hListView, i, 1, "Column 1 Row" + STR$(i))
                                      ListView_SetItemText(hListView, i, 2, "Column 2 Row" + STR$(i))
                                      ListView_SetItemText(hListView, i, 3, "Column 3 Row" + STR$(i))
                                      ListView_SetItemText(hListView, i, 4, "Column 4 Row" + STR$(i))
                                   NEXT
                                
                                   ' // Select the fist item
                                   ListView_SelectItem hListView, 0
                                   ' // Set the focus in the ListView
                                   SetFocus hListView
                                
                                   ' // Default message pump (you can replace it with your own)
                                   FUNCTION = pWindow.DoEvents(nCmdShow)
                                
                                END FUNCTION
                                ' ========================================================================================
                                
                                ' ========================================================================================
                                ' Main callback function.
                                ' ========================================================================================
                                FUNCTION WindowProc (BYVAL hwnd AS DWORD, BYVAL uMsg AS DWORD, BYVAL wParam AS DWORD, BYVAL lParam AS LONG) AS LONG
                                
                                   STATIC pWindow AS IWindow        ' // Reference to the IWindow interface
                                
                                   SELECT CASE uMsg
                                
                                      CASE %WM_CREATE
                                         ' // Get a reference to the IWindow interface from the CREATESTRUCT structure
                                         pWindow = CWindow_GetObjectFromCreateStruct(lParam)
                                         EXIT FUNCTION
                                
                                      CASE %WM_COMMAND
                                         SELECT CASE LO(WORD, wParam)
                                            CASE %IDCANCEL
                                               ' // If the Escape key has been pressed...
                                               IF HI(WORD, wParam) = %BN_CLICKED THEN
                                                  ' // ... close the application by sending a WM_CLOSE message
                                                  SendMessage hwnd, %WM_CLOSE, 0, 0
                                                  EXIT FUNCTION
                                               END IF
                                            CASE %IDC_BUTTON
                                               ' // Put your code here
                                               DIM wsText AS WSTRING
                                               wsText = Edit_GetText(GetDlgItem(hwnd, %IDC_EDIT))
                                               MessageBoxW(hwnd, BYCOPY(wsText), "Message", %MB_OK)
                                         END SELECT
                                
                                      CASE %WM_SIZE
                                         ' // If the window isn't minimized, resize the controls
                                         IF wParam <> %SIZE_MINIMIZED THEN
                                            ' // Gets the handle of the status bar
                                            LOCAL hStatusBar AS DWORD
                                            hStatusBar = GetDlgItem(hwnd, %IDC_STATUSBAR)
                                            ' // Resizes it
                                            SendMessage hStatusBar, %WM_SIZE, wParam, lParam
                                            ' // Redraws it
                                            InvalidateRect hStatusBar, BYVAL %NULL, %TRUE
                                            ' // Resize the Listview control
                                            pWindow.MoveWindow(GetDlgItem(hwnd, %IDC_LISTVIEW), 20, 20, pWindow.ClientWidth - 40, pWindow.ClientHeight - 100, %TRUE)
                                            ' // Move the position of the edit an button controls
                                            pWindow.SetWindowPos(GetDlgItem(hwnd, %IDC_EDIT), 0, 20, pWindow.ClientHeight - 60, 200, 23, %SWP_NOSIZE OR %SWP_NOZORDER)
                                            pWindow.SetWindowPos(GetDlgItem(hwnd, %IDC_BUTTON), 0, 293, pWindow.ClientHeight - 60, 75, 23, %SWP_NOSIZE OR %SWP_NOZORDER)
                                         END IF
                                         EXIT FUNCTION
                                
                                      CASE %WM_DESTROY
                                         ' // End the application
                                         PostQuitMessage 0
                                         EXIT FUNCTION
                                
                                   END SELECT
                                
                                   ' // Pass unprocessed messages to Windows
                                   FUNCTION = DefWindowProc(hwnd, uMsg, wParam, lParam)
                                
                                END FUNCTION
                                ' ========================================================================================
                                Last edited by José Roca; 23 Aug 2020, 12:38 AM.
                                Forum: http://www.jose.it-berater.org/smfforum/index.php

                                Comment


                                • #17
                                  > Convert the LoadListView function into a thread function. The window freezes while the query runs and loads the listview control.

                                  You can't update a GUI created in a thread from another thread.
                                  Forum: http://www.jose.it-berater.org/smfforum/index.php

                                  Comment


                                  • #18
                                    > For a later demo:
                                    > Add DropDownCombo control to the main window and get user selections. Might as well learn that now.

                                    Code:
                                    #COMPILE EXE
                                    #DIM ALL
                                    #IF %DEF(%PB_CC32)
                                      #CONSOLE OFF   ' <- if PBCC and you don't want/need console
                                    #ENDIF
                                    %UNICODE = 1
                                    
                                    ' // Include files for external files
                                    #INCLUDE ONCE "CWindow.inc"        ' // CWindow class
                                    #INCLUDE ONCE "ComboBoxCtrl.inc"   ' // Combobox wrapper functions
                                    
                                    %IDC_COMBOBOX = 1001
                                    
                                    ' ========================================================================================
                                    ' Main
                                    ' ========================================================================================
                                    FUNCTION WinMain (BYVAL hInstance AS DWORD, BYVAL hPrevInstance AS DWORD, BYVAL lpszCmdLine AS WSTRINGZ PTR, BYVAL nCmdShow AS LONG) AS LONG
                                    
                                       ' // Set process DPI aware
                                       AfxSetProcessDPIAware
                                    
                                       ' // Create an instance of the class
                                       LOCAL pWindow AS IWindow
                                       pWindow = CLASS "CWindow"
                                       IF ISNOTHING(pWindow) THEN EXIT FUNCTION
                                    
                                       ' // Create the main window
                                       ' // Note: CW_USEDEFAULT is used as the default value When passing 0's as the width and height
                                       pWindow.CreateWindow(%NULL, "CWindow with a combobox", 0, 0, 0, 0, 0, 0, CODEPTR(WindowProc))
                                       ' // Set the client size
                                       pWindow.SetClientSize 500, 320
                                       ' // Center the window
                                       pWindow.CenterWindow
                                    
                                       ' // Add a combobox control
                                       DIM hCombobox AS DWORD
                                       hCombobox = pWindow.AddComboBox(pWindow.hwnd, %IDC_COMBOBOX, "", 80, 30, 190, 200)
                                    
                                       ' // Fill the control with some data
                                       DIM wsText AS WSTRING
                                       DIM i AS LONG
                                       FOR i = 1 TO 9
                                          wsText = "Item " & RIGHT$("00" & STR$(i), 2)
                                          ComboBox_AddString(hComboBox, wsText)
                                       NEXT
                                       ' // Select the first item in the combo box
                                       ComboBox_SetCursel(hComboBox, 0)
                                    
                                       ' // Default message pump (you can replace it with your own)
                                       FUNCTION = pWindow.DoEvents(nCmdShow)
                                    
                                    END FUNCTION
                                    ' ========================================================================================
                                    
                                    ' ========================================================================================
                                    ' Main callback function.
                                    ' ========================================================================================
                                    FUNCTION WindowProc (BYVAL hwnd AS DWORD, BYVAL uMsg AS DWORD, BYVAL wParam AS DWORD, BYVAL lParam AS LONG) AS LONG
                                    
                                       ' // Process window mesages
                                       SELECT CASE uMsg
                                    
                                          CASE %WM_COMMAND
                                             SELECT CASE LO(WORD, wParam)
                                                CASE %IDCANCEL
                                                   ' // If the Escape key has been pressed...
                                                   IF HI(WORD, wParam) = %BN_CLICKED THEN
                                                      ' // ... close the application by sending a WM_CLOSE message
                                                      SendMessage hwnd, %WM_CLOSE, 0, 0
                                                      EXIT FUNCTION
                                                   END IF
                                                CASE %IDC_COMBOBOX
                                                   IF HI(WORD, wParam) = %LBN_SELCHANGE THEN
                                                      ' // Handle of the combobox
                                                      DIM hCombobox AS DWORD
                                                      hCombobox = GetDlgItem(hwnd, %IDC_COMBOBOX)
                                                      ' // Retrieve the Item selected
                                                      DIM curSel AS LONG
                                                      curSel = ComboBox_GetCursel(hCombobox)
                                                      MessageBox(hwnd, "You have selected " & _
                                                         ComboBox_GetLbText(hCombobox, curSel), "ComboBox Test", %MB_OK)
                                                   END IF
                                             END SELECT
                                    
                                          CASE %WM_DESTROY
                                             ' // End the application
                                             PostQuitMessage 0
                                             EXIT FUNCTION
                                    
                                       END SELECT
                                    
                                       ' // Pass unprocessed messages to Windows
                                       FUNCTION = DefWindowProc(hwnd, uMsg, wParam, lParam)
                                    
                                    END FUNCTION
                                    ' ========================================================================================
                                    Forum: http://www.jose.it-berater.org/smfforum/index.php

                                    Comment


                                    • #19
                                      Originally posted by José Roca View Post
                                      > Convert the LoadListView function into a thread function. The window freezes while the query runs and loads the listview control.

                                      You can't update a GUI created in a thread from another thread.
                                      Two things to improve the responsiveness:
                                      Get the recordset into a global array in a separate thread and then LoadListview from the array once it has been populated.

                                      Wrap the listview populating in %WM_SETREDRAW,%FALSE and %WM_SETREDRAW,%TRUE messages
                                      (or make it a virtual listview based on the global array)

                                      Comment


                                      • #20
                                        > Convert post date from UCT to local user time and better format it for display...

                                        Change
                                        " T1.PostDate, "
                                        to
                                        " strftime('%Y %m %d %H:%M', T1.PostDate,'localtime'

                                        or another available format
                                        https://sqlite.org/lang_datefunc.html

                                        If none of them suit then you'll have to go the slower route of running every date/time through your own function using string replacement or PowerTime.

                                        Comment

                                        Working...
                                        X