|
Hello,
I'm working on an MFC application. For reasons I cannot fathom, there seems to be a problem with inconsistent display of the icons of an icon style CListCtrl between versions of Windows (XP and Vista). On Vista, one of the icons (Debtor statement) is omitted. This only occurs sometimes. When it actually occurs varies from build to build of the application, where changes between builds ought to have no bearing on this at all.
Why might this be? How can the problem be fixed? Here is the relevant code:
CMyReportView::OnInitialUpdate()
{
CFormView::OnInitialUpdate();
ModifyStyleEx(WS_EX_CLIENTEDGE, 0, SWP_FRAMECHANGED);
ReportsCtrl.ModifyStyle(0, LVS_AUTOARRANGE);
// Send an ID_RELOAD rather than calling UpdateStateData() directly - this is
// a hack to work around the problem of no icons being displayed initially
// in release build
SendMessage(ID_RELOAD );
}
CMyReportView::UpdateData()
{
CBitmap sales_bitmap,
daily_reconciliation_bitmap,
debtor_statement_bitmap,
debtor_invoice_bitmap,
voided_items_bitmap,
suspended_sales_bitmap,
stock_count_rep_bitmap,
live_stock_figures_bitmap,
sales_by_item,
pos_download_bitmap;
sales_bitmap.LoadBitmap(IDB_SALES);
daily_reconciliation_bitmap.LoadBitmap(IDB_DAILY_RECONCILIATION);
debtor_statement_bitmap.LoadBitmap(IDB_DEBTOR_STATEMENT);
debtor_invoice_bitmap.LoadBitmap(IDB_DEBTOR_INVOICE);
voided_items_bitmap.LoadBitmap(IDB_ICON_VOID);
suspended_sales_bitmap.LoadBitmap(IDB_SUSPENDED_SALES_ICON);
stock_count_rep_bitmap.LoadBitmap(IDB_STOCK_COUNT_REPORT_ICON);
live_stock_figures_bitmap.LoadBitmap(IDB_ICON_LIVE_STOCK_FIGURES);
sales_by_item.LoadBitmap(IDB_SALES_BY_ITEM_ICON);
pos_download_bitmap.LoadBitmap(IDB_POS_DOWNLOAD_REPORT_ICON);
COLORREF rgbTransparentColour = RGB(255, 255, 255);
imgl.Create(64, 64, ILC_MASK | ILC_COLOR32, 0, 0);
int sales_bit_id = imgl.Add(&sales_bitmap, rgbTransparentColour);
int daily_rec_bit_id = imgl.Add(&daily_reconciliation_bitmap, rgbTransparentColour);
int debtor_stat_bit_id = imgl.Add(&debtor_statement_bitmap, rgbTransparentColour);
int debt_invo_bit_id = imgl.Add(&debtor_invoice_bitmap, rgbTransparentColour);
int voided_itms_bit_id = imgl.Add(&voided_items_bitmap, rgbTransparentColour);
int suspend_sls_bit_id = imgl.Add(&suspended_sales_bitmap, rgbTransparentColour);
int stock_count_bit_id = imgl.Add(&stock_count_rep_bitmap, rgbTransparentColour);
int live_stock_figures_bit_id = imgl.Add(&live_stock_figures_bitmap, rgbTransparentColour);
int sales_by_item_bit_id = imgl.Add(&sales_by_item, rgbTransparentColour);
int pos_day_end_download_bit_id = imgl.Add(&pos_download_bitmap, rgbTransparentColour);
ReportsCtrl.SetImageList(&imgl, 0);
LVITEM lvi0;
lvi0.mask = LVIF_IMAGE | LVIF_TEXT;
lvi0.iSubItem = 0;
lvi0.pszText = "Sales report";
lvi0.iImage = sales_bit_id;
LVITEM lvi1;
lvi1.mask = LVIF_IMAGE | LVIF_TEXT;
lvi1.iSubItem = 0;
lvi1.pszText = "Daily reconciliation report";
lvi1.iImage = daily_rec_bit_id;
LVITEM lvi2;
lvi2.mask = LVIF_IMAGE | LVIF_TEXT;
lvi2.iSubItem = 0;
lvi2.pszText = "Debtor statement";
lvi2.iImage = debtor_stat_bit_id;
LVITEM lvi3;
lvi3.mask = LVIF_IMAGE | LVIF_TEXT;
lvi3.iSubItem = 0;
lvi3.pszText = "Debtor invoice";
lvi3.iImage = debt_invo_bit_id;
LVITEM lvi4;
lvi4.mask = LVIF_IMAGE | LVIF_TEXT;
lvi4.iSubItem = 0;
lvi4.pszText = "Voided items report";
lvi4.iImage = voided_itms_bit_id;
LVITEM lvi5;
lvi5.mask = LVIF_IMAGE | LVIF_TEXT;
lvi5.iSubItem = 0;
lvi5.pszText = "Suspended sales report";
lvi5.iImage = suspend_sls_bit_id;
LVITEM lvi6;
lvi6.mask = LVIF_IMAGE | LVIF_TEXT;
lvi6.iSubItem = 0;
lvi6.pszText = "Stock count report";
lvi6.iImage = stock_count_bit_id;
LVITEM lvi7;
lvi7.mask = LVIF_IMAGE | LVIF_TEXT;
lvi7.iSubItem = 0;
lvi7.pszText = "Live stock figures report";
lvi7.iImage = live_stock_figures_bit_id;
LVITEM lvi8;
lvi8.mask = LVIF_IMAGE | LVIF_TEXT;
lvi8.iSubItem = 0;
lvi8.pszText = "Sales by item report";
lvi8.iImage = sales_by_item_bit_id;
LVITEM lvi9;
lvi9.mask = LVIF_IMAGE | LVIF_TEXT;
lvi9.iSubItem = 0;
lvi9.pszText = "POS day-ends report";
lvi9.iImage = pos_day_end_download_bit_id;
int sales = ReportsCtrl.InsertItem(&lvi0);
ReportsCtrl.SetItemData(sales, 1);
int daily_reconcil = ReportsCtrl.InsertItem(&lvi1);
ReportsCtrl.SetItemData(daily_reconcil, 2);
int debtor_statement = ReportsCtrl.InsertItem(&lvi2);
ReportsCtrl.SetItemData(debtor_statement, 3);
int debtor_invoice = ReportsCtrl.InsertItem(&lvi3);
ReportsCtrl.SetItemData(debtor_invoice, 4);
int voided_items = ReportsCtrl.InsertItem(&lvi4);
ReportsCtrl.SetItemData(voided_items, 5);
int suspended_sales = ReportsCtrl.InsertItem(&lvi5);
ReportsCtrl.SetItemData(suspended_sales, 6);
int stock_count = ReportsCtrl.InsertItem(&lvi6);
ReportsCtrl.SetItemData(stock_count, 7);
int live_stock_figures = ReportsCtrl.InsertItem(&lvi7);
ReportsCtrl.SetItemData(live_stock_figures, 8);
int sales_item = ReportsCtrl.InsertItem(&lvi8);
ReportsCtrl.SetItemData(sales_item, 9);
int pos_download = ReportsCtrl.InsertItem(&lvi9);
ReportsCtrl.SetItemData(pos_download, 10);
ReportsCtrl.SetItemState(ReportsCtrl.GetItemCount() - 1, LVIS_SELECTED | LVIS_FOCUSED, LVIS_SELECTED | LVIS_FOCUSED);
}
Any assistance is greatly appreciated.
Regards,
Sternocera
|
|
|
|
|
I seem to have isolated the problem somewhat (It still erratically tends to swing between omitting and not omitting the icon between builds, I guess).
By commenting out:
ReportsCtrl.ModifyStyle(0, LVS_AUTOARRANGE);
I can make the problem disappear (although I have a new problem, which is that the icons are displayed as one big column). Commenting out anything else of note doesn't have the effect of suppressing the problem, so I guess that's progress.
Regards,
Sternocera
|
|
|
|
|
Hi Sternocera,
Where are you setting the column width?
|
|
|
|
|
Hi Randor,
I'm not - it isn't a report style CListCtrl, it's an icon style CListCtrl. I understand that column width isn't set with an icon style CListCtrl.
Regards,
Sternocera
|
|
|
|
|
Have you entertained the possibility of a bad/corrupt/outdated icon cache? I've had it happen once with an older version of Windows, so it's probably not a common problem.
"Old age is like a bank account. You withdraw later in life what you have deposited along the way." - Unknown
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
|
|
|
|
|
That seems like a reasonable explanation. I've found that moving the initialisation of the icons into OnIntialUpdate seems to fix the problem, but I'm not overly confident that it hasn't just temporarily concealed the problem.
I'll delete the cache to be sure.
Regards,
Sternocera
|
|
|
|
|
Where is imgl declared? Is its lifetime longer than the lifetime of the list control?
It's a good idea to always zero-init structs, like LVITEM , so that you aren't accidentally sending garbage data in the members that you don't explicitly set.
--Mike--
Dunder-Mifflin, this is Pam
|
|
|
|
|
Hi Mike,
Yes, imgl is declared in the same class definition as the CListCtrl. I have now zero initialised the LVITEM structs. Thanks for your help.
Regards,
Sternocera
|
|
|
|
|
There is a method that allows adjustment of the icon width: SetIconSpacing() You might try playing around with that.
|
|
|
|
|
I haven't had a re-occurrence since I simply initialised my structs, but thanks for pointing that out.
|
|
|
|
|
Hi,
I am working on an application, which calls a WPF page in MFC exe and loads it too, but the backgound for the WPF is coming black.
here is code snippet
Declaration
using namespace System;
using namespace System::Windows;
using namespace System::Windows::Controls;
using namespace System::Windows::Media;
ref class Globals
{
public:
static System::Windows::Interop::HwndSource^ gHwndSource;
static WpfApplication1::Window1^ gwcContainer;
};
i have added in oninitdialog,
System::Windows::Interop::HwndSourceParameters^ sourceParams = gcnew System::Windows::Interop::HwndSourceParameters("MyWindowName");
sourceParams->PositionX = 20;
sourceParams->PositionY = 30;
sourceParams->ParentWindow = System::IntPtr(this->GetSafeHwnd());
sourceParams->WindowStyle = WS_VISIBLE | WS_CHILD;
System::Windows::Interop::HwndSource^ source = gcnew System::Windows::Interop::HwndSource(*sourceParams);
source->SizeToContent = System::Windows::SizeToContent::WidthAndHeight;
Globals::gwcContainer = gcnew WpfApplication1::Window1();
FrameworkElement^ myPage = Globals::gwcContainer;
source->RootVisual = myPage;
I dont want the black color around.
Any help is highly appriciated.
Thanks&Regards,
KDevloper
|
|
|
|
|
I got 1231 error value when using the code below.
1231: The network location cannot be reached. For information about network troubleshooting, see Windows Help.
my lan and internet is working fine.
then where is actually the problem residing.
HANDLE hIcmpFile;
unsigned long ipaddr = INADDR_NONE;
DWORD dwRetVal = 0;
char SendData[] = "Data Buffer";
LPVOID ReplyBuffer = NULL;
DWORD ReplySize = 0;
ipaddr = inet_addr((const char*)m_sAddress);
ReplySize = sizeof(ICMP_ECHO_REPLY) + sizeof(SendData) +1;
ReplyBuffer = (VOID*)malloc(ReplySize);
hIcmpFile = IcmpCreateFile();
if (hIcmpFile == INVALID_HANDLE_VALUE)
{
return -1;
}
dwRetVal = IcmpSendEcho(hIcmpFile, ipaddr, SendData, sizeof(SendData) + sizeof(ICMP_ECHO_REPLY), NULL, ReplyBuffer, ReplySize, 500);
if(dwRetVal != 0)
{
PICMP_ECHO_REPLY pEchoReply = (PICMP_ECHO_REPLY)ReplyBuffer;
struct in_addr ReplyAddr;
ReplyAddr.S_un.S_addr = pEchoReply->Address;
m_sMessage.Format(_T("Received from %s Status = %ld RoundTripTime = %ld"), inet_ntoa(ReplyAddr), pEchoReply->Status, pEchoReply->RoundTripTime);
return 0;
}
Future Lies in Present.
Manmohan Bishnoi
|
|
|
|
|
If you want to use ping from your application, have a look at boost::asio. Boost have a ping example program that you may be able to adopt. Note that your application requires administrative privileges on Vista to create ICMP packets.
Regards,
Sternocera
|
|
|
|
|
Manmohan29 wrote: I got 1231 error value when using the code below.
From GetLastError() ?
"Old age is like a bank account. You withdraw later in life what you have deposited along the way." - Unknown
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
|
|
|
|
|
yes
Future Lies in Present.
Manmohan Bishnoi
|
|
|
|
|
Do you get that error for all addresses?
"Old age is like a bank account. You withdraw later in life what you have deposited along the way." - Unknown
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
|
|
|
|
|
yes same for all IP's.
My OS is Windows Seven RC.
I have also tested this on XP. There also the problem is same.
Future Lies in Present.
Manmohan Bishnoi
|
|
|
|
|
I suggest you try others examples from here.
"Old age is like a bank account. You withdraw later in life what you have deposited along the way." - Unknown
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
|
|
|
|
|
How to plug/unplug USB serial port problematically?
I am facing some strange issue with my USB serial port.
I want to unplug and plug the USB Serial port Programitically, as i need to refresh the connection between system and hardware connected.Kindly help.......
Thank in advance for the great programmers
|
|
|
|
|
pallaka wrote: I want to unplug and plug the USB Serial port Programitically, as i need to refresh the connection between system and hardware connected.
You cannot do that from user mode. You must ask the driver for that functionality if it supports it at all, which I doubt when it comes to serial port drivers for USB.
pallaka wrote: I am facing some strange issue with my USB serial port.
Perhaps you can elaborate on what the "strange issue" is all about.
It's quite possible that there is another solution than resetting the port/device.
What have you done so far and what problems are you facing that you want to solve by resetting the port?
"It's supposed to be hard, otherwise anybody could do it!" - selfquote "High speed never compensates for wrong direction!" - unknown
|
|
|
|
|
Hi All,
I have a basic question , i have a dialog based application and in the App class we create an object for the dialog class and do DoModal()in InitInstance() of the App class ..
Can anyone tell me when Run the Application How the InitInstance will get called or the other of calls made which calls the App classes InitInstance()
Thanks,
Hari
|
|
|
|
|
There's a very easy way to check that: put a breakpoint in the function and start your debugger. Once the breakpoint is hit, take a look at the callstack.
|
|
|
|
|
I tried it and it says AfxWinMain() can anybody explain in detail and thks for the quick reply.
|
|
|
|
|
Hari_16 wrote: can anybody explain in detail
See here[^]. It's an old article but I think it will already give you valuable information.
|
|
|
|
|
Hari_16 wrote: Who calls InitInstance()?
God.
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong.
-- Iain Clarke
[My articles]
|
|
|
|