InputBox() in console program

Windows specific questions.
srvaldez
Posts: 3379
Joined: Sep 25, 2005 21:54

Re: InputBox() in console program

Post by srvaldez »

@UEZ thank you
but your input box as it is, lacks the functionality of returning user input, other than the yes or no
but I like the fading effect :-)
UEZ
Posts: 988
Joined: May 05, 2017 19:59
Location: Germany

Re: InputBox() in console program

Post by UEZ »

srvaldez wrote:@UEZ thank you
but your input box as it is, lacks the functionality of returning user input, other than the yes or no
but I like the fading effect :-)
Indeed, my mind was at a messagebox rather than an inputbox. I updated the code but currently ANSI only. I need to find out how to get unicode compatible code...
srvaldez
Posts: 3379
Joined: Sep 25, 2005 21:54

Re: InputBox() in console program

Post by srvaldez »

@deltarho[1859]
if you want fix the suspicious pointer warnings in AfxWin.inc, just change LPWSTR = RT_RCDATA to LPWSTR = Cptr(LPWSTR, RT_RCDATA) in functions AfxExtractResourceToFile and AfxExtractResource
Last edited by srvaldez on Jul 15, 2019 21:23, edited 1 time in total.
srvaldez
Posts: 3379
Joined: Sep 25, 2005 21:54

Re: InputBox() in console program

Post by srvaldez »

thank you UEZ
look forward to the unicode version :-)
Josep Roca
Posts: 564
Joined: Sep 27, 2016 18:20
Location: Valencia, Spain

Re: InputBox() in console program

Post by Josep Roca »

> if you want fix the suspicious pointer warnings in AfxWin.inc, just change LPWSTR = RT_RCDATA to LPWSTR = Cptr(LPWSTR, RT_RCDATA) in functions AfxExtractResourceToFile and AfxExtractResource

PWSTR = RT_RCDATA? You must be using an old version. Currently I'm using BYVAL pResourceType AS LPWSTR = MAKEINTRESOURCEW(10).
deltarho[1859]
Posts: 4310
Joined: Jan 02, 2017 0:34
Location: UK
Contact:

Re: InputBox() in console program

Post by deltarho[1859] »

srvaldez wrote:if you want fix the suspicious pointer warnings in AfxWin.inc, just change LPWSTR = RT_RCDATA to LPWSTR = Cptr(LPWSTR, RT_RCDATA) in functions AfxExtractResourceToFile and AfxExtractResource
Done!

Thank you. <smile>
deltarho[1859]
Posts: 4310
Joined: Jan 02, 2017 0:34
Location: UK
Contact:

Re: InputBox() in console program

Post by deltarho[1859] »

Josep Roca wrote:You must be using an old version.
Just got the latest version ( https://github.com/JoseRoca/WinFBX ).

Thanks, José.
srvaldez
Posts: 3379
Joined: Sep 25, 2005 21:54

Re: InputBox() in console program

Post by srvaldez »

@Josep Roca thanks, there are no warnings when using your latest version :-)
deltarho[1859]
Posts: 4310
Joined: Jan 02, 2017 0:34
Location: UK
Contact:

Re: InputBox() in console program

Post by deltarho[1859] »

I should have mentioned that in the above example code I am using 'Dim S As String'. Strictly speaking AfxInputBox returns a CWSTR which is José's dynamic unicode string which works transparently with literals and FreeBASIC native strings. I think I am right in saying that WinFBX is 'wall to wall' unicode friendly.
Josep Roca
Posts: 564
Joined: Sep 27, 2016 18:20
Location: Valencia, Spain

Re: InputBox() in console program

Post by Josep Roca »

Like Windows, WinFBX is fully unicode. Unlike Windows, I don't have separate A and W functions, but take advantage of automatic conversions. AfxInputBox works with unicode, but you can use ansi strings with it. No need for two separate functions. It is also DPI aware and the captions of the buttons are localized/localised.

I even have made changes for upcoming FB 1.07, which allows to extend CWSTR from WSTRING, allowing a seamless integration with FB intrinsic functions. See: https://www.planetsquires.com/protect/f ... pic=4295.0
deltarho[1859]
Posts: 4310
Joined: Jan 02, 2017 0:34
Location: UK
Contact:

Re: InputBox() in console program

Post by deltarho[1859] »

If you want a themed AfxInputBox, compatible with your console window, create this file:

MyProgs.rc

Code: Select all

1 24 "Theme.xml" 
where Theme.xml is

Code: Select all

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<assembly xmlns="urn:schemas-microsoft-com:asm.v1" manifestVersion="1.0" xmlns:asmv3="urn:schemas-microsoft-com:asm.v3">
 
    <assemblyIdentity
        version="1.0.0.1"
        processorArchitecture="*"
        name="MyAppName.exe"
        type="win32"
    />
    <description>Optional MyDescription for MyAppName.exe</description>
 
    <asmv3:application>
        <asmv3:windowsSettings xmlns="http://schemas.microsoft.com/SMI/2005/WindowsSettings">
        <dpiAware>true</dpiAware>
        </asmv3:windowsSettings>
    </asmv3:application>
 
    <!-- Compatibility section for Program Compatibility Assistant (PCA) -->
    <compatibility xmlns="urn:schemas-microsoft-com:compatibility.v1">
        <application>
            <!-- Windows Vista -->
            <supportedOS Id="{e2011457-1546-43c5-a5fe-008deee3d3f0}"/>
            <!-- Windows 7 -->
            <supportedOS Id="{35138b9a-5d96-4fbd-8e2d-a2440225f93a}"/>
            <!-- Windows 8 -->
            <supportedOS Id="{4a2f28e3-53b9-4441-ba9c-d69d4a4a6e38}"/>
            <!-- Windows 8.1 -->
            <supportedOS Id="{1f676c76-80e1-4239-95bb-83d0f6d0da78}"/>
            <!-- Windows 10 -->
            <supportedOS Id="{8e0f7a12-bfb3-4fe8-b9a5-48fd50a15a9a}"/>
        </application>
    </compatibility>
 
    <!-- Trustinfo section for User Account Control (UAC) -->
    <trustInfo xmlns="urn:schemas-microsoft-com:asm.v2">
        <security>
            <requestedPrivileges>
                <!-- level   = "asInvoker"            -->
                <!-- level   = "highestAvailable"     -->
                <!-- level   = "requireAdministrator" -->
                <requestedExecutionLevel
                    level    = "asInvoker"
                    uiAccess = "false"
                />
            </requestedPrivileges>
        </security>
    </trustInfo>
 
    <!-- Dependency section -->
    <dependency>
        <dependentAssembly>
            <assemblyIdentity
                type="win32"
                name="Microsoft.Windows.Common-Controls"
                version="6.0.0.0"
                processorArchitecture="*"
                publicKeyToken="6595b64144ccf1df"
                language="*"
            />
        </dependentAssembly>
    </dependency>
 
</assembly>
Now add MyProgs.rc to the FB command line or, if you have WinFBE, put '#Resource "MyProgs.rc" at the top of your source code; noting that the statement is a comment.

I now get ( tested with gcc 5.2 and gcc 9.1 and both with 32-bit and 64-bit ):
Image

I don't know what srvaldez intends with an input box but it is a neat way to get switches into your console application. The optional prompt could be a list of switches and the edit control populated with your selected switches. Eg -t -verbose -ms or whatever. Your code, of course, will have to parse the input text and have default values for switches not chosen. I can hear you brains crunching ideas. <smile>
Josep Roca
Posts: 564
Joined: Sep 27, 2016 18:20
Location: Valencia, Spain

Re: InputBox() in console program

Post by Josep Roca »

BTW, if you're using WinFBX, there is an AfxOpenFileDialog function in AfxWin.inc (you were asking for it in your "file requester" topic). It uses "|" instead of nulls for the filter to solve the problem of embeded nulls with null terminated strings.

Documentation: https://github.com/JoseRoca/WinFBX/blob ... FileDialog
deltarho[1859]
Posts: 4310
Joined: Jan 02, 2017 0:34
Location: UK
Contact:

Re: InputBox() in console program

Post by deltarho[1859] »

I use AfxOpenFileDialog in Encrypternet. I have just done a quick search and found that 10 different Afx* are used in that application; If I had to rely on my knowledge of the SDK I would probably still be writing it. <smile>
srvaldez
Posts: 3379
Joined: Sep 25, 2005 21:54

Re: InputBox() in console program

Post by srvaldez »

@deltarho[1859] and Josep Roca thank you
that's a nice themed input box :-)
dodicat
Posts: 7983
Joined: Jan 10, 2006 20:30
Location: Scotland

Re: InputBox() in console program

Post by dodicat »

For an easy theme (one liner) you can do:

Code: Select all



#Include Once "windows.bi"
Declare Function SetWindowTheme Lib "UxTheme.dll" Alias "SetWindowTheme"(As Any Ptr,As zstring Ptr,As zstring Ptr) As Long 
Sub box(textmessage As zstring)
    Static  As HWND  MessageWindow,EditBox,save,cancel,del
    #macro CreateMessageWindow(textmessage)
    MessageWindow = CreateWindowEx(NULL,"#32770", "What is your message?", WS_OVERLAPPEDWINDOW Or WS_VISIBLE, CW_USEDEFAULT, CW_USEDEFAULT, 350, 200, NULL, NULL, NULL, NULL)
    EditBox = CreateWindowEx(WS_EX_CLIENTEDGE, "Edit", textmessage, WS_VISIBLE Or WS_CHILD Or WS_HSCROLL  Or ES_AUTOHSCROLL Or ES_MULTILINE, 10, 0, 250, 50, MessageWindow, NULL, NULL, NULL)
    save = CreateWindowEx(NULL, "Button", "Save", WS_VISIBLE Or WS_CHILD, 10, 70, 200, 24, MessageWindow, NULL, NULL, NULL)
    cancel=CreateWindowEx(NULL, "Button", "cancel", WS_VISIBLE Or WS_CHILD, 10, 100, 200, 24, MessageWindow, NULL, NULL, NULL)
    del=CreateWindowEx(NULL, "Button", "delete message", WS_VISIBLE Or WS_CHILD, 10, 130, 200, 24, MessageWindow, NULL, NULL, NULL)
    SetWindowTheme(messagewindow," "," ")
    #endmacro
    createmessagewindow(textmessage)
    Dim As msg msg1
    While GetMessage(@msg1,0,0,0)
        TranslateMessage(@msg1)
        DispatchMessage(@msg1)
        Select Case msg1.hwnd
        Case Messagewindow
            Select Case msg1.message
            Case 273  'close by clicking X
                destroywindow(messagewindow)
                Exit Sub
            End Select
            
        Case save
            Select Case msg1.message  
            Case WM_LBUTTONDOWN
                GetWindowText(EditBox,textMessage,255)
                destroywindow(messagewindow)
                Exit Sub
            End Select
            
        Case cancel
            Select Case msg1.message  
            Case WM_LBUTTONDOWN
                destroywindow(messagewindow)
                Exit Sub
            End Select
            
        Case del
            Select Case msg1.message  
            Case WM_LBUTTONDOWN
                textmessage=""
                destroywindow(messagewindow)
                Exit Sub
            End Select
        End Select
    Wend
End Sub


Dim As String s
Dim As zstring *255 txt
Do
    
    Do
        Print "Do you want to save a message y/n or <esc> key ?"
        s=Input(1)
        s=Lcase(s)
        If s=Chr(27) Then End
    Loop Until s="y" Or s="n"
    If Lcase(s)="y" Then box(txt)
    If Lcase(s)="n" Then Print "no message chosen"
    If Len(txt) Then Print "your message was  ";txt
Loop Until Multikey(1)

  
Here on win 10 it produces a neat blue window (with a grey border when in focus)
It might be different on other computers.
Post Reply