Skip to main content

Posts

Application Context Menus

Context menus (or "right-click popup" menus) come in two flavors: application-wide or control-specific. This article focuses on the former. Implementing the Application Popup Menu The first step in creating a context menu is simple: use the Visual Studio resource editor to create the menu you wish to display. Make sure that you give it a unique ID; I will use the value IDR_POPUP_MENU for this example. Add to the menu the various menu items that you want to include. Note that your context menu should only have one top-level item (under which all other menu items will be placed). The caption for this top-level item can be whatever you like since the user will never see it. If you are mapping menu items in this context menu to commands that already exist in the program (as is likely), make sure that you give each menu item the appropriate ID. For example, if the ID to my "Open File" command in my main application menu is ID_FILE_OPEN, I would give that same ID to the c
Recent posts

Advanced Windows Registry Access

If you are interested in how to access arbitrary locations in the Windows registry, this is the article for you. However, if you would prefer to learn a simpler method of registry access to store and retrieve program settings, consult my simple registry access article . Opening (Reading) Keys Unlike the simpler, application based method, we don't need to enable registry access via a special function call. Instead, the functions we will be using interface directly with the registry itself. Let's look at the code required to open an arbitrary key value:HKEY hKey; RegOpenKeyEx(HKEY_CURRENT_USER, TEXT("Control Panel\\Desktop"), 0, KEY_QUERY_VALUE, &hKey); As you can see, we are using the RegOpenKeyEx() function. Let's take a look at its various parameters: Parameter 1: A handle to a currently open key or any of the following predefined reserved handle values: HKEY_CLASSES_ROOT HKEY_CURRENT_CONFIG HKEY_CURRENT_USER HKEY_LOCAL_MACHINE HKEY_USERS HKEY_PERFORMANCE_DAT

Transferring Data From One Dialog Box to Another

In this exercise, we will learn how to exchange data from one dialog box to another. Start Microsoft Visual C++ On the main menu, click File -> New... Click the Projects property sheet and click MFC AppWizard (exe) In the Location box, specify a complete path for the folder, such as C:\Programs\MSVC In the Project Name: box, type ExoTransfer and click OK In the MFC AppWizard - Step 1, click the Dialog Based radio button. Click Finish and click OK Design the default dialog box by adding an Edit Box IDentified as IDC_FIRSTNAMEDLG1 Add a second Edit Box IDentified as IDC_LASTNAMEDLG1 Add one more Edit Box IDentified as IDC_FULLNAMEDLG1 Add a Button IDentified as IDC_CREATEACCOUNT and the Caption as C&reate Account... Set all three Edit controls read only by clicking the Read-Only check box of each (in the Edit Properties window). Press Ctrl + W to access the ClassWizard (I using Microsoft Visual C ++ 5/6 for this exercise and not MSVC .NET) Click Member Variables and Add Variabl

Simple Windows Registry Access

The Windows registry is an excellent place to store program information. From recent file lists to program settings, the registry provides programmers with a central location to store information for future use. Registry access can be quite simple, provided that you accept a few limitations. First, you must be willing to store your registry values on a per-user basis (rather than for all users). Second, you may only read and write values to your own application's registry branch. Poking around in arbitrary places in the Windows registry is somewhat more complicated than the method provided in this article. Do not assume that the constraints mentioned above render this method of registry access useless. I personally use this registry access method for all of my applications, using the advanced access method only when necessary. The simple method described below will do everything you need it to do for simple storage of application specific information. Enabling Registry Access The

Learn Visual C++ 2005

What Is Visual C++ 2005? Microsoft Visual C++ 2005 provides a powerful and flexible development environment for creating Microsoft Windows–based and Microsoft .NET–based applications. It can be used as an integrated development system, or as a set of individual tools. Visual C++ is comprised of these components: Visual C++ 2005 compiler tools - The compiler has new features supporting developers that target virtual machine platforms like the Common Language Runtime (CLR). There are now compilers to target x64 and Itanium. The compiler continues to support targeting x86 machines directly, and optimizes performance for both platforms. Visual C++ 2005 Libraries - This includes the industry-standard Active Template Library (ATL), the Microsoft Foundation Class (MFC) libraries, and standard libraries such as the Standard C++ Library, and the C RunTime Library (CRT), which has been extended to provide security enhanced alternatives to functions known to pose security issues. A new library,

Component Object Model FAQ's

1. What is IUnknown? What methods are provided by IUnknown? It is a generally good idea to have an answer for this question if you claim you know COM in your resume. Otherwise, you may consider your interview failed at this point. IUnknown is the base interface of COM. All other interfaces must derive directly or indirectly from IUnknown. There are three methods in that interface: AddRef, Release and QueryInterface. 2. What are the purposes of AddRef, Release and QueryInterface functions? AddRef increments reference count of the object, Release decrements reference counter of the object and QueryInterface obtains a pointer to the requested interface. 3. What should QueryInterface functions do if requested object was not found? Return E_NOINTERFACE and nullify its out parameter. 4. How can you create an instance of the object in COM? Well, it all depends on your project. Start your answer from CoCreateInstance or CoCreateInstanceEx, explain the difference between them. If interviewe

Visual C++ FAQs part-2

Q 1.01 Is there any function to minimize the window? A. ThatsAlok quoted :- If you are using MFC: this->ShowWindow(SW_MINIMIZE); If you are using Win32 API based application: ShowWindow(hWnd,SW_MINIMIZE); Q 1.02 How do I stop appearing of the SQL Sever login dialog again and again? A. renjith_sree quoted :- Use CDatabase::noOdbcDialog as the second parameter in OpenEx() method. E.g.: extern CDatabase oDb; extern CString csConnection; oDb.OpenEx(csConnection, CDatabase::noOdbcDialog ); This will suppress the login dialog. Q 1.03 How can I access USB port (COM 5)? A. Antti Keskinen quoted :- The USB is a bus that resides in the computer. The low-level drivers (supplied by Microsoft) allow the bus to enumerate and identify a piece of hardware and then send a request to the registry to find the correct function driver for the device by using the vendor and product IDs returned by the USB descriptors. This is how the bus works in a nutshell. Your computer systems might have a pseudo-devi