|
You are welcome.
"In testa che avete, Signor di Ceprano?"
-- Rigoletto
|
|
|
|
|
in visual studio c++ / x64:
what are way safest to convert from:
1.INT_PTR to int?
2.LRESULT to BOOL?
3.LRESULT to int?
|
|
|
|
|
|
Hi,
If you want to detect overflows, underflows, truncation. The Shell team provided the intsafe.h header.
wizQ wrote: 1.INT_PTR to int? The IntPtrToInt function will at least warn you if the pointer was truncated.
CPallini gave great advice, there really isn't a "safe" conversion. But you can at least detect overflows and underflows.
|
|
|
|
|
can one change int to LRESULT?.
change from
int c = ...
to
LRESULT c = ...
also change from
void func(int p,..
to
void func(LRESULT p,...
|
|
|
|
|
The question is, why would you want to do such a thing? The LRESULT type has a specific meaning and purpose, which is not the same as an int , or any other basic, type.
|
|
|
|
|
Hi,
Got two items to ask. First, is there a library available for c++ mfc that can write results to PDF?. libHARU is deoendent on zlib , libpng, etc. Like to try something more straight forward and free. secondly, is there a possibility to save a CDialog to PDF file?.
|
|
|
|
|
You could just print what you want using Microsoft Print to PDF printer.
|
|
|
|
|
When I googled certainly seem to suggest that.
"C++" pdf libary
Not free (I don't think) but years ago Crystal Reports had an API and among many outputs possible was PDF.
|
|
|
|
|
|
|
I have noted those discussion before, no clue..
|
|
|
|
|
Then perhaps you'll describe how you are doing the "dragging" anw how and in what class you are handling this notification...
|
|
|
|
|
Click the left button, hold on it and move the mouse to somewhere else, no any message receive... My codes as below:
<pre lang="C++"> BOOL CListCtrlEx::OnNotify(WPARAM wParam, LPARAM lParam, LRESULT*
pResult)
{
LPNMLISTVIEW pnmv = (LPNMLISTVIEW)lParam;
switch(pnmv->hdr.code){
case LVN_MARQUEEBEGIN:
; // Deal with some case here.
break;
}
return CListCtrl::OnNotify(wParam, lParam, pResult);
}
This method is trigged only when move mouse into the dialog which contains CListCtrlEx object, message type is TTN_GETDISPINFOW.
|
|
|
|
|
I added the message handler for LVN_MARQUEEBEGIN in my CListCtrl derived class:
BEGIN_MESSAGE_MAP(CListOptionsCtrl, CListCtrl)
ON_NOTIFY_REFLECT(LVN_MARQUEEBEGIN, &CListOptionsCtrl::OnLvnMarqueeBegin)
...
void CListOptionsCtrl::OnLvnMarqueeBegin(NMHDR* pNMHDR, LRESULT* pResult)
{
LPNMLISTVIEW pNMLV = reinterpret_cast<LPNMLISTVIEW>(pNMHDR);
*pResult = 0;
}
and it does work.
|
|
|
|
|
Without seeing some of your code it is impossible to guess.
|
|
|
|
|
Updated my question, added related codes.
|
|
|
|
|
Where is the MFC ON_NOTIFY table that defines the captures? Note also that the notification goes first to the list control's parent window, so you need to capture it there.
|
|
|
|
|
Li Lin 2023 wrote: BOOL CListCtrlEx::OnNotify
You cannot capture it there. You will need to use ON_NOTIFY_REFLECT if you want to capture LVN_MARQUEEBEGIN in your CListCtrl derived class.
Or as Richard pointed out you can capture that message in the parent window.
|
|
|
|
|
|
Good job, happy to see you solved it.
|
|
|
|
|
I have a c++ code that receives 3 information including the account number, name and deposit (Balance) as input and shows the information on the screen in a table. I have a function (deposit_amount) that is supposed to receive a new deposit and add it to the previous balance. The user has different options by pressing 1 (Making a new account), 2 (adding deposit to the balance), 3 showing the information of the accounts in a table and 4 (Exit the code). emphasized text
Everything looks fine in my code in terms of receiving the information and creating accounts by pressing 1. In addition, I can see the information of the accounts in the table by pressing 3.
The problem is when I want to add deposit by pressing 2. Although everything looks correct, after entering the amount of deposit, I expect that this amount should be added to the previous balance and when I press 3, I expect to see the updated balance. However, after pressing 3, the previous balance still shows up in the table. My guess is that I am missing something in the deposit_amount function but I was not able to capture it.
Could you please help me with this issue to figure out how this could be fixed?
Here is my full code:
#include<iostream>
#include<fstream>
#include<ctype.h>
#include<iomanip>
#include<stdio.h>
using namespace std;
class account
{
int acno;
char name[50];
int deposit;
public:
void create_account(int accno)
{
acno = accno;
cout<<"\nEnter The Name of The account Holder : ";
cin>>name;
cout<<"\nEnter The amount: ";
cin>>deposit;
cout<<"\n\n\n === Account Created... ===";
}
void show_account()
{
cout<<"\nAccount No. : "<<acno;
cout<<"\nAccount Holder Name : ";
cout<<name;
cout<<"\nBalance amount : "<<deposit;
}
void dep(int x){ deposit+=x;
cout << deposit;
}
int retacno(){ return acno;
}
void report(){ cout<<acno<<setw(14)<<name<<setw(15)<<deposit<<endl;
}
};
void write_account(); void deposit_amount(int); void display_all();
int main()
{
int num, ch;
do
{
cout<<endl;
cout<<"\n\n\n\tMAIN MENU";
cout<<"\n\n\t01. NEW ACCOUNT";
cout<<"\n\n\t02. DEPOSIT AMOUNT";
cout<<"\n\n\t03. ALL ACCOUNT HOLDER LIST";
cout<<"\n\n\t04. EXIT";
cout<<"\n\n\n\tSelect Your Option (1-4) ";
cin>>ch;
cout<<endl;
switch(ch)
{
case 1:
write_account();
break;
case 2:
cout<<"\n\n\tEnter The account No. : ";
cin>>num;
deposit_amount(num);
break;
case 3:
display_all();
break;
case 4:
cout<<"\n\n\tThanks";
break;
default:
cout<<"Select Your Option (1-4): ";
break;
}
}while(ch!=4);
return 0;
}
account ac;
void write_account()
{
fstream inFile;
bool flag = true;
int ac_number;
inFile.open("info.txt", ios::in);
cout << "Enter Your Account Number: ";
cin >> ac_number;
while(inFile.read((char *) &ac, (int)sizeof(ac)))
{
if(ac.retacno() == ac_number)
flag = false;
}
inFile.close();
fstream outFile;
outFile.open("info.txt", ios::out | ios::app);
if(flag){
ac.create_account(ac_number);
outFile.write((char *) &ac, (int)sizeof(ac));
}else
cout << "\n\nAccount number exist..." << endl;
outFile.close();
}
void display_all()
{
ifstream inFile;
inFile.open("info.txt");
cout<<"\n\n\t\tACCOUNT HOLDER LIST\n\n";
cout<<"=============================================\n";
cout<<"A/c no. NAME Balance\n";
cout<<"=============================================\n";
while(inFile.read((char *) &ac, sizeof(ac)))
{
ac.report();
}
inFile.close();
}
void deposit_amount(int n)
{
int amt=0;
fstream File;
File.open("info.txt", ios::in|ios::out);
while(File.read((char *) &ac, (int)sizeof(ac)))
{
if(ac.retacno()==n)
{
ac.show_account();
cout<<"\n\nEnter The amount to be deposited: ";
cin>>amt;
ac.dep(amt);
int pos = -1 * (int)sizeof(ac);
File.seekp(pos,ios::cur);
File.write((char*)&ac, (int)sizeof(ac));
cout<<"\n\n\t Record Updated";
}
}
File.close();
}
|
|
|
|
|
Works for me. Even compiles using g++ -Wall -Wextra with no warnings, so on that.
One issue I do have is that the program cannot handle input for a full name. e.g. Bill works fine, but Bill Smith causes the program to loop indefinitely. You may wan to fix that. One suggestion would be to use getline() rather that std::cin .
Keep Calm and Carry On
|
|
|
|
|
Thanks for your feedback. I am running it using vs-code and it is compiled without any issue. If I run it for the first time I pressed 1, then I entered 100 (Account number), Mark (Name) and 200 (Balance). Then, I pressed 3 to see the table that works fine (I can see all information for this account on the table):
=============================================
A/c no. NAME Balance
=============================================
100 Mark 200
Then I pressed 2 to add a deposit and I entered 350. Now I expect this value is added to the previous balance (200) and the new balance should be 550 now. However, after pressing 3, I still see the above table and the balance has not been updated. Do you know where the problem could be?
Thanks
|
|
|
|
|
In the deposit_amount function you should break out of the loop after updating the record. So change it to:
while(File.read((char *) &ac, (int)sizeof(ac)))
{
if(ac.retacno()==n)
{
ac.show_account();
cout<<"\n\nEnter The amount to be deposited: ";
cin>>amt;
ac.dep(amt);
int pos = -1 * (int)sizeof(ac);
File.seekp(pos,ios::cur);
File.write((char*)&ac, (int)sizeof(ac));
cout<<"\n\n\t Record Updated";
break; }
}
In the display_all function change the while statement to:
while(!inFile.read((char *) &ac, sizeof(ac)).eof())
|
|
|
|