|
|
|
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())
|
|
|
|
|
Thank you so much for your response. After breaking the while as you suggested, it is working fine now
|
|
|
|
|
You are welcome. But, as k5054 suggested, there are a few areas that cpuld be tidied up. For example I would read all accounts into memory at the beginning of the program, and only write out new or updated entries. That way you will always have the most up to date information available.
|
|
|
|
|
I will keep it mind for sure!
|
|
|
|
|
As you're using C++, you might consider using a std::map for the internal data structure. e.g std::map<int, account> . If you do that, then you can access an account via its account number, without searching for it
std::map<int, account> accounts;
accounts[account_no].dep(amount);
Keep Calm and Carry On
|
|
|
|
|
Hi,
In MFC, when using sending or posting message to UI in a worker threads, is better to call global ::postmessage or postmessage?. CWnd vs. MFC.
|
|
|
|
|
It does not matter, since CWnd::PostMessage is just a wrapper for the Win32 function.
|
|
|
|
|
within worker thread, could a pointer to CDialog access its member variables or even functions, nothing to do with its UI elements, without using postmessage or sendmessage?. I expect the answer is YES.
|
|
|
|
|
wizQ wrote: I expect the answer is YES. No, the answer is "maybe", as it depends on the way the code is written. Without considerably more detail about your code any answer is guesswork.
|
|
|
|
|
You probably would like to read this great Joe Newcomer's essay about using WorkerThreads
|
|
|
|