Click here to Skip to main content
15,884,298 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 Hatem Mostafa
Artificial Neural Network C++ class with two use cases: Counter and Handwritten Digits recognition
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.

Latest Articles

by Hatem Mostafa
Artificial Neural Network C++ class with two use cases: Counter and Handwritten Digits recognition
by Michael Chourdakis
An introduction to machine learning with working C++ code that trains a linear regression model.
by PJ Arends
Trace your function calls to the Output window.
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.

All Articles

Sort by Updated

C++ 

U 23 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...
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).
U 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);...
N 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...
U 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...
N 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...
N 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...
N 18 Apr 2024 by Michael Chourdakis
An introduction to machine learning with working C++ code that trains a linear regression model.
U 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...
N 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.
N 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...
N 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.
N 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
U 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...
U 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...
N 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...
N 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).
N 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
N 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...
N 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...
N 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...
N 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[^].
U 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
N 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...
N 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...
N 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...
U 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...
N 10 Apr 2024 by CPallini
You could try (not tested) HWND hwnd = GetSafeHwnd(); LONG id = GetWindowLong(hwnd, GWL_ID);
U 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;...
N 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...
N 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...
N 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...
N 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.
N 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
U 9 Apr 2024 by PJ Arends
Trace your function calls to the Output window.
N 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...
U 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...
U 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.
24 Mar 2024 by honey the codewitch
Do you need to be able to perform a firmware update without using WiFi? This project is for you.
23 Mar 2024 by merano99
What is meant by scrolling in this case is unclear. I assume that an image is to be drawn that is larger than the window. If the image is not to be scaled to the size of the window, you will only see the part of the image that fits into the...
23 Mar 2024 by Uwe_Sieber
Shows how to use IOCTL_USB_HUB_CYCLE_PORT to restart a USB port under Windows
22 Mar 2024 by OriginalGriff
If I understand you right, you are trying to "draw a picture" (which is what all text and lines end up as when they are rendered for actual display) that is bigger than the bitmap you are drawing into. Imagine this: you have a whiteboard on your...
22 Mar 2024 by Gbenbam
My app's document contains redered images, ellipse, rectangles, lines etc. For as long as I don't scroll past the memory dc bitmap size, display comes out fine, but ones I scroll over a distance greater than the memory dc bitmap size,the display...
22 Mar 2024 by VaKa
as i dont know initial values for formula, s1, v1, k, s2 and looking at 1st example code, i suppose that cycle stops within 3 steps with incerment=1 (supposing k=0 at begininig), and resulting k is 3. at 2nd example of code, k increments with...
22 Mar 2024 by OriginalGriff
It's not random, it's being read from the file: void readData() { 51 Student student; 52 ifstream read; 53 read.open("student.txt"); 54 while (!read.eof()) { 55 read >> student.id; Only when you add a new...
22 Mar 2024 by samcodeonline
I have created a crud to create, read, update and delete in C++. The problem I am facing right now is that while I enter the data the id's of the person don't start from 1, 2, 3 and so on. the id's start from the random numbers like 1586 , 1587...
21 Mar 2024 by Саша Гайдамак
Help me write a program in C that will fit the values of k into the equation. formula = 5/1+k + 9/2+k + 13/3+k + 17/4+k -16 The value of k can be negative and an integer; in the case of the above selection method, the result should come out to...
21 Mar 2024 by Rick York
I don't think you are writing that correctly. Shouldn't it be 5/(1+k) + 9/(2+k) ... with parenthesis around each denominator term? This detail is very, very important. I would add parenthesis around each term summed so you don't have to rely...
20 Mar 2024 by CPallini
What Every Computer Scientist Should Know About Floating-Point Arithmetic[^].
20 Mar 2024 by merano99
Several things don't fit together in this program. The following excerpt alone is creepy: for (int i = 0; i
20 Mar 2024 by k5054
Look at your search function. What happens when an item is not found? You clearly print the fact that the item does not exist, but then what happens? You might need either a return statement somewhere or wrap part of the function in an else clause.
20 Mar 2024 by Michael Chourdakis
DirectX hardware screen capture and encoding with audio mixing capabilities. H264/H265/VP80/VP90/FLAC/MP3. HDR supported.
20 Mar 2024 by Member 15018472
My code stops running until the query "search flower rose" and does not continue to process the rest of the queries in in.txt. I think that the loop is exiting due to some other condition rather than reaching EOF but I am not entirely sure. The...
20 Mar 2024 by Member 14594285
I have a array of CEdit*, if this array has elements that aren't NULL I have to delete these..I wrote: if (m_arEdit.GetSize() > 0) { for (int j = 0; j
20 Mar 2024 by Pete O'Hanlon
Building on Richard's answer, I would make a minor change.int size = m_arEdit.GetSize(); for (int j = size - 1; j >= 0; j--) { if(NULL != m_arEdit[j]) { delete m_arEdit[j]; m_arEdit[j] = NULL; } }
19 Mar 2024 by Richard MacCutchan
I am assuming that you are calling this code more than once, and the second time you are trying to delete an entry that has already been deleted. You should change the code to: for (int j = 0; j
19 Mar 2024 by OriginalGriff
It's been a long time since I used MFC ... but your problem is simpler than you think: delete is used to return memory to the heap, it won't remove text from a CEdit control. And that's why your app crashes: the chunk of memory you are trying to...
19 Mar 2024 by honey the codewitch
Just a clock with snazzy digits that syncs using NTP and gets your timezone from your IP.
19 Mar 2024 by merano99
There are several things to note here. It seems that only the variable k is changed with each loop. for (int i = -10000; i
19 Mar 2024 by Саша Гайдамак
please explain how it works? The program gives me the correct result only when I add integers, but in my task I would prefer to use the type double. working option: ` for (int i = -10000; i