PlanetSquires Forums

Please login or register.

Login with username, password and session length
Advanced search  

Author Topic: AfxInputBox  (Read 2200 times)

Paul Squires

  • Administrator
  • Guru Member
  • *****
  • Posts: 9316
  • Windows 10
    • PlanetSquires Software
AfxInputBox
« on: September 01, 2017, 09:53:30 PM »

Another gem of a function!

It's found in the CWindow.inc source code file. Great versatile quick way to get input from the user. Localized button captions, unicode aware, prompt, caption, positioning....

I am using it in WinFBE to prompt the user for a new name for a Theme.

Awesome.
Logged
Paul Squires
PlanetSquires Software
WinFBE Editor and Visual Designer

Bumblebee

  • Junior Member
  • **
  • Posts: 51
Re: AfxInputBox
« Reply #1 on: July 02, 2020, 01:49:45 PM »

I couldn't find it in the help file, I'm glad I found it here.
Logged

Bumblebee

  • Junior Member
  • **
  • Posts: 51
Re: AfxInputBox
« Reply #3 on: July 02, 2020, 02:14:55 PM »

Thanks. Bookmarked :)

Edit: When x,y are set to zero, the input box can be briefly seen in the top left corner of the screen, before it is centered.
For the time being, I entered a 1/3,1/2 form position, and this avoids this small issue.
« Last Edit: July 02, 2020, 02:26:58 PM by Bumblebee »
Logged

Josť Roca

  • Moderator
  • Guru Member
  • *****
  • Posts: 3282
Re: AfxInputBox
« Reply #4 on: July 02, 2020, 10:41:28 PM »

I don't see such phenomenon.

Code: [Select]
#define UNICODE
#INCLUDE ONCE "Afx/CWindow.inc"
USING Afx

#define ID_INPUTBOX 101

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
   ' // The recommended way is to use a manifest file
   AfxSetProcessDPIAware

   ' // Creates the main window
   DIM pWindow AS CWindow
   ' -or- DIM pWindow AS CWindow = "MyClassName" (use the name that you wish)
   pWindow.Create(NULL, "CWindow with a button", @WndProc)
   ' // Sizes it by setting the wanted width and height of its client area
   pWindow.SetClientSize(500, 320)
   ' // Centers the window
   pWindow.Center

   ' // Adds a button
   pWindow.AddControl("Button", , ID_INPUTBOX, "&Input Box", 350, 250, 75, 23)

   ' // Displays the window and dispatches the Windows messages
   FUNCTION = pWindow.DoEvents(nCmdShow)

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

' ========================================================================================
' Main window 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)
            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 ID_INPUTBOX
               ' // If ESC key pressed, close the application by sending an WM_CLOSE message
               IF GET_WM_COMMAND_CMD(wParam, lParam) = BN_CLICKED THEN
                  DIM cws AS CWSTR = AfxInputBox(hwnd, 0, 0, "InputBox test", "What's your name?", "My name is Josť")
                  EXIT FUNCTION
               END IF
         END SELECT

      CASE WM_SIZE
         ' // Optional resizing code
         IF wParam <> SIZE_MINIMIZED THEN
            ' // Retrieve a pointer to the CWindow class
            DIM pWindow AS CWindow PTR = AfxCWindowPtr(hwnd)
            ' // Move the position of the button
            IF pWindow THEN pWindow->MoveWindow GetDlgItem(hwnd, IDCANCEL), _
               pWindow->ClientWidth - 120, pWindow->ClientHeight - 50, 75, 23, CTRUE
         END IF

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

   END SELECT

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

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

Bumblebee

  • Junior Member
  • **
  • Posts: 51
Re: AfxInputBox
« Reply #5 on: July 03, 2020, 08:31:16 AM »

With this code I am seeing it on Windows 7. Aero theme off.

Excerpt from CWindow.inc
Code: [Select]
DIM hInputBox AS HWND = pInputBox.Create(hParent, **cwsCaption, @AfxInputBoxWindowProc, x, y, 326, 142, dwStyle, dwExStyle)
   ' // Center the window
   IF x = 0 AND y = 0 THEN pInputBox.Center(hInputBox, hParent)

« Last Edit: July 04, 2020, 05:15:38 AM by Bumblebee »
Logged

Josť Roca

  • Moderator
  • Guru Member
  • *****
  • Posts: 3282
Re: AfxInputBox
« Reply #6 on: July 04, 2020, 03:20:19 PM »

As I don't have Windows 7 to test, please try the following to see of it works in your system:

In the AfxInputBox function, change

Code: [Select]
   DIM dwStyle AS DWORD = WS_VISIBLE OR WS_CAPTION OR WS_POPUPWINDOW

to

Code: [Select]
   DIM dwStyle AS DWORD = WS_CAPTION OR WS_POPUPWINDOW

Bumblebee

  • Junior Member
  • **
  • Posts: 51
Re: AfxInputBox
« Reply #7 on: July 04, 2020, 11:35:26 PM »

It worked. Problem resolved :)
Logged