titbits from the world less travelled

Archive for the 'visual studio' Category

Using CListBox in windows especially in pop up windows

I had an opportunity to use CListbox. The scenario was that I had to pre populate the list box and display it in a pop up window.

Its very to use listbox when using it in a parent window but when you want to display it in a standalone pop up window, you would get an error.

This is because the data is present only after the window comes into picture completely and is gone when the window disappears. In order to rectify this you would need to over rider the Initdialog method as below:

BOOL OnInitDialog()
{
//check if the parent window dialog is also initialized
if(CDialog::OnInitDialog())
{
//enter the values into the listbox here
}
}

By the above code you can enter into a listbox before its displayed.

Declare the below methods in the header file for getting the list selection changes:
afx_msg void OnLbnSelchangeList1();
afx_msg void OnLbnDblclkList1();

Add them to the message map in the class as below:

BEGIN_MESSAGE_MAP(YourClassname, CWnd)
ON_LBN_SELCHANGE(IDC_LIST1, &YourClassname::OnLbnSelchangeList1)
ON_LBN_DBLCLK(IDC_LIST1, &YourClassname::OnLbnDblclkList1)
END_MESSAGE_MAP()

Over ride them with the functionalities you need as below:
void YourClassname::OnLbnSelchangeList1()
{

}

void YourClassname::OnLbnDblclkList1()
{
// TODO: Add your control notification handler code here
}

Use CArray to get the values:

CArray aryListBoxSel;
aryListBoxSel.SetSize(nCurrentSelected);
m_ListBox1.GetSelItems(nCurrentSelected, aryListBoxSel.GetData());
CString sTitle;
int indexVal = 0;

for(int i=0;i<=aryListBoxSel.GetUpperBound();i++)
{
indexVal = aryListBoxSel.GetAt(i);
m_ListBox1.GetText(indexVal, sTitle);
}
---------------------------------------------------------------------------------------------------
Incase CArray gives a error in vc6 you can do the following:

int Count = m_ListBox1.GetSelCount();
if (Count > 0)
{
int *pSels = new int[Count];
m_ListBox1.GetSelItems(Count,pSels);
for (int i = 0; i < Count;i++)
{
//pSels[i] this is the index of the item that was selected
CString Temp;
m_ListBox1.GetText(pSels[i],Temp);
}
delete [] pSels;
}

posted by admin in c++, msdn, visual studio, windows and have No Comments

error C2065: ‘CArray’ : undeclared identifier in visual studio

You would be getting this error if you tried to use CArray in VC 6. You would need to use some other way to get the values selected in listbox. In my next post I would be showing how to use two different ways to access a CListBox.

posted by admin in c++, msdn, visual studio, windows and have No Comments

Detecting memory leaks in VC++

One of the simplest ways to detect a leak in your code would be to use debugCRT.

Simple usage:
a. Create you project in visual studio
b. run the project in debug mode, then only you will find the memory leak dumps
int main()
{
_CrtSetDbgFlag(_CRTDBG_CHECK_ALWAYS_DF | _CRTDBG_ALLOC_MEM_DF);
//below call will break where the leak is in the code provided you give the error number as shown in the //dump.
_CrtSetBreakAlloc(108);

// your code here

//Below windows API will dump the leaks
_CrtDumpMemoryLeaks();
return 0;
}

posted by admin in c++, msdn, visual studio, windows and have No Comments

comparing two systemtime variables using filetime in vc++

lets take a look at how to compare two systemtime variables but using Filetime to do so. We make use of the utility method CompareFiletime to do this.

1) store the systemtime in a variable
2) convert it into filetime. Use this method
SystemTimeToFileTime(&systemtime1, &filetime1)

SystemTimeToFileTime(&systemtime2, &filetime2)
3) Compare the filetimes using the method
CompareFileTime(&filetime1, &filetime2) > 0

4) finally convert the filetime to systemtime using the method
FileTimeToSystemTime(..)

posted by admin in c++, msdn, windows and have No Comments

[VC compile error] uuid.lib : fatal error LNK1103: debugging information corrupt; recompile module

This happens usually because in your visual studio vc6 compiler options you would have set the library files path to “Microsoft platform SDKs” , which uses the newer library files. Goto the option again and then set to “Microsoft SDKs” which is set to older SDK. this will help to solve your problem.

posted by admin in c++, visual studio and have No Comments

Error result -1073741819 returned from ‘C:\Program Files\Microsoft Visual Studio 9.0\VC\bin\cl.exe’

I kept getting the above error. The most logical reason I found was related to my computer. I had installed a Antivirus called spycatcher with an out dated 4.x version. This was preventing most of my exe’s to start or run. This is just a guess. Since I uninstalled this application and everything worked fine. Else the other application I installed was bit defender 4.x on the same computer. I think both of these made a potent mix and was not letting my computer function as required.

The reason with the error as you see is that the .exe, is not allowed to run or execute which in turn throws the error.

FYI, I tried all else like replacing the libraries and so on. It didnt work.

Tags:
posted by admin in Uncategorized, c++, visual studio and have No Comments

Error result -1073741819 returned from 'C:\Program Files\Microsoft Visual Studio 9.0\VC\bin\cl.exe'

I kept getting the above error. The most logical reason I found was related to my computer. I had installed a Antivirus called spycatcher with an out dated 4.x version. This was preventing most of my exe’s to start or run. This is just a guess. Since I uninstalled this application and everything worked fine. Else the other application I installed was bit defender 4.x on the same computer. I think both of these made a potent mix and was not letting my computer function as required.

The reason with the error as you see is that the .exe, is not allowed to run or execute which in turn throws the error.

FYI, I tried all else like replacing the libraries and so on. It didnt work.

Tags:
posted by admin in Uncategorized, c++, visual studio and have No Comments