Click here to Skip to main content
15,892,253 members
Everything / Programming Languages / C++

C++

C++

Great Reads

by Dr. WPF
.NET 3.5 SP1 is here! It's time to break out your DirectX skills. This article provides the information necessary to get started using a new DirectX interop feature in WPF called D3DImage.
by Jeffrey Walton
Import and export Cryptographic Keys in PKCS#8 and X.509 formats, using Crypto++, C#, and Java.
by Hans Dietrich
XColorSpectrumCtrl displays a color spectrum that allows user selection, and provides APIs for color based on RGB and HSL color models.
by Hans Dietrich
XQueue implements a shared-memory first-in first-out (FIFO) queue, based on memory-mapped files, that works on all versions of Windows.

Latest Articles

by Gareth Richards
An implementation of the Neural Network backpropagation learning algorithm in C++ using the BLAS proposal in P1673.
by Shao Voon Wong
C++ SAX library to simplify XML parsing
by Shao Voon Wong
Tutorial on a cross-platform C++ XML DOM library
by Hatem Mostafa
Artificial Neural Network C++ class with two use cases: Counter and Handwritten Digits recognition

All Articles

Sort by Updated

C++ 

U 3 May 2024 by merano99
For a comprehensive evaluation of a program's performance, all relevant criteria must first be defined and prioritized. In addition to CPU utilization and memory consumption, for example, computing time is an important factor. Here it seems as if...
N 3 May 2024 by Richard MacCutchan
See CWnd Class OnVScroll | Microsoft Learn[^]
U 3 May 2024 by Papy@007
I am looking for a map implementation which is optimized than std::unordered_map in C++ interms of CPU and memory usage. What I have tried: I had tried the ankerl::unordered_dense_map ,few sites suggested its the fastest,but with my profiling I...
N 3 May 2024 by Member 14594285
I used void OnVScroll(UINT nSBCode, UINT nPos, CScrollBar* pScrollBar) to scroll my scrool bar but I don't know the event that I must use if I click on my scrollBar.. What I have tried: I tried to search on internet but I don't find
N 1 May 2024 by merano99
As others have said, it's important to start simple and then work your way to the solution step by step. Some knowledge of C++ is required, which can be acquired in this project using a practical example. Here are some basic first steps: 1....
N 1 May 2024 by KarstenK
So it is time to Learn C++ to get the job done. To kickstart your learning process you should profit from my 20+ year experience in How to start a Developer career. This will help you to avoid some common traps and give you some orientation. ...
N 1 May 2024 by Pete O'Hanlon
Writing an A* algorithm is a hard thing to do if you don't have a decent amount of programming knowledge already. If you don't have a good grasp of C++, then writing a relatively complex algorithm such as A* is going to be beyond you right now....
N 30 Apr 2024 by Member 16255147
How can you implement the A* algorithm in C++ to solve the 15 puzzle? What I have tried: I have been reading about the A* algorithm but do not know how implement it in C++
N 29 Apr 2024 by Gareth Richards
An implementation of the Neural Network backpropagation learning algorithm in C++ using the BLAS proposal in P1673.
U 28 Apr 2024 by Shao Voon Wong
C++ SAX library to simplify XML parsing
N 28 Apr 2024 by OriginalGriff
I would suggest that you go back to the github repository you started with, and ask there - we would have to fork / extract the source and try it locally to even start duplicating your problem and since we are likely to be even less familiar with...
N 28 Apr 2024 by Gbenbam
I wrote the following programs based on crypto++ as part of an application and tried to run the app after appropriately adding a crypto++ dynamic link library compiled from source code obtained from the official Crypto++ GitHub repository....
N 28 Apr 2024 by OriginalGriff
DeviceIoControl returns error code 50 when the requested operation is not supported by the device: System Error Codes (0-499) (WinError.h) - Win32 apps | Microsoft Learn[^] IIRC not all hard drives support serial numbers, so that may be your...
N 28 Apr 2024 by Gbenbam
The following program failed with GetLastError() returning code 50. What could be wrong? Please note the hard disk in question definitely has a serial number. BOOL GetDiskSerialNumber(std::wstring& wstSerialNumber, const TCHAR * wszPath) { ...
U 26 Apr 2024 by Shao Voon Wong
Tutorial on a cross-platform C++ XML DOM library
N 25 Apr 2024 by Daniel Pfeffer
HDCs are thread-specific. You are creating the HDC in your main thread, but using it in a child thread. This has always been forbidden in Windows.
U 24 Apr 2024 by merano99
To display an image with the correct aspect ratio on a button, you must first calculate a common scaling factor, rescale the image with it and finally crop it. The following function performs these steps. The image can be a file or a resource...
N 24 Apr 2024 by Richard MacCutchan
It is not clear what you are asking for but you have two choices. 1. Use cin multiple times, once for each item you want. 2. Use std::istream::getline - cppreference.com[^] to read a complete line of text and split it into its separate parts in...
U 24 Apr 2024 by Member 16250369
the user can't input multiple words with spaces. What I have tried: void createAccount() { string createUser, createPass; cout
U 23 Apr 2024 by Hatem Mostafa
Artificial Neural Network C++ class with two use cases: Counter and Handwritten Digits recognition
N 22 Apr 2024 by Richard MacCutchan
Something like this should do it. m_Btn1.ModifyStyle(0, BS_BITMAP); UINT style = m_Btn1.GetButtonStyle(); style &= ~BS_OWNERDRAW; // mask with all bits except owner draw m_Btn1.SetButtonStyle(style);
N 22 Apr 2024 by Member 14594285
if (PathFileExists(str_path)) { m_Btn1.ShowWindow(SW_SHOW); m_Btn1.ModifyStyle(0, BS_BITMAP); } else { m_Btn1.ModifyStyle(0, BS_OWNERDRAW); m_Btn1.Set_Art(m_pArt, 0); ...
U 22 Apr 2024 by Member 14594285
CBitmap bitmap; bitmap.Attach(image.Detach()); HBITMAP hBitmap6 = (HBITMAP)bitmap.GetSafeHandle(); m_Btn1.SetBitmap(hBitmap6); but image isn't proportionate to size of button but image of CButton isn't proportionate to size of my button ...
N 22 Apr 2024 by mbue
You called: if (dlg.DoModal() == IDOK) after that call you set pEditCtrl->SetWindowText(CString(pBuffer, nFileSize)); this must be done before (!) the dialog will be shown (DoModal).
21 Apr 2024 by Maryala Shreya
void CFileView::OnDoubleClick(NMHDR* pNMHDR, LRESULT* pResult) { NMITEMACTIVATE* pNMItem = (NMITEMACTIVATE*)pNMHDR; int nItem = pNMItem->iItem; if (nItem != -1) { ITEMINFO* pItem = (ITEMINFO*)GetListCtrl().GetItemData(nItem);...
21 Apr 2024 by Andre Oosthuizen
Your code seems to be correct for loading an image and setting it as the bitmap for your button button. As Rick stated, first check if the path you use is correct and if it is returning something, Add error handling and debugging statements to...
19 Apr 2024 by Member 14594285
I wrote: CImage image; image.Load(str_path); // just change extension to load jpg CBitmap bitmap; bitmap.Attach(image.Detach()); m_Btn1.SetBitmap(bitmap); m_Btn1.ShowWindow(SW_SHOW); str_path is the path of...
19 Apr 2024 by Rick York
I would guess it is because the image is not accessible to your program. Either give the image file name an explicit path or run your program in the directory where the image file is located. Actually, the first thing you should do is check the...
19 Apr 2024 by KarstenK
The conversion is as easy as already answered but you need to take care when making it to a COLORREF again. You need the same byte order and the same color depth. When you mismatch it the colors are weirdly changed. To better learn about working...
18 Apr 2024 by Michael Chourdakis
An introduction to machine learning with working C++ code that trains a linear regression model.
17 Apr 2024 by BernardIE5317
Greetings Kind Regards I am attempting to duplicate in C++ the work shown on Code Project article titled "International Number Formats" link below. My C++ code is shown below and output also. Each line of output is the number 123.56 in my global...
17 Apr 2024 by Dave Kreskowiak
You already posted this in the C/C++ forum. Don't spam the site with the same question in multiple places.
16 Apr 2024 by mbue
This code is obsolete since win2000 because every process has its own wave mapper. The code seems to try if the wave mapper (win95) is already in use - not a specific audio file. To try if a specific file is in use you should open the file...
16 Apr 2024 by Richard MacCutchan
COLORREF (Windef.h) - Win32 apps | Microsoft Learn[^]. As you can see it is defined as a DWORD (32 bits) so itis already an integer value.
16 Apr 2024 by Member 14594285
I tried to convert COLORREF to int but I don't find the correct way.. What I have tried: I tried to search on internet, but I don't find the correct way
15 Apr 2024 by Pete O'Hanlon
Looking at your code - you are using Sql which is expecting you to use a parameterised query (as far as I can tell). In your particular case here, using hardcoded values, you should be using SqlStatement instead. As others point out though, you...
15 Apr 2024 by Member 14594285
I tried my query in SQLite Expert Personal and it's correct, but if I write query in mfc c++ my database isn't update.. I wrote: in .h: Kompex::SQLiteDatabase *m_pDB; Kompex::SQLiteStatement *m_pStmt; m_pDB = new...
15 Apr 2024 by OriginalGriff
Your code doesn't include any actual SQL query, much less an UPDATE or INSERT query with actual data for the DB to accept. Go back to your working code, and look more closely at exactly what is going on: the code you show us creates an empty...
15 Apr 2024 by Jan Ringos
WM_KEYDOWN doesn't work for PowerPoint Viewer, not reliably. Send WM_COMMAND with wParam = 0x000106EF (for next slide) or 0x000106EE (for previous slide).
13 Apr 2024 by Andre Oosthuizen
You need to use the 'CComboBox::InsertString' method instead of 'CComboBox::AddString' method, see - MS Learn | CComboBox Class[^] Your code should be - for (INT_PTR nInd = 0; nInd
13 Apr 2024 by Andre Oosthuizen
This is a bit of a guessing game of what code you have in the rest of your app... You need to store the 'IVector' object in a member variable of your class, so that it remains valid for the lifetime of the class instance and your error is likely...
13 Apr 2024 by Vicente Flich
I think the Richard's solution is probably the correct, but other possibilities: 1. How do you construct and initialize the m_adEdit array?. If you created it with new and not initialize it, maybe they contain some chunk. Initialize it with...
13 Apr 2024 by Vicente Flich
Hello! I'm trying to use AutoSuggestionBox control in WinUI 3, developing in C++. I can't add suggestion to the control. I try handling the TextChanged event to add some text to the subbestion box but I have some runtime error. Here my code...
12 Apr 2024 by Pete O'Hanlon
The flag you are looking for is CBS_SORT. This sets the combobox up to automatically sort the strings. You can find bout more here[^].
12 Apr 2024 by Member 14594285
I have a comboBox and in properties I put sort to false..but elements in comboBox are in alphabetical order, my code: for (INT_PTR nInd = 0; nInd
11 Apr 2024 by merano99
The MFC uses CWnd::GetDlgItem and uses an existing pointer to the parent window or dialog as a member of CWnd. see: https://learn.microsoft.com/en-us/cpp/mfc/reference/cwnd-class?view=msvc-170#getdlgitem Unfortunately, it is not clear from the...
11 Apr 2024 by KarstenK
You can also open the RC file with a text editor and search for the control. IMPORTANT: each control must have an unique ID in your app. So check whether each control has an own identifier and the identifier are resolved in the resource.h to...
10 Apr 2024 by CPallini
Try to closely mimic the behaviour this MSDN piece of code[^]. Namely, DO NOT create (and destroy) brushes (or other GDI object) inside the OnCtlColor handler. On the contrary create the brushes once, in your initialization code, and release them...
10 Apr 2024 by Patrice T
Quote: How will I do this calculation for this project ... 'this project' is not a description of the project you working on. 'this calculation', the end of title do not describe any calculation because we have no context. As a requester, your...
10 Apr 2024 by CPallini
You could try (not tested) HWND hwnd = GetSafeHwnd(); LONG id = GetWindowLong(hwnd, GWL_ID);
10 Apr 2024 by Member 14594285
I created a derived class of CStatic, and I must find id of my CStatic but I don't know how I can do IMPLEMENT_DYNAMIC(CDerStatic, CStatic) CDerStatic::CDerStatic() { int n_color; RGBTRIPLE rgb; double red; double green; double blue;...
9 Apr 2024 by Pete O'Hanlon
I will repeat what I said in my answer here[^]. We typically don't provide code for homework assignments here but surely this is just subtracting tax from salary. To quote Richard Deeming's excellent reply: Nobody is going to do your homework...
9 Apr 2024 by OriginalGriff
While we are more than willing to help those that are stuck, that doesn't mean that we are here to do it all for you! We can't do all the work, you are either getting paid for this, or it's part of your grades and it wouldn't be at all fair for...
9 Apr 2024 by OriginalGriff
While we are more than willing to help those that are stuck, that doesn't mean that we are here to do it all for you! We can't do all the work, you are either getting paid for this, or it's part of your grades and it wouldn't be at all fair for...
9 Apr 2024 by Pete O'Hanlon
We typically don't provide code for homework assignments here but surely this is just subtracting tax from salary. You must know how to do this I would have thought.
9 Apr 2024 by Member 16240157
So the problem is that,how is the calculatio with the c++ What I have tried: Please I need for the calculation for c++ for this project
9 Apr 2024 by PJ Arends
Trace your function calls to the Output window.
9 Apr 2024 by OriginalGriff
Compiling does not mean your code is right! :laugh: Think of the development process as writing an email: compiling successfully means that you wrote the email in the right language - English, rather than German for example - not that the email...
9 Apr 2024 by Member 14594285
When I resize my window software crashes because hbrush objcet isn't destoyed, I wrote this: HBRUSH CDlgEst::OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor) { HBRUSH hbr = CDialog::OnCtlColor(pDC, pWnd, nCtlColor); //HBRUSH hbrN = HBRUSH...
9 Apr 2024 by That New Coder
I am currently making a text-based game. In this game, the character has to move around between rooms. Each room as a "roomAddress" or "roomId". Currently, I am trying to make the options for a level. Then, when an option is made, the character...
9 Apr 2024 by Pete O'Hanlon
Something to look at in your code. You are returning early from your switch statements, so the brushes aren't removed. You are leaking resources in that code. You are leaking a lot of resources. What's even more interesting is - if you somehow...
8 Apr 2024 by Vasily Androshchook
As the debugger showed a protected member of CFile::m_strFileName became empty for the closed file. So, derive your class from CFile and add a function bool MyFile::isClosed () const {return m_strFileName.IsEmpty ();}
8 Apr 2024 by steveb
You need to draw to memory DC before you call BeginPaint. Your BeginPaint should have only 2 more lines after it - BitBlt and EndPaint. All drawing must be done prior to these lines. And perhaps use Direct2D API. This way you'll take care of...
8 Apr 2024 by Ștefan-Mihai MOGA
Task Manager shows you the programs, processes, and services that are currently running on your computer. You can use Task Manager to monitor your computer’s performance or to close a program that is not responding.
7 Apr 2024 by OriginalGriff
Simple: learn a computer language, learn to code, write a specification for the task, write a test and acceptance specification, design to meet the specification, then code to the design. Then abandon all attempts to become a spammer because you...
6 Apr 2024 by Pete O'Hanlon
The problem you're describing is resolution. Typically, printers support a much higher resolution than a screen does, so if you have made assumptions about DPI, for instance, you will see a different output. It's best to work with Device...
6 Apr 2024 by Gbenbam
The display program that I used to render to a window dc was used by me to write to PriPrinter a virtual printing software. Everything worked fine except that the images were rendered to true size and not according to specified size. Is it...
5 Apr 2024 by Gbenbam
For some time now I have been trying to resolve the WM_PAINT code or my application. Every advise I have ever been given on this issue, I have applied. Someone said I should carry out all the DC operations in WM_PAINT. I did that. Someone said...
5 Apr 2024 by KarstenK
I see no easy fix but you may debug it via double buffering. At first you paint a complete image into some memory dc and than make a BitBlt to the screen. Read this Guide to DC to improve your knowledge. Best is to optimize the code via...
4 Apr 2024 by Mohammed Faci
How to leverage ChatGPT to Build an Automation Framework using the Page Object Model
4 Apr 2024 by Gbenbam
I am using GDI to write a document printing program or my application, but StartDoc is not succeeding. What could be wrong. The relevant codes are shown below: case IDM_FILE_PRINT: { //Invoke Print commn dialog ...
2 Apr 2024 by Pete O'Hanlon
Leslie, if I were in your position, I would look to your local chambers of commerce to see if there was anybody local who could come and perform an audit of your software. Make it clear that you are only interested in the audit and would not be...
2 Apr 2024 by OriginalGriff
My condolences on your loss - I lost my wife last year, and I know how traumatic it can be trying to tidy up a life partner's affairs. But this isn't the right place to ask for this help: we aren't a recruitment or "code it for you" site. You...
2 Apr 2024 by Igor Gribanov
C++ iterators and algorithms work well for containers, but can we sort the Structure of Arrays?
2 Apr 2024 by Member 16235419
I am a small business north of Boston. My late husband originally wrote our very specific software in Business Basic - starting in the Data General Mini Computer age. One of his programmers has been supporting us over the years, but is now...
31 Mar 2024 by honey the codewitch
Stream JSON efficiently on little devices with minimal flash and memory usage
30 Mar 2024 by Shao Voon Wong
InsertionSort outperforms QuickSort on almost In-Order Array
28 Mar 2024 by OriginalGriff
While we are more than willing to help those that are stuck, that doesn't mean that we are here to do it all for you! We can't do all the work, you are either getting paid for this, or it's part of your grades and it wouldn't be at all fair for...
28 Mar 2024 by Rick York
"Do my homework for me" questions are usually not received very well here. You have all the required members and methods listed. The next step is for you to write the header file that declares all of them. Following that will come...
28 Mar 2024 by Richard MacCutchan
Here is the essential parts of the code I use to allow scrolling in a self painted Window. If you want an easier life then you can use one of the standard Windows controls (e.g. Edit Control (Windows Controls) - Win32 apps | Microsoft Learn[^] )...
27 Mar 2024 by Yochai Timmer
A way to avoid JNI's reflection oriented programming. Wrapping Java with C++
27 Mar 2024 by Gbenbam
In the program below, everything works fine until I try to scroll with the thumbtrack. The thumtrack simply snaps back to its initial position after I release it. What could be wrong? case WM_VSCROLL: { SCROLLINFO scrollInfo; ...
25 Mar 2024 by Gbenbam
Below is a program I use for opening files. bool GetfilePath(HWND hWnd, wchar_t* pszFilename, const wchar_t* pwstFileTypes) { OPENFILENAME ofn; ZeroMemory(&ofn, sizeof(ofn)); ofn.lStructSize = sizeof(ofn); ofn.hwndOwner = hWnd;...
25 Mar 2024 by Mircea Neacsu
Examines the performance of SQLite in multi-threading applications
25 Mar 2024 by Pete O'Hanlon
Given what you have posted, you are only attempting to choose image types in your file dialog. Text Files\0*.txt\0Image Files\0*.jpg;*.jpeg;*.gif;*.png;*.bmp\0All files (*.*)\0*.*\0\0 Just pass that string into your GetfilePath method and you...
24 Mar 2024 by merano99
In fact, a lot can go wrong here at the same time, as Rick has already written. In addition to the problem of choosing the correct search range and step size, the function also has 4 jumps, as the formula already reveals. In addition to the risk...
24 Mar 2024 by merano99
The source code to be found under the link is actually not directly prepared for Windows. In addition to incompatible shell scripts, Linux system calls and some assembler instructions, the "do" scripts create a lib for the current architecture. ...
24 Mar 2024 by k5054
See: NaCl Installation[^] That's fairly clear on how to download and compile the source. NaCl seems to be a mixture of C, C++ and assembler. It does not appear to be a pure C++ project. If you're looking for pure C++ code for NaCl, I think...
24 Mar 2024 by Gbenbam
There is no link or explicit instruction on how to download NACL c++ source code for Windows even on its official website. Can anyone here point me in the right direction? What I have tried: I have spent hours searching the web.