Please help, SendMesssage not working in MFC Dialog Application, (with wizard)
-
Greetings all, Im trying to send messages to a main dialog, but it seems that the messages does not get received.
extern CListBox* hList; . . . if (lTotalCols > 0) { //SendMessage(LVM_DELETEALLITEMS, 0,0); // Clear all the previous listview item SendMessage((HWND)hList, LVM_DELETEALLITEMS, 0, 0); // Clear the previous column header for (idx=0; idx Any Suggestions of what to try? Reinart Laast, Junior Developer. Greetings from South Africa
-
Greetings all, Im trying to send messages to a main dialog, but it seems that the messages does not get received.
extern CListBox* hList; . . . if (lTotalCols > 0) { //SendMessage(LVM_DELETEALLITEMS, 0,0); // Clear all the previous listview item SendMessage((HWND)hList, LVM_DELETEALLITEMS, 0, 0); // Clear the previous column header for (idx=0; idx Any Suggestions of what to try? Reinart Laast, Junior Developer. Greetings from South Africa
extern CListBox* hList; SendMessage((HWND)hList, LVM_DELETEALLITEMS, 0, 0); (HWND)hList is pointing to a CListBox handle. that means, Message is being sent to the List box. is that what you intend to do? Pass the handle of the MainDialog here..:) regards, Haribabu
-
Greetings all, Im trying to send messages to a main dialog, but it seems that the messages does not get received.
extern CListBox* hList; . . . if (lTotalCols > 0) { //SendMessage(LVM_DELETEALLITEMS, 0,0); // Clear all the previous listview item SendMessage((HWND)hList, LVM_DELETEALLITEMS, 0, 0); // Clear the previous column header for (idx=0; idx Any Suggestions of what to try? Reinart Laast, Junior Developer. Greetings from South Africa
Keep in mind that I haven't tried this or looked around on MSDN/web (like you could easily do yourself), so I don't know if this is going to work, but try one of these:
SendMessage(WM_COMMAND, LVM_DELETEALLITEMS, 0);
SendMessage(WM_MESSAGE, LVM_DELETEALLITEMS, 0);"Why don't you tie a kerosene-soaked rag around your ankles so the ants won't climb up and eat your candy ass..." - Dale Earnhardt, 1997
-----
"...the staggering layers of obscenity in your statement make it a work of art on so many levels." - Jason Jystad, 10/26/2001 -
Greetings all, Im trying to send messages to a main dialog, but it seems that the messages does not get received.
extern CListBox* hList; . . . if (lTotalCols > 0) { //SendMessage(LVM_DELETEALLITEMS, 0,0); // Clear all the previous listview item SendMessage((HWND)hList, LVM_DELETEALLITEMS, 0, 0); // Clear the previous column header for (idx=0; idx Any Suggestions of what to try? Reinart Laast, Junior Developer. Greetings from South Africa
Thanks Haribabu, and that is the intention actually, sorry if i phrased the question wrong:doh: I want to clear the listbox and insert the items from the function im sending the messages from, the listbox is on the main dialog, but when i add an messagebox that should receive LVM_DELETEALLITEMS message, it doesnt work. As if the messages go somewhere else or nowhere at all.
BOOL frmMenu::OnInitDialog() { CDialog::OnInitDialog(); this->SetRedraw(true); // TODO: Add extra initialization here hList = (CListBox*)(GetDlgItem(IDC_LIST)); return TRUE; // return TRUE unless you set the focus to a control // EXCEPTION: OCX Property Pages should return FALSE }
void frmMenu::OnDeleteallitemsList(NMHDR* pNMHDR, LRESULT* pResult) { NM_LISTVIEW* pNMListView = (NM_LISTVIEW*)pNMHDR; // TODO: Add your control notification handler code here //Supposed to show when message was received as a test. AfxMessageBox(TEXT("Got it")); *pResult = 0; }
-- modified at 6:10 Monday 5th February, 2007 -
Keep in mind that I haven't tried this or looked around on MSDN/web (like you could easily do yourself), so I don't know if this is going to work, but try one of these:
SendMessage(WM_COMMAND, LVM_DELETEALLITEMS, 0);
SendMessage(WM_MESSAGE, LVM_DELETEALLITEMS, 0);"Why don't you tie a kerosene-soaked rag around your ankles so the ants won't climb up and eat your candy ass..." - Dale Earnhardt, 1997
-----
"...the staggering layers of obscenity in your statement make it a work of art on so many levels." - Jason Jystad, 10/26/2001 -
Thanks Haribabu, and that is the intention actually, sorry if i phrased the question wrong:doh: I want to clear the listbox and insert the items from the function im sending the messages from, the listbox is on the main dialog, but when i add an messagebox that should receive LVM_DELETEALLITEMS message, it doesnt work. As if the messages go somewhere else or nowhere at all.
BOOL frmMenu::OnInitDialog() { CDialog::OnInitDialog(); this->SetRedraw(true); // TODO: Add extra initialization here hList = (CListBox*)(GetDlgItem(IDC_LIST)); return TRUE; // return TRUE unless you set the focus to a control // EXCEPTION: OCX Property Pages should return FALSE }
void frmMenu::OnDeleteallitemsList(NMHDR* pNMHDR, LRESULT* pResult) { NM_LISTVIEW* pNMListView = (NM_LISTVIEW*)pNMHDR; // TODO: Add your control notification handler code here //Supposed to show when message was received as a test. AfxMessageBox(TEXT("Got it")); *pResult = 0; }
-- modified at 6:10 Monday 5th February, 2007- Add a control variable for the listctrl. It will simplify further manipulation of the control, eliminating the need for code like this:
hList = (CListBox*)(GetDlgItem(IDC_LIST));
- If you want to remove all items from the list control, use this (based on your apparent current code):
hList->DeleteAllItems();
- There's no need to send a message to the listbox (see item #2 above). 4) Quite frankly, your naming conventions suck. Personally, I would never name a dialog box class something like "frmMenu". If you scan file names and you see
frmmenu.cpp
, wouldn't you assume that file contains some sort of menu code? Is the message you're sending coming from outside the dialog box? If so, make a programmer-defined message and handle it that way:
// in a separate header file, like "CustomMessages.h"
#define UWM_DELETE_ALL_ITEMS WM_APP+1
// in the dlg header file
#include "CustomeMessages.h"
class frmMenu public
{
public:
afx_msg LRESULT OnDeleteAllItems(WPARAM wParam=0, LPARAM lParam=0);
};// in the dlg cpp file
{MESSAGE_MAP
ON_MESSAGE(UWM_DELETE_ALL_ITEMS, OnDeleteAllItems)
MESSAGE_MAP}LRESULT frmMenu::OnDeleteAllItems(WPARAM wParam, LPARAM lParam)
{
lParam;
wParam;
((CListBox*)(GetDlgItem(IDC_LIST)))->DeleteAllItems();
return 1L;
}This was all done off the top of my head, so you may need to adjust the code to fit/compile, but this should do what you need.
"Why don't you tie a kerosene-soaked rag around your ankles so the ants won't climb up and eat your candy ass..." - Dale Earnhardt, 1997
-----
"...the staggering layers of obscenity in your statement make it a work of art on so many levels." - Jason Jystad, 10/26/2001 -
- Add a control variable for the listctrl. It will simplify further manipulation of the control, eliminating the need for code like this:
hList = (CListBox*)(GetDlgItem(IDC_LIST));
- If you want to remove all items from the list control, use this (based on your apparent current code):
hList->DeleteAllItems();
- There's no need to send a message to the listbox (see item #2 above). 4) Quite frankly, your naming conventions suck. Personally, I would never name a dialog box class something like "frmMenu". If you scan file names and you see
frmmenu.cpp
, wouldn't you assume that file contains some sort of menu code? Is the message you're sending coming from outside the dialog box? If so, make a programmer-defined message and handle it that way:
// in a separate header file, like "CustomMessages.h"
#define UWM_DELETE_ALL_ITEMS WM_APP+1
// in the dlg header file
#include "CustomeMessages.h"
class frmMenu public
{
public:
afx_msg LRESULT OnDeleteAllItems(WPARAM wParam=0, LPARAM lParam=0);
};// in the dlg cpp file
{MESSAGE_MAP
ON_MESSAGE(UWM_DELETE_ALL_ITEMS, OnDeleteAllItems)
MESSAGE_MAP}LRESULT frmMenu::OnDeleteAllItems(WPARAM wParam, LPARAM lParam)
{
lParam;
wParam;
((CListBox*)(GetDlgItem(IDC_LIST)))->DeleteAllItems();
return 1L;
}This was all done off the top of my head, so you may need to adjust the code to fit/compile, but this should do what you need.
"Why don't you tie a kerosene-soaked rag around your ankles so the ants won't climb up and eat your candy ass..." - Dale Earnhardt, 1997
-----
"...the staggering layers of obscenity in your statement make it a work of art on so many levels." - Jason Jystad, 10/26/2001Thanks, this will work with EVC++ 4.0? Because im doing this for a win ce device. I already have a control variable for the control, should i rather use that? And the naming convention thing i know, that was a slip from the c# i've done for menu forms. Only recently started dabbling in c++:confused:
-
- Add a control variable for the listctrl. It will simplify further manipulation of the control, eliminating the need for code like this:
hList = (CListBox*)(GetDlgItem(IDC_LIST));
- If you want to remove all items from the list control, use this (based on your apparent current code):
hList->DeleteAllItems();
- There's no need to send a message to the listbox (see item #2 above). 4) Quite frankly, your naming conventions suck. Personally, I would never name a dialog box class something like "frmMenu". If you scan file names and you see
frmmenu.cpp
, wouldn't you assume that file contains some sort of menu code? Is the message you're sending coming from outside the dialog box? If so, make a programmer-defined message and handle it that way:
// in a separate header file, like "CustomMessages.h"
#define UWM_DELETE_ALL_ITEMS WM_APP+1
// in the dlg header file
#include "CustomeMessages.h"
class frmMenu public
{
public:
afx_msg LRESULT OnDeleteAllItems(WPARAM wParam=0, LPARAM lParam=0);
};// in the dlg cpp file
{MESSAGE_MAP
ON_MESSAGE(UWM_DELETE_ALL_ITEMS, OnDeleteAllItems)
MESSAGE_MAP}LRESULT frmMenu::OnDeleteAllItems(WPARAM wParam, LPARAM lParam)
{
lParam;
wParam;
((CListBox*)(GetDlgItem(IDC_LIST)))->DeleteAllItems();
return 1L;
}This was all done off the top of my head, so you may need to adjust the code to fit/compile, but this should do what you need.
"Why don't you tie a kerosene-soaked rag around your ankles so the ants won't climb up and eat your candy ass..." - Dale Earnhardt, 1997
-----
"...the staggering layers of obscenity in your statement make it a work of art on so many levels." - Jason Jystad, 10/26/2001All my messages come from outside the dlg class, so should i rather define all the messages in a custom message .cpp file? Not only for delete as well as the populating of the listbox, because at the moment i try to fill it with messages as well with -
// Display the rows. while(lNumRowsRetrieved > 0) { //For each row, print the column data. for(lCount=0; lCountGetData(hRows[lCount], hAccessor, pBuffer); // -- Item pitem.mask = LVIF_TEXT; pitem.iItem = SendMessage((HWND)hList, LVM_GETITEMCOUNT, 0, 0); //pitem.iItem = SendMessage(hList, LVM_GETITEMCOUNT, 0, 0); pitem.pszText = (LPTSTR)&pBuffer[pBindings[0].obValue]; pitem.iSubItem = 0; // Insert item idx = SendMessage((HWND)hList, LVM_INSERTITEM, 0, (LPARAM)&pitem); //idx = SendMessage(hList, LVM_INSERTITEM, 0, (LPARAM)&pitem); // Walk through each columns... for (lColumn=1; lColumn
-
Thanks, this will work with EVC++ 4.0? Because im doing this for a win ce device. I already have a control variable for the control, should i rather use that? And the naming convention thing i know, that was a slip from the c# i've done for menu forms. Only recently started dabbling in c++:confused:
I have no clue if it will work in that environment, but there is little in MFC that doesn't (MSDN sometimes points out CE-specific concerns). My advice is to give it a try. We also have a Windows CE forum here that yo could post CE-specific questions in. I have some more advice for you. When you ask questions here, provide as much detail on your requirements as you can. It's hard enough to answer ambiguous questions, and not knowing the requirements make sit harder to give you the right answer the first time. For this particular thread, you should have started out with something like this: Compiler: EVC 4.0 Framework: Windows CE application using MFC Experience: I'm new at this C++ stuff, so go kinda slow. And then proceed with a DETAILED description of your problem, and what you've tried to fix it. This will keep us from having to go over stuff you've trie or point you to where you went wrong.
"Why don't you tie a kerosene-soaked rag around your ankles so the ants won't climb up and eat your candy ass..." - Dale Earnhardt, 1997
-----
"...the staggering layers of obscenity in your statement make it a work of art on so many levels." - Jason Jystad, 10/26/2001 -
All my messages come from outside the dlg class, so should i rather define all the messages in a custom message .cpp file? Not only for delete as well as the populating of the listbox, because at the moment i try to fill it with messages as well with -
// Display the rows. while(lNumRowsRetrieved > 0) { //For each row, print the column data. for(lCount=0; lCountGetData(hRows[lCount], hAccessor, pBuffer); // -- Item pitem.mask = LVIF_TEXT; pitem.iItem = SendMessage((HWND)hList, LVM_GETITEMCOUNT, 0, 0); //pitem.iItem = SendMessage(hList, LVM_GETITEMCOUNT, 0, 0); pitem.pszText = (LPTSTR)&pBuffer[pBindings[0].obValue]; pitem.iSubItem = 0; // Insert item idx = SendMessage((HWND)hList, LVM_INSERTITEM, 0, (LPARAM)&pitem); //idx = SendMessage(hList, LVM_INSERTITEM, 0, (LPARAM)&pitem); // Walk through each columns... for (lColumn=1; lColumn
I think you're going to have to describe what your app is doing and why you're handling it the way you are.
"Why don't you tie a kerosene-soaked rag around your ankles so the ants won't climb up and eat your candy ass..." - Dale Earnhardt, 1997
-----
"...the staggering layers of obscenity in your statement make it a work of art on so many levels." - Jason Jystad, 10/26/2001 -
I think you're going to have to describe what your app is doing and why you're handling it the way you are.
"Why don't you tie a kerosene-soaked rag around your ankles so the ants won't climb up and eat your candy ass..." - Dale Earnhardt, 1997
-----
"...the staggering layers of obscenity in your statement make it a work of art on so many levels." - Jason Jystad, 10/26/2001Oh Ok, what im trying to achieve is to insert items from a function separate from the dlg code, which retrieves rows from a database to display the last 5 or so inserted records that you can refresh with a click or timer, on a small menu dialog that should stay on the mobile device screen. But the dialog im trying to send the messages to doesnt seem te receive the messages, like the message pump doesnt get the messages to send. The above code is to insert the items to the listbox with messagea, im also working from examples as i dont have a lot of c++ exp. So a lot of the code is from the examples. Any advice is very welcome.
-
Oh Ok, what im trying to achieve is to insert items from a function separate from the dlg code, which retrieves rows from a database to display the last 5 or so inserted records that you can refresh with a click or timer, on a small menu dialog that should stay on the mobile device screen. But the dialog im trying to send the messages to doesnt seem te receive the messages, like the message pump doesnt get the messages to send. The above code is to insert the items to the listbox with messagea, im also working from examples as i dont have a lot of c++ exp. So a lot of the code is from the examples. Any advice is very welcome.
Why don't you access the database from within the dialog box? You can create a worker thread that runs the timer, and another worker thread that actually accesses the database and that sends a message back to the dialog that tells the dialog to refresh the list. In fact, the app should be a dialog based app if that's all it does. I wrote a series of articles that includes a part that describes a similar process. http://www.codeproject.com/samples/SDIMultiSplit_Part3.asp[^] The threading stuff is about halfway down the page, and the classes I included in the demo source code should be easily modifiable to fit your needs. Nothing is free, so be prepared to try to figure this stuff out on your own (because only YOU know all of your requirements). You'll learn more that way. I can say that the timer thread should be a direct drop-in in your code. You also don't have to worry about the status bar panes, so passing a NULL in for the timer thread for that parameter should be fine. Have a ball.
"Why don't you tie a kerosene-soaked rag around your ankles so the ants won't climb up and eat your candy ass..." - Dale Earnhardt, 1997
-----
"...the staggering layers of obscenity in your statement make it a work of art on so many levels." - Jason Jystad, 10/26/2001 -
Why don't you access the database from within the dialog box? You can create a worker thread that runs the timer, and another worker thread that actually accesses the database and that sends a message back to the dialog that tells the dialog to refresh the list. In fact, the app should be a dialog based app if that's all it does. I wrote a series of articles that includes a part that describes a similar process. http://www.codeproject.com/samples/SDIMultiSplit_Part3.asp[^] The threading stuff is about halfway down the page, and the classes I included in the demo source code should be easily modifiable to fit your needs. Nothing is free, so be prepared to try to figure this stuff out on your own (because only YOU know all of your requirements). You'll learn more that way. I can say that the timer thread should be a direct drop-in in your code. You also don't have to worry about the status bar panes, so passing a NULL in for the timer thread for that parameter should be fine. Have a ball.
"Why don't you tie a kerosene-soaked rag around your ankles so the ants won't climb up and eat your candy ass..." - Dale Earnhardt, 1997
-----
"...the staggering layers of obscenity in your statement make it a work of art on so many levels." - Jason Jystad, 10/26/2001Thank you very much, i'll do whatever it takes to get this app to work like i want it to, i've started from scratch in c++ last month because of the app having to be in c++, been a ball all the way:) I'll have a read through the article too. Only sometimes i feel like :wtf: Getting easier though. Thanks very much for the help.
-
Greetings all, Im trying to send messages to a main dialog, but it seems that the messages does not get received.
extern CListBox* hList; . . . if (lTotalCols > 0) { //SendMessage(LVM_DELETEALLITEMS, 0,0); // Clear all the previous listview item SendMessage((HWND)hList, LVM_DELETEALLITEMS, 0, 0); // Clear the previous column header for (idx=0; idx Any Suggestions of what to try? Reinart Laast, Junior Developer. Greetings from South Africa
XTr1NiTy wrote:
Im trying to send messages to a main dialog,
From where? It's just asking for trouble to update a UI control from someplace other than the owner. If you have another class or thread that needs to update the control, it's better to post a message to the owner of said control (i.e., main dialog).
"Approved Workmen Are Not Ashamed" - 2 Timothy 2:15
"Judge not by the eye but by the heart." - Native American Proverb
-
XTr1NiTy wrote:
Im trying to send messages to a main dialog,
From where? It's just asking for trouble to update a UI control from someplace other than the owner. If you have another class or thread that needs to update the control, it's better to post a message to the owner of said control (i.e., main dialog).
"Approved Workmen Are Not Ashamed" - 2 Timothy 2:15
"Judge not by the eye but by the heart." - Native American Proverb
-
Greetings all, Im trying to send messages to a main dialog, but it seems that the messages does not get received.
extern CListBox* hList; . . . if (lTotalCols > 0) { //SendMessage(LVM_DELETEALLITEMS, 0,0); // Clear all the previous listview item SendMessage((HWND)hList, LVM_DELETEALLITEMS, 0, 0); // Clear the previous column header for (idx=0; idx Any Suggestions of what to try? Reinart Laast, Junior Developer. Greetings from South Africa
You have two problems: 1. You're casting a
CListBox*
to anHWND
. This will not work because they are not the same thing. 2. You're sending the wrong messages. A list box doesn't understand list control messages.--Mike-- Visual C++ MVP :cool: LINKS~! Ericahist | PimpFish | CP SearchBar v3.0 | C++ Forum FAQ Ford, what's this fish doing in my ear?