cpp

How To Change The Background Color Of A Memo In An FMX C++ App

C++ Builder is the easiest and fastest C++ IDE for building professional FMX C++ Apps with powerful GUI components like Memo, Edit, ListBox, StringGrid, and many more. Each component can be skinned with Styles to change their visual appearance. Styles are very powerful and because of this it can sometimes take a little to get used to how they work. In this post, we explain how to change the background color of a Memo (TMemo), one of the most frequently asked questions about using styles. These methods below can be applied to other components too. How to change the background color of a Memo in C++ Builder by using Styles? Styles are sets of graphical details that define the look and feel of an application. They are one of the most beautiful and useful UI features of RAD Studio that can really add some extra professionalism to your apps. RAD Studio’s C++ Builder version comes with the award-winning VCL framework for high-performance native Windows apps (not wrapped in some kind of runtime interpretation layer) and the powerful FireMonkey (FMX) framework for cross-platform UIs. Both VCL and FMX C++ Apps support Styles. There are many styles in C++ Builder, and RAD Studio. More details about Styles can be found here. You can also find Premium Styles here. If you want to learn how you can modernize your components with styles this post has some great details; What are the steps to change the background color of a Memo in C++ Builder by using Styles? 1. Right-click on the Memo and select ‘Edit Custom Style…’ 2. Expand Memo1Style: you’ll see the background node. Click on background to select it. Then add a TRectangle via the Palette. The IDE should expand the background node and show a new Rectangle1Style tied to the TRectangle, 3. Via the Object Inspector change the Color of TRectangle as below 4. Click on the Apply Style button in the ‘Style Designer’, Save All. 5. Compile and run your application If you still have problems setting the color, this DocWiki article can help you: https://blogs.embarcadero.com/edit-custom-style-to-change-the-background-color-of-a-fmx-tedit/ How to change the background color of a Memo in C++ Builder code? If you want to change the background color of a Memo component (TMemo) in C++ Builder, first you should set the StyleLookup to “Memostyle” as shown below: Memo1->StyleLookup = “Memostyle”; If you look at the Custom Style of Memo, There is a “background” property, so we should find this resource by using FindStyleResource() method of Memo as given in the example below: Memo1->StyleLookup = “Memostyle”; auto fmxobj = Edit1->FindStyleResource(“background”, false); If this resource object we can create a rectangle (TRectangle) as a background: std::unique_ptr<TRectangle> rect(new TRectangle(fmxobj)); Here we used unique_ptr which more modern to create this rectangle. Now we can set properties of our Rectangle, including its color. rect->Align = TAlignLayout::Client; rect->Fill->Color = color; rect->Stroke->Color = color; // = claNull; rect->HitTest = false; rect->SendToBack(); Now, at last we need to add this object by using the .get() method of unique_ptr. And the final trick here is you must release this unique_ptr by using .release() otherwise it doesn’t have any effect. fmxobj->AddObject(rect.get()); rect.release(); Is there a full example of how to change the background color of a Memo in C++ Builder code? Here is a full C++ Builder FMX FMX C++ Apps example that changes the color of 3 TMemo components that has Memo1, Memo2, Memo3 names. To do this we create a ChangeMemoColor() function that uses the […]

Read More

How To Use A Game Pad Or Joystick Controller In C++ On Windows

C++ On Windows is one of the most powerful programming languages that we use for all sorts of purposes, from regular applications, games, business, industrial infrastructure, robotics, and in the control of IoT devices. The most well-known controllers for those areas where human and computer interaction are important and stretches beyond simple keyboard input are joysticks or gamepads. One of the simplest examples to use them on Windows is using the venerable XInput library which has been around for quite a long time but can still be easily used with the latest C++ Compiler. In this post, we explain how you can use a gamepad or joystick controller in C++ On Windows with Xinput library. Is there a component for the gamepad or joystick in C++ On Windows? If you are looking for a ready-to-use component library, there are Delphi and C++ Builder-compatible components built on the XInput library. For example, the Controller library is a Delphi and C++ Builder component that allows applications to receive input from an Xbox Controller. The main features of this library are, Uses Windows XInput API. Available for Delphi/C++ Builder 6 – 11 and Lazarus 2.0.12. Source code included in the registered version. Royalty free distribution. You can download the trial version of the XInput library or you can buy a professional edition from Winsoft.sk. How can I control a gamepad or joystick in C++ with the Xinput Library? The XInput library is deprecated but it still supported by Microsoft. They recommend moving towards the GameInput library or Windows.Game.Input for Windows applications. If we look at these kinds of libraries (i.e GamePad.h library), like MS’ own DirectXTK, we can see that the toolkit allows one to define USING_XINPUT vs. USING_GAMEINPUT vs. USING_WINDOWS_GAMING_INPUT to pick which underlying library is used. If we compare  XInput compared to GameInput: XInput library is fairly old and easy to implement Windows applications. XInput library is limited to 4 controllers. XInput library has no uniform interface to other inputs (like mouse/keyboard). XInput library input occurs with higher latency. XInput library is not friendly with other controllers. i.e. no support for Xbox One Rumble Motors. So, briefly, DirectInput is a better long-term choice than XInput. If you still want to use XInput, you can read more about https://learn.microsoft.com/en-us/windows/win32/xinput/getting-started-with-xinput XINPUT_GAMEPAD structure (declared in ) is explained here : https://learn.microsoft.com/en-us/windows/win32/api/xinput/ns-xinput-xinput_gamepad As in there, this structure has these members: wButtons, bLeftTrigger, bRightTrigger, sThumbLX, sThumbLY, sThumbRX, sThumbRY. Here wButtons member is used as a bitmask of the device digital buttons, it can be used as below, wButtons Device digital button flags Gamepad Bitmask XINPUT_GAMEPAD_DPAD_UP 0x0001 XINPUT_GAMEPAD_DPAD_DOWN 0x0002 XINPUT_GAMEPAD_DPAD_LEFT 0x0004 XINPUT_GAMEPAD_DPAD_RIGHT 0x0008 XINPUT_GAMEPAD_START 0x0010 XINPUT_GAMEPAD_BACK 0x0020 XINPUT_GAMEPAD_LEFT_THUMB 0x0040 XINPUT_GAMEPAD_RIGHT_THUMB 0x0080 XINPUT_GAMEPAD_LEFT_SHOULDER 0x0100 XINPUT_GAMEPAD_RIGHT_SHOULDER 0x0200 XINPUT_GAMEPAD_A 0x1000 XINPUT_GAMEPAD_B 0x2000 XINPUT_GAMEPAD_X 0x4000 XINPUT_GAMEPAD_Y 0x8000 How to use a gamepad or joystick in C++? If you wonder how XInput library works, you can create a simple example as in given steps below. First, we need library header to use XInput library. This is how you can use XInput library in C++. #include #include #include #pragma comment(lib, “XInput.lib”) Now, lets create a TController class that have n for the controller number and state for it. Here is an example. class TController { private: int n; XINPUT_STATE state; public:             // add controller methods here }; Then we need to add some methods for this class, first lets set our private controller number n in construction like […]

Read More

The best programming languages to learn in 2022

One of the challenges for people pursuing a career in programming is deciding which languages to learn. With so many languages used for different purposes, choosing the ones you want to study will depend on the specialty that most interests you as well as on job demand. A report released on Tuesday by programming course site CodingNomads looks at the “best” programming languages for 2022. If you’re excited by the data and logic side of coding, you may wish to learn Python, Java, C, C++ or C#. If you’re jazzed about visual design and user interfaces, TypeScript might be up your alley. And if you’re looking to develop mobile apps, you’d want to check out Java for Android, and Swift or Objective-C for Apple’s iOS. Aside from satisfying your own professional interests, you naturally want to select a language that’s in demand among employers and promises a good salary. In this regard, CodingNomads examined the most popular languages based on job postings and on salary. Looking at the greatest number of job postings on LinkedIn across the U.S. and Europe, CodingNomads awarded the top spot to Python. In second place was Java, with JavaScript, C++, C#, C, TypeScript, PHP, Perl and Ruby rounding out the top 10. Analyzing the average salaries of the most in-demand languages according to data from Indeed and Glassdoor, CodingNomads put Ruby in first place with an average salary in the U.S. of $111,994. C++ came in second with a salary of $103,818. The other languages and their salaries were Python at $103,540, JavaScript/TypeScript at $100,492, Java at $96,786, C# at $89,203, PHP at $85,435, Perl at $83,159 and C at $82,924. TypeScript was not listed separately because it had limited salary data. But CodingNomads deemed its salary similar to that for JavaScript jobs. Also, these figures are considered average salaries and not what beginning programmers would earn. But successful coders can expect to meet or beat these salaries within a couple of years, according to the report. Python is the best programming languages 2022 As a general purpose, server-side language, Python is used for a variety of tasks from simple scripting to advanced web applications and artificial intelligence. For developers interested in data science or machine learning as well as overall software development and web development, Python is the best language to learn, according to CodingNomads. “While Python has been around for decades, the demand for Python skills in 2022 will continue growing exponentially thanks to its use in the booming industries of data science, machine learning and AI,” said Ryan Desmond, co-founder and lead instructor at CodingNomads. “In addition, Python is considered one of the easiest, most powerful, and most versatile languages to learn, making it popular amongst companies, developers, and aspiring developers.” Java A respected and time-tested language, Java is widely used by organizations around the world. Java is the main language behind Android, which owns an 85% share of the mobile market. It’s also the most popular language for Internet of Things (IoT) devices. Java is considered harder to learn than Python but easier than C or C++, according to CodingNomads. The main reason is that Java improved on C, and Python improved on Java. On the plus side, once you master Java, learning something like Python will be much easier. Anyone who wants […]

Read More

C++ Builder Multi-Device application with Platform APIs

C++ Builder Multi-Device application provides three levels of development: ⦁ Components (VCL and FMX)⦁ Common Libraries (RTL).⦁ Platform APIs (iOS, Android, Mac OS) In this post we will discuss and show how to use the Platform APIs (iOS, Android, Mac OS). Specifically, we’ll look at how to use the iOS APIs to obtain Apple iOS device information for the Operating System (OS) version, the OS name and the iOS device type. Some refer to this as being able to ‘Touch the Metal’ of the device, meaning having access to the low level APIs of the device. The C++ Builder Run Time Library (RTL) includes a number of header files that provide C++ interfaces to the iOS frameworks written in Objective-C. And C++ Builder has the same for Android for the Java Libraries for Android, to allow you to access the APIs of the Android Java libraries from your native C++ code. For Apple IOS, using C++ Builder, these units are scoped with iOSapi and are installed by default in your installation folder \include\ios\rtl.  For Example: The complete list of these units are listed on this C++ Builder DocWiki page iOS Objective-C Frameworks (iOSapi) The C++ Builder FireMonkey framework relies on some of these units. For help on these iOS APIs, you can see the Apple documentation at iOS Developer Library To get to the iOS device information we need, we will need to use the iOS Objective-C Framework for:  iOSapi.UIKit.hpp Note:  The iOSapi.UIKit.hpp also includes the iOSapi.Foundation.hpp and the Macapi.Helpers (Macapi.ObjectiveC.hpp): 123 #define Iosapi_UikitHPP#include <iOSapi.Foundation.hpp>#include <Macapi.ObjectiveC.hpp> Here are steps to create a C++ Builder Multi-Device application to display Apple iOS device information for the Operating System (OS) version, the OS name and the iOS device type: Create a new C++ Builder Multi-Device application, BLANK. Target Platform = iOS 64-bit. Save Project in a new Folder, such as /Projects/CppiOSDeviceInfo Use Project | Options | Deployment | Provisioning, to select your Apple Provisioning Profile and your Developer Certificate: 4. Use Project | Options | Application | Version Info | to enter your unique Application Identifier for the CFBundleIdentifier: Q4X27M46Z4.$(ModuleName) 5. In our C++ Builder Multi-Device iOS application, we will include this one header file:  #include <iOSapi.UIKit.hpp> 1234 #include <fmx.h>#include <iOSapi.UIkit.hpp>  // iOS Device information#pragma hdrstop#include “uMain.h” 6. For the User Interface (UI), create a UI that look like this: 7. To create this UI, follow these steps: On your Blank form in your new C++ Builder Multi-Device application: a. Add a Toolbar, property Align = Top. b. On the Toolbar, add a Button, Align = Right. Button Name = btnGetDeviceInfo. StyleLookup = refreshtoolbuttonbordered. c. On the Toolbar, add a Label, Align = Contents. Label->Text = Device Information d. To display the iOS Device information we will use a ListBox. Add ListBox to the form. Align = Top. e. To the ListBox, add three (3) ListBoxItems, to display the OS version, the OS name and the iOS device type.  To do this, in the Structure Pane, Right-click on ListBox1, Items Editor, Select ListBoxItem from the dropdown, Click Add item button 3 times. Rename ListBoxItem’s TEXT values as OS Name:, Device Type:, and OS Version, and ListBoxItem.Name = lbOSName , lbDeviceType, and lbOSVersion , respectively. 8. You can now double-click on the button for GetDeviceInfo and for it’s OnClick Event Handler, and you can use the functions and methods in the iOSapi UIKit header file to get OS information from our iOS device. 9. First, in your C++ Builder IDE, lets look at the iOSapi.UIKit.hpp header file.  In the IDE Editor, select the iOSapi.UIKit.hpp | Right-Click | Open File At Cursor.  This should open the iOSapi.UIKit.hpp header file in the Editor. 10. Looking at the “Methods Insite” dropdown, […]

Read More