April 30, 2004 From: Bob Zale, President PowerBASIC, Inc. PowerBASIC Gazette #40 - Please share with fellow programmers ============================================================= Subject: What about those Windows Controls? ============================================ Windows Controls. An essential part of Windows GUI programming. But do any of us really know all there is to know about them? Even the standard controls like Buttons and TextBoxes? Of course not! So here's the first in a series of overviews... whether you're a novice or pro, it's probably worth your while to review all the info you can find! But first, would you indulge me? Would you help us spread the word about PowerBASIC? You know, you're the world's best PowerBASIC advertisement. And every time we add a PowerBASIC customer, it helps us all. Every new user is an investment in the future... with more users, we'll create better products, deliver them sooner, and keep the pricing right for you. How about it? Will you tell a friend about PowerBASIC? I hope so. We'll make it easy for you to "Share the Power"! {smile} Anyway, here's the plan... You give us a name (or a few names), and we'll send just one short, informative e-mail under your name and ours. We won't follow up. We'll never use their e-mail again, unless they choose to sign up. So, Share the Power! Just GoTo... http://www.powerbasic.com/bin/ps.exe You'll see the text of the message and add a contact name! The message is harmless, yet informative. And just think of the compilers we could build for you if everyone brought us just one new PowerBASIC user! TextBox - Tips and Tricks - by Borje Hagsten ===================================================================== The TextBox is a standard Edit control, used as both single-line text input fields and multi-line text editors, like NotePad. It can handle one font type and font size for all text and has a single-step undo level for last edit action. In Windows 95/98/Me, a multi-line textbox has ~32KB max text size limit. In later systems the limit is ~2.1 GB. A blinking, vertical caret shows the current insert position. The creation of a TextBox and the different styles it can be given is well described in the PB/WIN help file, under CONTROL ADD TEXTBOX. In addition to this, there is also a range of API messages available for changing its appearence after creation. Let's take a look at some of them - to be used with CONTROL SEND, like: ' %EM_LIMITTEXT ' Limit the amount of text a user can enter into an edit control. ' wParam sets the new limit. If wParam = 0, the default text limit ' is set. In Windows 95/98/Me, the default text limit is 32,766 ' characters, while in Windows NT/2000/XP, the default text limit ' is 2,147,483,646 characters. ' Example - to limit user input to max of 8 characters: ' - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - CONTROL SEND hDlg, %IDC_TEXTBOX1, %EM_LIMITTEXT, 8, 0 ' ----------------------------------------------------------------- ' %EM_SETRECT ' Set the formatting rectangle of a multiline edit control. ' Example - to shrink the formatting rectangle by 5 pixels, which ' gives the control a 5 pixel margin on left and right sides: ' - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - LOCAL rc AS RECT CONTROL SEND hDlg, %IDC_TEXTBOX1, %EM_GETRECT, 0, VARPTR(rc) InflateRect rc, -5, 0 CONTROL SEND hDlg, %IDC_TEXTBOX1, %EM_SETRECT, 0, VARPTR(rc) ' ----------------------------------------------------------------- ' %EM_SETTABSTOPS ' Change the default tab stop positions. ' Note: To insert tab characters via the keyboard, press Ctrl+Tab. ' The default tab stops are set at every 32 dialog box units. ' Example 1 - change default tab stop positions from 32 to 64: ' - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - CONTROL SEND hDlg, %IDC_TEXTBOX1, %EM_SETTABSTOPS, 1, 64 ' ----------------------------------------------------------------- ' Example 2 - use an array to set your own specific positions for ' tab stops. Here we set 4 tab stops, at 16, 32, 80 and 140 dialog ' box units. This method can be useful for creating "columns" with ' desired widths in TAB$ delimited text, showing some specific data ' type (for example, numeric, with known digit limits). ' - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - REDIM tbs(1 TO 4) AS LONG tbs(1) = 16 tbs(2) = 32 tbs(3) = 80 tbs(4) = 140 CONTROL SEND hDlg, %IDC_TEXTBOX1, _ %EM_SETTABSTOPS, UBOUND(tbs), VARPTR(tbs(1)) --------------------------------------------------------------------- Command messages - talking to a TextBox --------------------------------------------------------------------- Aside from the DDT commands CONTROL GET/SET TEXT, we can also use a range of API messages together with CONTROL SEND to master the control. The following is a collection of solutions to questions often asked in the PB support forums. For a complete list of commands, see Win32.hlp or the SDK information available at for example http://msdn.microsoft.com We'll begin with the commands in the TextBox's right-click popup menu. Sometimes it can be necessary to perform these actions via code instead, so here we go: ' Undo the latest edit operation CONTROL SEND CBHNDL, %IDC_TEXTBOX1, %EM_UNDO, 0, 0 ' Cut out selected text to the ClipBoard CONTROL SEND CBHNDL, %IDC_TEXTBOX1, %WM_CUT, 0, 0 ' Copy selected text to the ClipBoard CONTROL SEND CBHNDL, %IDC_TEXTBOX1, %WM_COPY, 0, 0 ' Insert text from the ClipBoard at the caret's place CONTROL SEND CBHNDL, %IDC_TEXTBOX1, %WM_PASTE, 0, 0 ' Delete selected text CONTROL SEND CBHNDL, %IDC_TEXTBOX1, %WM_CLEAR, 0, 0 ' Select all text CONTROL SEND CBHNDL, %IDC_TEXTBOX1, %EM_SETSEL, 0, -1 ' ----------------------------------------------------------------- ' Note: if not created with %ES_NOHIDESEL style, a TextBox ' will need to have focus for a selection to be shown. Use ' CONTROL SET FOCUS CBHNDL, %IDC_TEXTBOX1 to give it focus. ' ----------------------------------------------------------------- ' Select a part of a text. nStart/nEnd are zero-based positions. ' Tip: to move the caret without selecting any text, or to reset ' a selection, let nStart and nEnd have the same value. CONTROL SEND CBHNDL, %IDC_TEXTBOX1, %EM_SETSEL, nStart, nEnd ' Scroll the caret into view (often useful after %EM_SETSEL) CONTROL SEND CBHNDL, %IDC_TEXTBOX1, %EM_SCROLLCARET, 0, 0 ' Replace selected text, or insert text at the caret's position CONTROL SEND CBHNDL, %IDC_TEXTBOX1, %EM_REPLACESEL, 1, STRPTR(sTxt$) --------------------------------------------------------------------- Finally, one of the most common questions -- always worth repeating: How to trap the Enter key in a single-line TextBox. --------------------------------------------------------------------- The Enter key triggers a default control id in dialogs, usually %IDOK, unless a button with another id has been created with BS_DEFPUSHBUTTON style, or the default control id has been changed via the %DM_SETDEFID message. We can trap this default id under WM_COMMAND in the dialog procedure and use a call to GetFocus to see which control has focus when Enter is pressed. This can be useful in data input forms, etc. SELECT CASE CBMSG CASE %WM_COMMAND SELECT CASE CBCTL CASE %IDOK ' <- def. dialog id - change if needed IF CBCTLMSG = %BN_CLICKED OR CBCTLMSG = 1 THEN SELECT CASE GetDlgCtrlId(GetFocus) 'where is focus? CASE %IDC_TEXTBOX1 ' this TextBox has focus - do whatever needed CASE ELSE ' some other control has focus END SELECT END IF END SELECT END SELECT Note: it is also possible to use keyboard accelerators to trap desired keys and perform actions in a control. See ACCEL ATTACH in PB/WIN help. ======================================================================= ======================================================================= If you haven't yet acquired all three PowerBASIC Compilers, now might be a good time to look a bit further. Pricing remains unchanged at the most competitive levels known in our industry. PB/CC is our Console Compiler -- with a text mode interface to 32-bit Windows. PB 7 for Windows is oriented towards a GUI (graphical user interface) for a typical Windows "look and feel". With all of the new extensions, you won't believe how easy it is to build real GUI applications! PB/Forms is our new, state-of-the-art visual designer. It works with PowerBASIC 7 to build GUIs almost as fast as you can imagine them. More information? Sure, it's very simple. Just click to go to each or all of the PowerBASIC product pages... PB/CC 3.0: http://www.powerbasic.com/products/pbcc/ PB/WINDOWS 7.0: http://www.powerbasic.com/products/pbdll32/ PowerBASIC Forms1.5: http://www.powerbasic.com/products/pbforms/ PowerTREE: http://www.powerbasic.com/products/powertree/ Graphics Tools: http://www.powerbasic.com/products/graftool/ SQL Tools: http://www.powerbasic.com/products/sqltools/ Console Tools: http://www.powerbasic.com/products/contools/ PB/WIN 7.0 is attractively priced at $199.00, while PB/CC 3.0 is just $169.00. Upgrades from the prior versions are just $99 and $89. PowerBASIC Forms is priced at $99, and upgrades from 1.0 are just $39. Graphics Tools Standard and Pro are $69.95 and $139.95. You can order with ease by just replying to this e-mail. You can call us at (888) 659-8000 or (941) 473-7300, fax us at (941) 681-3100, place an electronic order on our web site (http://www.powerbasic.com), or even mail it in. But no matter the method you choose, please do it today and do it with confidence. Every product PowerBASIC shipped for physical delivery is offered with a money-back guarantee for 30 days from the transaction date. Regards, Bob Zale, President PowerBASIC Inc. =================================================================== PowerBASIC Price List ------------------------------------------------------------------- PB/CC Console Compiler 3.0 - Full Product $169.00 PB/CC Console Compiler 3.0 - Upgrade from vs 2 89.00 PB/CC Console Compiler 3.0 - Upgrade from vs 1 119.00 Add Printed Documentation 39.00 ------------------------------------------------------------------- PowerBASIC for Windows 7.0 (GUI) - Full Product $199.00 PowerBASIC for Windows 7.0 - Upgrade from ver 6 99.00 PowerBASIC for Windows 7.0 - Upgrade from prior versions 129.00 Add Printed Documentation 39.00 PowerBASIC Forms Visual Design Tool for PB/Win 7 99.00 PowerBASIC Forms Visual Design Tool - Upgrade from 1.0 39.00 ------------------------------------------------------------------- PowerBASIC for DOS 3.5 - Full Product $99.00 PowerBASIC for DOS 3.5 - Upgrade from prior versions 49.00 Add Printed Documentation (2 book set) 29.00 ------------------------------------------------------------------- PowerTree BTree Manager for DOS and Windows $99.00 PB/Vision for DOS 20.00 PB/Xtra III for DOS and Windows 49.00 ------------------------------------------------------------------- Graphics Tools Standard ver 2 $69.95 Graphics Tools Professional ver 2 139.95 Console Tools Standard 49.95 Console Tools Professional 99.95 SQL Tools Standard Version 99.95 SQL Tools Professional Version 199.95 ------------------------------------------------------------------- Shipping/Handling costs: Software & Each Any Software 1 or 2 books Addl Book E-mail $6 N/A N/A UPS Ground/Mail US $10 $10 $6 Fedex 2-day US $16 $16 $6 Fedex 1-day US $28 $28 $6 Air Mail Canada/Mex $12 $22 $6 Air Mail Intl $16 $28 $6 Fedex Intl $34 $44 $6 Fedex International Rates are for Western Europe, Pacific Rim, Asia, and North America. Others please request a quotation. ------------------------------------------------------------------- Order online at https://www.powerbasic.com/shop/ (secure server) or just send an e-mail with all pertinent information to sales@powerbasic.com and we'll take it from there! ------------------------------------------------------------------- Most PowerBASIC products (those without printed books) can now be delivered by electronic mail. No wait for a package to arrive... No high shipping costs... For just $6 per order, no matter how many products, we'll deliver directly to your computer. If you're outside the U.S., savings might be greater. You won't pay taxes or duties to a freight company or postal service because they aren't involved in the delivery. Check your tax code to be sure, but some countries charge no tax at all on transactions like this. It could just be your lucky day! ==================================================================== Is your PowerBASIC Gazette Electronic Edition subscription coming to you at home or work? If you don't want to miss a single issue, why not subscribe from both e-mail addresses? Send your subscription request to email@powerbasic.com and please include your name and all e-mail addresses you'd like to add as well as your Zip or Postal Code. If you know someone else who would enjoy this newsletter please forward a copy to them so they can subscribe. ==================================================================== All contents Copyright (c) 2004 PowerBASIC Inc All Rights Reserved. PowerBASIC is a registered trademark of PowerBASIC, Inc. PB/CC, PB/DLL, PB/Win, PowerTREE, and PowerBASIC Forms are trademarks of PowerBASIC Inc. Other names are trademarks or registered trademarks of their respective owners. ==================================================================== PowerBASIC Gazette - Electronic Edition Volume 1 - Issue 40 PowerBASIC, Inc. (888) 659-8000 Sales 2061 Englewood Road (941) 473-7300 Voice Englewood, FL 34223 (941) 681-3100 Fax Visit us on the World Wide Web at http://www.powerbasic.com Email PowerBASIC Sales: sales@powerbasic.com This newsletter is only sent to e-mail addresses in our subscription list. If you have received this newsletter by mistake or no longer wish to receive it, please send a simple unsubscribe request to gazette@powerbasic.com with your name and zip/postal code. ====================================================================