KwikNote

Started by MrBcx, August 27, 2024, 11:01:37 PM

Previous topic - Next topic

MrBcx

Quin,

Adding the WS_TABSTOP style alone is insufficient for accomplishing what you want.

You must subclass the edit control, as I've shown in the following code:



GUI "KwikNote", PIXELS

ENUM
    ID_Edit1 = 101
    ID_Button1
    ID_Button2
    ID_Button3
END ENUM

GLOBAL WinCount = 1

SUB FORMLOAD
    DIM SHARED AS HWND Form1, Edit1, Button1, Button2, Button3
    Form1   = BCX_FORM("KwikNotes", 0, 0, 250, 200, DS_MODALFRAME OR WS_POPUP OR WS_CAPTION OR WS_SYSMENU)
    Edit1   = BCX_EDIT("",              Form1, ID_Edit1,      2,    2, 275, 125)
    MODSTYLE(Edit1, WS_TABSTOP)

    SetWindowSubclass(Edit1, EditProc, ID_Edit1, 0)

    Button1 = BCX_BUTTON("&New Note",    Form1, ID_Button1,   10, 135,   65,   30)
    Button2 = BCX_BUTTON("&Delete Me",   Form1, ID_Button2,   90, 135,   65,   30)
    Button3 = BCX_BUTTON("Delete &All", Form1, ID_Button3, 175, 135,   65,   30)
    CENTER Form1
    SHOW   Form1
    SetFocus(Button1)
END SUB

BEGIN EVENTS
    SELECT CASE CBMSG
        '=================
        CASE WM_COMMAND
        '=================
        IF CBCTL = ID_Button1 THEN
            INCR WinCount
            CALL FORMLOAD
            SHOW CBHWND
            EXIT FUNCTION
        END IF
        '=================
        IF CBCTL = ID_Button2 THEN
            LOCAL h AS HWND
            DECR WinCount
            IF WinCount = 0 THEN
                RemoveWindowSubclass(Edit1, EditProc, ID_Edit1)
                PostQuitMessage(0)                  ' Don't leave hidden windows running
            END IF
            h = GetParent(GetFocus())
            HIDE CAST(HWND, h)                      ' Hide / don't delete
            EXIT FUNCTION
        END IF
        '=================
        IF CBCTL = ID_Button3 THEN
            RemoveWindowSubclass(Edit1, EditProc, ID_Edit1)
            PostQuitMessage(0)
        END IF
        '=================
        CASE WM_DESTROY
        RemoveWindowSubclass(Edit1, EditProc, ID_Edit1)
        PostQuitMessage(0)
        '=================
    END SELECT
END EVENTS


FUNCTION EditProc (          _
    hWnd AS HWND,            _
    Msg AS UINT,             _
    wParam AS WPARAM,        _
    lParam AS LPARAM,        _
    uIdSubclass AS UINT_PTR, _
    dwRefData AS DWORD_PTR) AS LRESULT CALLBACK
    IF Msg = WM_GETDLGCODE THEN
        IF wParam = VK_TAB THEN
            FUNCTION = DLGC_WANTCHARS OR DLGC_HASSETSEL OR DLGC_WANTARROWS
        END IF
    END IF
    FUNCTION = DefSubclassProc(hWnd, Msg, wParam, lParam)
END FUNCTION


Quin

MrBcx,
I took it upon myself to update this little demo today to use an Enum for control IDs, and to make it more accessible. Still a major work in progress for sure, for example if I tab to the edit field I can't tab out of it again, but it's a start.

Gui "KwikNote", Pixels

Enum
    ID_Edit1 = 101
    ID_Button1
    ID_Button2
    ID_Button3
End Enum

Global WinCount = 1

Sub Formload
    Dim Shared As HWND Form1, Edit1, Button1, Button2, Button3
    Form1   = Bcx_Form("KwikNotes", 0, 0, 250, 200, DS_MODALFRAME Or WS_POPUP Or WS_CAPTION Or WS_SYSMENU)
    Edit1   = Bcx_Edit("",              Form1, ID_Edit1,      2,    2, 275, 125)
    Modstyle(Edit1, WS_TABSTOP)
    Button1 = Bcx_Button("&New Note",    Form1, ID_Button1,   10, 135,   65,   30)
    Button2 = Bcx_Button("&Delete Me",   Form1, ID_Button2,   90, 135,   65,   30)
    Button3 = Bcx_Button("Delete &All", Form1, ID_Button3, 175, 135,   65,   30)
    Center Form1
    Show   Form1
    SetFocus(Button1)
End Sub

Begin Events
    Select Case Cbmsg
        '=================
        Case WM_COMMAND
        '=================
        If Cbctl = ID_Button1 Then
            Incr WinCount
            Call Formload
            Show Cbhwnd
            Exit Function
        End If
        '=================
        If Cbctl = ID_Button2 Then
            Local h As HWND
            Decr WinCount
            If WinCount = 0 Then PostQuitMessage(0) ' Don't leave hidden windows running
            h = GetParent(GetFocus())
            Hide Cast(HWND, h)                      ' Hide / don't delete
            Exit Function
        End If
        '=================
        If Cbctl = ID_Button3 Then
            PostQuitMessage(0)
        End If
        '=================
        Case WM_DESTROY
        PostQuitMessage(0)
        '=================
    End Select
End Events


MrBcx

#1
One of my BCX apps written 20+ years ago is named KwikNote and can be found in the GUI_DEMO collection.

I always felt my technique for spawning copies of a running program was clever.  Maybe not.

Anyway, today I updated the app to use normal BCX GUI commands which reduced the lines
of code.  When you click "New Note" it pops up in the center of the screen.  See screenshot ...


GUI "KwikNote", PIXELS

CONST  ID_Edit1   = 101
CONST  ID_Button1 = 102
CONST  ID_Button2 = 103
CONST  ID_Button3 = 104

GLOBAL WinCount     = 1

SUB FORMLOAD
    DIM SHARED AS HWND Form1, Edit1, Button1, Button2, Button3
    Form1   = BCX_FORM("KwikNotes", 0, 0, 250, 200, DS_MODALFRAME OR WS_POPUP OR WS_CAPTION OR WS_SYSMENU)
    Edit1   = BCX_EDIT("",             Form1, ID_Edit1,     2,   2, 275, 125)
    Button1 = BCX_BUTTON("New Note",   Form1, ID_Button1,  10, 135,  65,  30)
    Button2 = BCX_BUTTON("Delete Me",  Form1, ID_Button2,  90, 135,  65,  30)
    Button3 = BCX_BUTTON("Delete All", Form1, ID_Button3, 175, 135,  65,  30)
    CENTER Form1
    SHOW   Form1
END SUB

BEGIN EVENTS
    SELECT CASE CBMSG
        '=================
    CASE WM_COMMAND
        '=================
        IF CBCTL = ID_Button1 THEN
            INCR WinCount
            CALL FORMLOAD
            SHOW CBHWND
            EXIT FUNCTION
        END IF
        '=================
        IF CBCTL = ID_Button2 THEN
            LOCAL h AS HWND
            DECR WinCount
            IF WinCount = 0 THEN PostQuitMessage(0) ' Don't leave hidden windows running
            h = GetParent(GetFocus())
            HIDE CAST(HWND, h)                      ' Hide / don't delete
            EXIT FUNCTION
        END IF
        '=================
        IF CBCTL = ID_Button3 THEN
            PostQuitMessage(0)
        END IF
        '=================
    CASE WM_DESTROY
        PostQuitMessage(0)
        '=================
    END SELECT
END EVENTS