PowerBASIC Forums
  Source Code
  PB/WIN 7, Data input form and API trix..

Post New Topic  Post A Reply
profile | register | preferences | faq | search

UBBFriend: Email This Page to Someone! next newest topic | next oldest topic
Author Topic:   PB/WIN 7, Data input form and API trix..
Borje Hagsten
Member
posted May 06, 2003 05:00 PM     Click Here to See the Profile for Borje Hagsten     Edit/Delete Message   Reply w/Quote

'¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤
' Small sample of data input form. Textbox in focus is framed.
' Enter-key moves focus to next textbox, and closes dialog if
' Exit button has focus. Just to show some useful API tricks..
' Public Domain by Borje Hagsten, May 2003.
'¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤
' Declares
'--------------------------------------------------------------------
#COMPILE EXE
#INCLUDE "WIN32API.INC"
'--------------------------------------------------------------------
%IDC_LABEL1 = 140
%IDC_TEXT1 = 141
%IDC_LABEL2 = 142
%IDC_TEXT2 = 143
%IDC_LABEL3 = 144
%IDC_TEXT3 = 145
'--------------------------------------------------------------------
DECLARE CALLBACK FUNCTION DlgProc() AS LONG
DECLARE SUB FrameControlInFocus (BYVAL hDlg AS DWORD, BYVAL hWnd AS DWORD, _
BYVAL clr AS DWORD)

'¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤
' Program entrance
'--------------------------------------------------------------------
FUNCTION WINMAIN (BYVAL hInst AS DWORD, BYVAL hPrevInstance AS DWORD, _
BYVAL lpszCmdLine AS ASCIIZ PTR, BYVAL nCmdShow AS LONG) AS LONG

LOCAL hDlg AS DWORD

DIALOG NEW 0, "Data Input",,, 220, 120, _
%WS_CAPTION OR %WS_SYSMENU, 0 TO hDlg

CONTROL ADD LABEL, hDlg, %IDC_LABEL1, "&Name", 6, 7, 50, 9
CONTROL ADD TEXTBOX, hDlg, %IDC_TEXT1, "", 5, 17, 100, 13

CONTROL ADD LABEL, hDlg, %IDC_LABEL2, "&City", 6, 34, 50, 9
CONTROL ADD TEXTBOX, hDlg, %IDC_TEXT2, "", 5, 44, 100, 13

CONTROL ADD LABEL, hDlg, %IDC_LABEL3, "&Phone", 6, 61, 50, 9
CONTROL ADD TEXTBOX, hDlg, %IDC_TEXT3, "", 5, 71, 100, 13

CONTROL ADD BUTTON, hDlg, %IDCANCEL, "E&xit", 164, 101, 50, 14

DIALOG SHOW MODAL hDlg, CALL DlgProc

END FUNCTION

'¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤
' Main Dialog procedure
'--------------------------------------------------------------------
CALLBACK FUNCTION DlgProc() AS LONG

SELECT CASE CBMSG
CASE %WM_INITDIALOG
STATIC sthText AS DWORD, stCol AS LONG 'to store handle and color for %WM_PAINT

CASE %WM_PAINT 'must be able to repaint if dialog has
IF sthText THEN 'been covered/uncovered by something else.
FrameControlInFocus CBHNDL, sthText, stCol
END IF

CASE %WM_COMMAND
SELECT CASE CBCTL
CASE %IDC_TEXT1 TO %IDC_TEXT3 'textboxes only
SELECT CASE CBCTLMSG
CASE %EN_SETFOCUS 'a textbox has got focus, draw frame
stCol = RGB(255,0,0) 'store color and handle for eventual %WM_PAINT
sthText = CBLPARAM
FrameControlInFocus CBHNDL, sthText, stCol

CASE %EN_KILLFOCUS 'we are leaving a textbox, so wipe out drawn rect
FrameControlInFocus CBHNDL, CBLPARAM, GetSysColor(%COLOR_3DFACE)
sthText = 0 'reset handle, we don't need to repeat this under WM_PAINT
END SELECT

CASE %IDOK 'Enter key triggers IDOK in dialogs - let's use that fact..
IF GetDlgCtrlId(GetFocus) = %IDCANCEL THEN 'if exit button
DIALOG END CBHNDL, 0 'whatever..
ELSE 'else textbox - move to next
SetFocus GetNextDlgTabItem(CBHNDL, GetFocus, 0)
END IF

CASE %IDCANCEL
IF CBCTLMSG = %BN_CLICKED OR CBCTLMSG = 1 THEN
DIALOG END CBHNDL, 0
END IF
END SELECT

END SELECT

END FUNCTION

'¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤
' Draw a rectangle around any given control
'--------------------------------------------------------------------
SUB FrameControlInFocus (BYVAL hDlg AS DWORD, BYVAL hWnd AS DWORD, _
BYVAL clr AS DWORD)
LOCAL hDC AS DWORD, hBrush AS DWORD, hPen AS DWORD, rc AS RECT

GetWindowRect hWnd, rc 'get control's pos and size on screen
MapWindowPoints 0, hDlg, rc, 2 'map rect to dialog
InflateRect rc, 2, 2 'increase slightly to draw around control

hDC = GetDc(hDlg) 'use dialog's DC since we want to paint on dialog
hPen = CreatePen(%PS_SOLID, 1, clr) 'create a pen for given color
hPen = SelectObject(hDC, hPen) 'select the new pen into the DC
hBrush = SelectObject(hDC, GetStockObject(%NULL_BRUSH)) 'use stock null brush for hollow rect

Rectangle hDC, rc.nLeft, rc.nTop, rc.nRight, rc.nBottom 'draw the rectangle

SelectObject hDC, hBrush 'return original pen and brush, then release DC
DeleteObject SelectObject(hDC, hPen)
ReleaseDc hDlg, hDC

END SUB


------------------
http://www.tolkenxp.com/pb
Download: incLean, PBcodec, custom controls and code, etc.
Borje Hagsten - pb@tolkenxp.com

[This message has been edited by Borje Hagsten (edited May 06, 2003).]

IP: Logged

All times are EasternTime (US)

next newest topic | next oldest topic

Administrative Options: Close Topic | Archive/Move | Delete Topic
Post New Topic  Post A Reply
Hop to:

Contact Us | PowerBASIC BASIC Compilers

Copyright © 1999-2005 PowerBASIC, Inc. All Rights Reserved.


Ultimate Bulletin Board 5.45c