You are not logged in. You can browse in the PowerBASIC Community, but you must click Login (top right) before you can post. If this is your first visit, check out the FAQ or Sign Up.
'
' Example DLL to display a modal dialog and return a value to the calling
' application.
'
' Requires PB/DLL v1.10 or later to compile.
'
$COMPILE DLL
$INCLUDE "WINAPI.INC"
DECLARE FUNCTION InputDlgProc(BYVAL hDlg AS INTEGER, _
BYVAL wMsg AS INTEGER, _
BYVAL wParam AS INTEGER, _
BYVAL lParam AS LONG) AS INTEGER
GLOBAL DlgAddr AS DWORD
GLOBAL hCurInstance AS WORD
GLOBAL gText AS ASCIIZ * 255
GLOBAL gCaption AS ASCIIZ * 255
GLOBAL gDefault AS ASCIIZ * 255
FUNCTION LibMain (BYVAL hInstance AS INTEGER, _
BYVAL wDataSeg AS WORD, _
BYVAL wHeapSize AS WORD, _
lpszCmdLine AS ASCIIZ) EXPORT AS INTEGER
'Save the instance handle of the DLL
hCurInstance = hInstance
'Remember! We have to return a "one" to indicate successful
' initialization
LibMain = 1 'success!
END FUNCTION
FUNCTION InputBox(Text AS ASCIIZ PTR, _
Caption AS ASCIIZ PTR, _
Default AS ASCIIZ PTR) EXPORT AS INTEGER
' Get the address of the dialog callback
DlgAddr = MakeProcInstance(CODEPTR(InputDlgProc), hCurInstance)
' If pointers are non-null, set default values for dialog
IF Text THEN
gText = @Text
ELSE
gText = "Enter Text"
END IF
IF Caption THEN
gCaption = @Caption
ELSE
gCaption = "INPUT BOX"
END IF
IF Default THEN
gDefault = @Default
ELSE
gDefault = ""
END IF
' Pop up the modal dialog and get return value
FUNCTION = DialogBox(hCurInstance, "INPUTBOX", 0, DlgAddr)
' If default buffer was passed, return the input text
IF Default THEN
@Default = gDefault
END IF
END FUNCTION
' **
' ** Generic routine to center any window given its handle.
' **
SUB CenterWindow(BYVAL hWnd AS WORD)
DIM WndRect AS RECT
DIM x AS INTEGER
DIM y AS INTEGER
GetWindowRect hWnd, WndRect
x = (GetSystemMetrics(%SM_CXSCREEN)-(WndRect.nRight-WndRect.nLeft))\2
y = (GetSystemMetrics(%SM_CYSCREEN)-(WndRect.nBottom-WndRect.nTop+GetSystemMetrics(%SM_CYCAPTION)))\2
SetWindowPos hWnd, %NULL, x, y, 0, 0, %SWP_NOSIZE OR %SWP_NOZORDER
END SUB
FUNCTION InputDlgProc(BYVAL hDlg AS INTEGER, _
BYVAL wMsg AS INTEGER, _
BYVAL wParam AS INTEGER, _
BYVAL lParam AS LONG) EXPORT AS INTEGER
' See INPUTBOX.RC script for details on the dialog itself
SELECT CASE wMsg
CASE %WM_INITDIALOG
'Center the window
CenterWindow hDlg
'Assign the initial values to the dialog
SetWindowText GetDlgItem(hDlg, 101), gText
SetWindowText GetDlgItem(hDlg, 102), gDefault
SetWindowText hDlg, gCaption
FUNCTION = 1
EXIT FUNCTION
CASE %WM_COMMAND
SELECT CASE wParam
CASE 103, %IDOK
'When the "OK" button is pressed, get the edit box value
' and end the dialog
GetWindowText GetDlgItem(hDlg, 102), gDefault, 255
EndDialog hDlg, 1
FUNCTION = 1
EXIT FUNCTION
'When the "CANCEL" button is pressed, or escape is pressed, or
' the dialog is closed, end the dialog
CASE 104, %IDCANCEL
EndDialog hDlg, 0
FUNCTION = 1
EXIT FUNCTION
END SELECT
END SELECT
END FUNCTION
INPUTST.BAS
Code:
'
' Example of calling a DLL which has a modal dialog resource
'
' Modal Dialog is a generic input box
'
$COMPILE EXE
DECLARE FUNCTION MessageBox LIB "USER" (BYVAL hWnd AS WORD, lpText AS ASCIIZ, lpCaption AS ASCIIZ, BYVAL wTYPE AS WORD) AS INTEGER
DECLARE FUNCTION InputBox LIB "INPUTBOX" (Question AS ASCIIZ,
Caption AS ASCIIZ,
Default AS ASCIIZ) AS INTEGER
FUNCTION WinMain (BYVAL hCurInstance AS INTEGER, _
BYVAL hPrevInstance AS INTEGER, _
lpCmdLine AS ASCIIZ, _
BYVAL nCmdShow AS INTEGER) AS INTEGER
DIM Answer AS ASCIIZ * 255
'Set default answer value
Answer = "Dave Navarro"
'Call the DLL with the modal dialog
IF InputBox("Enter Complete User Name", "User Name Dialog", Answer) THEN
'Display the result
MessageBox 0, "You entered: " + Answer, "Input Box DLL Test", 0
ELSE
MessageBox 0, "Cancel was pressed!", "Input Box DLL Test", 0
END IF
END FUNCTION
INPUTBOX.RC
Code:
#include "resource.h"
INPUTBOX DIALOG PRELOAD 104, 59, 209, 79
STYLE DS_MODALFRAME | WS_POPUP | WS_VISIBLE | WS_CAPTION | WS_SYSMENU
CAPTION "Input Box"
FONT 8, "MS Sans Serif"
BEGIN
CTEXT "Message", 101, 4, 13, 203, 8
EDITTEXT 102, 2, 31, 205, 12, ES_AUTOHSCROLL | WS_GROUP | WS_TABSTOP
DEFPUSHBUTTON "&Ok", 103, 35, 54, 40, 14, WS_TABSTOP
PUSHBUTTON "&Cancel", 104, 128, 54, 40, 14, WS_TABSTOP
END
VERSIONINFO_1 VERSIONINFO
FILEVERSION 1, 0, 0, 0
PRODUCTVERSION 1, 0, 0, 0
FILEOS VOS_DOS_WINDOWS16
FILETYPE VFT_APP
BEGIN
BLOCK "StringFileInfo"
BEGIN
BLOCK "040904E4"
BEGIN
VALUE "CompanyName", "PowerBASIC, Inc.\000"
VALUE "FileDescription", "Dynamic Link Library\000"
VALUE "FileVersion", "01.00.0000\000"
VALUE "InternalName", "INPUTBOX.DLL\000"
VALUE "LegalCopyright", "Copyright (c) 1996 PowerBASIC, Inc.\000"
VALUE "LegalTrademarks", "PowerBASIC is a trademark of PowerBASIC, Inc.\000"
VALUE "ProductName", "PB/DLL Compiler for Windows\000"
VALUE "ProductVersion", "01.00.0000\000"
VALUE "Comments", "Generic Input Box Example for PB/DLL.\000"
END
END
END
MKINPUT.BAT
Code:
@echo on
rem ** Compile the DLL and the test executable
pbdll modal.bas
pbdll modaltst.bas
rem ** Add the resource dialog to the DLL
rc modal.rc modal.dll
We process personal data about users of our site, through the use of cookies and other technologies, to deliver our services, and to analyze site activity. For additional details, refer to our Privacy Policy.
By clicking "I AGREE" below, you agree to our Privacy Policy and our personal data processing and cookie practices as described therein. You also acknowledge that this forum may be hosted outside your country and you consent to the collection, storage, and processing of your data in the country where this forum is hosted.
Comment