|
When your project is causing you enough headake on its own, last thing you want is errors because of a buggy IDE/compiler.
There is no serious match for VS from what I know.
|
|
|
|
|
Qt Creator is worthwhile ONLY if you embrace Qt. Qt is great but is like its own OS. I still vastly prefer Visual Studio and so did my Qt development with it. Had I ported my last app to Linux, only then would I use Qt Creator.
Don't bother with Code::Blocks. It's adequate for Linux but a waste of time for Windows. Moreover, for Linux CLion is vastly superior.
|
|
|
|
|
Visual Studio is always the best choice for creating Win32 GUI applications as it integrates all the tools you will need. It also includes a simple template to create your first GUI program (although it is a bit clunky). And the standard Windows Controls - Win32 apps | Microsoft Docs[^] cover most control types you are likely to need.
|
|
|
|
|
With no prior baggage, I would think that WinUI 3 and VS2022 (with C++) would be the route.
About WinUI
"Before entering on an understanding, I have meditated for a long time, and have foreseen what might happen. It is not genius which reveals to me suddenly, secretly, what I have to say or to do in a circumstance unexpected by other people; it is reflection, it is meditation." - Napoleon I
|
|
|
|
|
I will start with my code:
template < typename T1, typename T2 >
void printvector(T1& fout, const std::vector < T2 >& V)
{
if (V.empty()) fout << "EMPTY\n";
else {
for (size_t x = 0; x != V.size() - 1; ++x)
{
fout << V[x] << ", ";
}
fout << V[V.size() - 1] << '\n';
}
}
fstream StatFile;
StatFile.open(STATICFILE, std::fstream::out);
if (StatFile.is_open())
{
for (i = 0; i != NewLandmarks.size(); ++i)
{
cout << NewLandmarks[i].name << " "; printvector(cout, Subtractions);
StatFile << NewLandmarks[i].fiducial << ", " << NewLandmarks[i].name << ", "; NewLandmarks[i].location.print(StatFile);
if (Subtractions.empty()) StatFile << "\n";
else {
StatFile << ','; printvector(StatFile, Subtractions);
}
}
StatFile.close();
}
The template is supposed to print out the contents of a vector, either to the console when given cout, or to a text file when given an fstream variable.
NewLandmarks is a vector of a struct and that seems to be working just fine here.
Subtractions is a vector of size_t, and this is where the problem lies.
When the code runs, the NewLandmarks name is printed to the console, as well as the contents of the Subtractions vector, which in this case is always 45, 46, 47, 48
When the code gets to the next line, where it prints to the file, NewLandmarks.fiducial, NewLandmarks.name and NewLandmarks.location.print(StatFile) all work as expected.
However, the Subtractions vector only prints its last element, 48, to the file. This implies that the Subtractions vector somehow got changed by the printvector template. But, I don't see how, or why.
Even more confusing, this code loops several times. The first time Subtractions prints to the file as 48. The second time it prints as 47, 48. The third time as 46, 47, 48. I don't loop through a fourth time, but I think I can see what would happen. But I still don't know why. Even worse, during each of these loops when Subtractions is printed to the console I always get the full vector: 45, 46, 47, 48.
So,
Why is the template function behaving differently from its console and file printing activations?
Why does the template function write only the last element of the vector to the file and its first iteration?
Why does the template function change behavior and write an additional vector element each time it runs?
In case it is relevant, NewLandmarks.location is a Vector (a mathematical Vector class that I created) and its print function looks like this:
(L is the length of the Vector)
void Vector::print(std::fstream & fout) const {
for (size_t i = 0; i != L; ++i) {
fout << std::setprecision(15) << std::setw(22) << v[i];
if (i != L - 1) fout << ',';
}
}
Even if this is somehow causing my problem, I still do not see how or why. But, it seems to be working fine.
Thank you for your help
|
|
|
|
|
|
Yes, or that is what I am in the process of doing. I found this unexpected behavior and I do not know why it happens or how to fix it.
|
|
|
|
|
Probably there is part of your code (not posted here) messing up with the Subtraction vector.
This code
#include <iostream>
#include <fstream>
#include <vector>
using namespace std;
template < typename T1, typename T2 >
void printvector(T1& fout, const std::vector < T2 >& V)
{
if (V.empty()) fout << "EMPTY\n";
else {
for (size_t x = 0; x != V.size() - 1; ++x)
{
fout << V[x] << ", ";
}
fout << V[V.size() - 1] << '\n';
}
}
int main()
{
vector <size_t> sub {46,47,48};
printvector(cout, sub);
fstream foofile("foo.txt", ios::out);
if (foofile)
{
printvector(foofile, sub);
}
} produces the same output
46, 47, 48 both to the console and to the foo.txt file.
[update]
Note, you might also write
#include <iostream>
#include <fstream>
#include <vector>
using namespace std;
template <typename T>
ostream & operator<< (ostream & os, const vector <T> & v)
{
if ( v.empty() ) os << "EMPTY\n";
else
{
for (size_t n = 0; n != v.size() - 1; ++n)
{
os << v[n] << ", ";
}
os << v.back() << '\n';
}
return os;
}
int main()
{
vector <size_t> sub {46,47,48};
cout << sub;
fstream foofile("foo.txt", ios::out);
if (foofile)
{
foofile << sub;
}
} [/update]
"In testa che avete, Signor di Ceprano?"
-- Rigoletto
modified 24-May-22 6:02am.
|
|
|
|
|
That is what I thought at first. But why does the vector print correctly when it is to the console and incorrectly when it is to a file, and the two commands are right next to each other. Where was the opportunity to screw up the Subtractions vector?
|
|
|
|
|
You only, having the full code, might know.
"In testa che avete, Signor di Ceprano?"
-- Rigoletto
|
|
|
|
|
I just ran the above code and it works correctly. I had to create my own version of the NewLandmarks structure, so maybe what you have is actually the issue.
|
|
|
|
|
Here is my struct and the NewLandmarks vector. Do you see anything in this code that could be causing this problem?
struct landmarktype {
std::string fiducial{};
std::string name{};
Matrix location{};
std::vector <size_t> subtractions{};
};
vector <landmarktype> NewLandmarks;
declared earlier in the code, but in case it's important here is my Matrix class:
class Matrix {
private:
double * M;
size_t ROWS, COLUMNS;
public:
Matrix(): M(NEW double[1]), ROWS(1), COLUMNS(1) {}
Matrix(size_t R, size_t C): M(NEW double[R * C]), ROWS(R), COLUMNS(C) {}
~Matrix() {delete[] M;};
Matrix(const Matrix & m): M(NEW double[m.ROWS * m.COLUMNS]),
ROWS(m.ROWS), COLUMNS(m.COLUMNS) {
for (size_t i = 0; i != (ROWS * COLUMNS); i++) M[i] = m.M[i];
}
double & operator()(const size_t R,
const size_t C);
double operator()(const size_t R,
const size_t C) const;
[[nodiscard]] size_t rows() const { return ROWS; }
[[nodiscard]] size_t cols() const { return COLUMNS; }
void set(const size_t R, const size_t C) {
double* newMat = NEW double[R*C];
delete[] M;
M = newMat;
ROWS = R;
COLUMNS = C;
}
void clear()
{
double* newMat = DBG_NEW double[0];
delete[] M;
M = newMat;
ROWS = 0;
COLUMNS = 0;
}
void print(std::fstream & ) const;
}
void Matrix::print(fstream & fout) const {
size_t r, c;
for (c = 0; c != COLUMNS; ++c)
for (r = 0; r != ROWS; ++r)
{
fout << setiosflags(ios::fixed) << std::setprecision(outputprecision) << std::setw(22) << M[r * COLUMNS + c];
if ((r*COLUMNS+c) != (ROWS*COLUMNS - 1)) fout << ", ";
}
}
|
|
|
|
|
I cannot get that to build, the compiler does not know NEW or DBG_NEW . But either way that is a rather complex class. However, I can see nothing obvious, I guess the only way to find the problem is via the debugger.
[edit]
OK, with a bit of editing I got it to work and the output is correct (as far as I can see) in both cases.
So the issue must have something to do with what you are running, or your data.
[/edit]
|
|
|
|
|
Sorry, my mistake. That's my attempt at some debugging.
When I switch debugging off the preprocessor will replace NEW and DBG_NEW with new. Do that now and it should compile.
|
|
|
|
|
See the update in my previous message.
|
|
|
|
|
Hello,
We have an application. We want to check while starting that application in any system (customer place) whether any virus is there or not or the exe went out with or without virus.
Can we do this in C++ in the application startup itself or can we use any third party software?
Please suggest.
Regards,
Gopinath.
|
|
|
|
|
Gopi Nath wrote: Can we do this in C++ in the application startup Not unless you know how to write a virus check program, and have a database of all known viruses.
|
|
|
|
|
No, you can't.
The reason being is executable viruses have a nasty habit of hiding themselves from attempts to find them. File system reads/writes get redirected to what looks like good data, so your attempts to find them will actually find nothing.
It's far better to rely on actual anti-virus software, which protects the actual file system code from attempts to redirect/replace it. That's something your code cannot do when a user launches it.
|
|
|
|
|
Thank you Richard and Dave for reply and suggestion.
Regards,
Gopinath.
|
|
|
|
|
At first I thought I could set the above values in DrawItem (I have an ownerdraw combobox). The Drawitem however only gets invoked when clicking the right icon after the display
I have tried OnCtlColor in the dialog (for the text color) It does get invoked but doesnt set the text color.
Tried OnCreate in ComboBox for the font for that it just didn't get invoked
Thanks
|
|
|
|
|
Presubclasswindntrolow got the font working
Then I re-read remarks on CTLCOLOR seems like for a combobox the message is sent to the combobox as it is the parent to the edit control and list box
However the ctlcolor for the combobox only got called twice and both times had a value CTLCOLOREDIT
maybe the idea is then to set the color of the listbox in the Drawitem
Thanks
|
|
|
|
|
|
I downloaded it built it debug x64 and as I was stepping thru that code it got an exception it was somewhere in MFC code the call stack indicated it was from an Additem Ill go back and try to fix it up thank you
|
|
|
|
|
Hi,
In my trying on understanding semaphores I am looking on the following example:
DWORD WINAPI ChildThreadProc( HWND hWnd )
{
TCHAR szBuffer[256]; DWORD dwSemCount = 0; HANDLE hSemaphore = OpenSemaphore( SYNCHRONIZE, FALSE, "TEST SEMAPHORE");
wsprintf(szBuffer, "Thread %x waiting for semaphore %x", GetCurrentThreadId(), hSemaphore );
SendMessage(hWnd, WM_USER, 0, (LPARAM)szBuffer);
WaitForSingleObject( hSemaphore, INFINITE );
wsprintf(szBuffer, "Thread %x got semaphore", GetCurrentThreadId() );
SendMessage(hWnd, WM_USER, 0, (LPARAM)szBuffer);
Sleep(5000);
ReleaseSemaphore( hSemaphore, 1, (LPLONG)&dwSCount );
wsprintf( szBuffer, "Thread %x is done with semaphore. Its count was %ld.", GetCurrentThreadId(), dwSemCount );
SendMessage( hWnd, WM_USER, 0, (LPARAM)szBuffer );
CloseHandle( hSemaphore );
ExitThread ( TRUE );
}
And I am having 2 problems here:
-first, the dwSemCount value si always printed as 0, even if the semaphore works fine
-second, incrementing the counter with ReleaseSemaphore function from inside of thread doesn't working, I can't explain why.
Can you please help me with some advices?
Thank you very much,
|
|
|
|
|
|