|
That is true. I forgot that one, sorry.
Christian
come on all you MS suckups, defend your sugar-daddy now. - Chris Losinger - 11/07/2002
|
|
|
|
|
Thank you both for your help. It's working fine now.
But i had to do a minor change in your code sample.
CBand *selectedItem = dynamic_cast<cband*>( (CObject*)
m_treeMain.GetItemData(
m_treeMain.GetSelectedItem() ));
if( selectedItem )
{
AfxMessageBox( selectedItem->GetBandName() );
}
I don't know why but it didn't directly cast from DWORD to CBand and gave the following message :
error C2681: 'unsigned long' : invalid expression type for dynamic_cast
So i decided to cast it to CObject* first. Frankly, i didn't quite understand why this change made it work, but it did, so i just moved on
Anyway, thanks again.
|
|
|
|
|
hi all,
I found an article about I have an excel automation dos based application . I take an article,
Automate excel from c++ without using mfc or #import (Q216686) as an example.
then based on another article Automate excel and then know the use closed it(Q192348)
I changed my code again. actually, i added,
<br />
<br />
HWND hWnd;<br />
char buf[1024];<br />
hWnd = ::FindWindow("XLMain",NULL);<br />
if(NULL==hWnd)<br />
{<br />
long lErr = GetLastError();<br />
sprintf(buf, "FindWindow Error code = %d",lErr);<br />
AfxMessageBox(buf);<br />
}<br />
<br />
DWORD pid;<br />
DWORD dThread;<br />
DWORD dwReason;<br />
dThread = ::GetWindowThreadProcessId(hWnd,&pid);<br />
HANDLE hProcess;<br />
hProcess = ::OpenProcess(SYNCHRONIZE|PROCESS_ALL_ACCESS,TRUE,pid);<br />
<br />
dwReason = ::WaitForSingleObject(hProcess,INFINITE);<br />
::CloseHandle(hProcess);<br />
everything is fine except
dwReason = ::WaitForSingleObject(hProcess,INFINITE);
is waiting forever because in windows task manager's processes tab, you will find EXCEL.EXE eventhough you have closed ms excel application.
if you command the line
dwReason = ::WaitForSingleObject(hProcess,INFINITE);
you will not find EXCEL.EXE in windows task manager's processes tab.
why is that?
|
|
|
|
|
can someone help me please
|
|
|
|
|
G'Day Win,
I use the same code successfully. What I discovered was that as I developed the application I would run it and terminate it prematurely with Excel open. This of course did not close down excel properly. So that when I started the application again I had 2 versions of excel running etc. Thus when I had a 'real' excel application running and I tested my program and shut excel down this code failed because I had closed down a different excel to the one being watched. I think this is what may be happening in your case. So terminate all excel processes with task manager, run excel and then your application and see if it works then.
Hope that is of some help,
Richard.
|
|
|
|
|
thank you Richard.
that's is a really helpful. Thanks
|
|
|
|
|
I need to handle the WM_MOUSEMOVE message for my tree control. I've been told that I have to derive a class from my tree control and handle mousemove int there but I can't figure out how to derive the class from my tree control.
-Raffi
|
|
|
|
|
It's simple. Launch the MFC wizard (CTRL+W) and create a new class selecting CTreeCtrl as the base class (call it CMyTreeCtrl , for instance.) Handle WM_MOUSEMOVE in the new class. Now, where you defined a variable of type CTreeCtrl , replace CTreeCtrl with CMyTreeCtrl (you'll need to include "mytreectrl.h" , also.) That's it.
Joaquín M López Muñoz
Telefónica, Investigación y Desarrollo
|
|
|
|
|
I previously have all my tree control code in my view class. Do I have to move all my tree control code to this new class or will it work with just leaving it as is and doing what you said above?
-Raffi
|
|
|
|
|
It'll work by only replacing CTreeCtrl with the new class, you can leave all the other stuff where it was
Joaquín M López Muñoz
Telefónica, Investigación y Desarrollo
|
|
|
|
|
worked perfectly, thanks a lot
-Raffi
|
|
|
|
|
Hi All
I am trying to connect to SQL Server using the ODBC classes. In my sql to CRecordset.Open, I provide a query which looks like:
CString sSql = "select ani from cxcu where company = ' + sCompany;
cxcu is a very large table and the query will return upward of 600k records. I am also turning on the CRecordset::useMultiRowFetch option.
What I want to do is to lookup an "ani" ( from above query ) and check if it exists in the table or not.
Would it make sense if I connected with a NULL string and then called Requery()? I am having to wait for a very long time (in excess of 15 minutes) for the CRecordset.Open(...) to complete.
What would be the best way to do this lookup of a record in amongst 600k+ using CRecordset?
Thanks
ashish
|
|
|
|
|
Have you investigated as to how long will it take for the query to execute from QueryAnalyzer in SQlServer itself? If not you may want to do that and then see what type of indexing may be required to make your query go faster.
If the existing WHERE clause is returning 600K plus records and you wish to run this query only to see if this company exists then try to tighten the WHERE clause such that the number of records returned is smaller.
|
|
|
|
|
Thanks Ranjan. Here is what I am currently doing:
Since the lookup has to be from a table with 600k+ records, I have to load it using CRecordset.Open. This would take me upwards of 10-15 minutes.
Now, to avoid this, what I am having to do is to call CRecordset.Open and CRecordset.Close to check each input value.
So what I am doing is setting the SQL and m_strFilter for each check I am performing. I am lucky that the field "ani" is indexed in the database.
Surely there is better way to do this????
thanks
ashish
|
|
|
|
|
I've just started learning VisualC++. I'm using Ivor Horton's book "Introduction to MS VisualC++ Standard Edition". I'm in chapter "MFC Dialog Programming".
I have a problem with a ComboBoxEx.
I put it on a form and add a member variable for it (Variable type is set to Value) m_strCboEx. Then, I add several items to the item-list.
At this stage, everything is working as I expected - whatever I choose in a running program it goes to m_strCboEx.
However, when I change combo's style to DropList - m_strCboEx is always an empy string at the end.
Why is it so?
I tried to use standard ComboBox instead of ComboBoxEx and in this case everything was OK.
I don't understand...
Can you help me?
Maciek Niedzielski
|
|
|
|
|
I have a CEdit control on a CFormView (didnt create it in code). I set its visible property to invisble. Now I want it to show up at runtime under certain conditions. How do I do this? Says Visible(TRUE) is not a property of Cedit....
Thanks,
Ns
|
|
|
|
|
OOps! It was ShowWindow(SW_SHOW).
Thanks anywyas,
ns
|
|
|
|
|
If anyone could help me with this I'd appreciate it.....
I've been trying to find out how to open a serial COM port through Visual C++ 6.0.
There is a sample code at http://www.codeproject.com/managedcpp/howtocomport.asp , but it doesn't work in Visual C++...
does anyone know what changes I have to make??
|
|
|
|
|
HANDLE hPort=CreateFile(
"\\\\.\\COM1",GENERIC_READ|GENERIC_WRITE,0,NULL,
OPEN_EXISTING,0,NULL);
Joaquín M López Muñoz
Telefónica, Investigación y Desarrollo
|
|
|
|
|
Hi.
I have discovered a major bug in a simple program. The problem has a propertysheet. There are two pages the are almost exactly the same. Both pages have a CListCtrl box. In both pages, the user can add items, select items, and/or remove existing items.
For some reason, only one page worked in the *release* version of the program. Everything worked perfect in debug mode, but one page crashed in release. The page that crashed does so in the same manner every time. Below is a logs of the crash.
// debug log
-----
// this occurs AFTER the user options a propertysheet
// program does NOT crash at this point
First-chance exception at 0x7196254a in myProgram: 0xC0000005: Access violation writing location 0x00463b2c.
// this occurs when the user selects an item in a CListCtrl box
// program crashes at this point
First-chance exception at 0x046936d7 in myProgram: 0xC0000005: Access violation reading location 0x046936d7.
Unhandled exception at 0x046936d7 in myProgram: 0xC0000005: Access violation reading location 0x046936d7.
The program '[1120] myProgram: Native' has exited with code 128 (0x80).
-----
I have no idea how to fix this problem. I have compared the two property pages I mentioned that have the CListCtrl boxes. The code in both property pages are flawless.
First, I thought the program crashed because there was a code program in the function that determines what item is selected in the CListCtrl box. However, I have found that the program does not crash at all inside that function. It crashed sometime after leaving the function.
Is this a memory problem? Please post if you have any idea on debugging this problem.
Thanks,
Kuphryn
|
|
|
|
|
Unless there's someone else here with strong divination capabilities, a little more help from you would be great. It could have to do with the data you're using to feed the controls (uninitialized arrays or something.) You can also take a poor-man approach to release mode debugging plaguing your code with MessageBox es and try to determine the exact location where the error is happening.
Joaquín M López Muñoz
Telefónica, Investigación y Desarrollo
|
|
|
|
|
Thanks.
When the program crashed, Visual C++ points to the line that caused the crash. In this case, it points to the following line from *cmdtarg.cpp*.
Note: cmdtarg.cpp is NOT part my the program. I have no idea what where Visual C++ gets it.
-----
// cmdtarg.cpp
#endif //_DEBUG
// this line
-> return _AfxDispatchCmdMsg(this, nID, nCode,
lpEntry->pfn, pExtra, lpEntry->nSig, pHandlerInfo);
}
}
-----
Kuphryn
|
|
|
|
|
Seems like somehow you have corrupted the stack. Is there any loop in one of your handlers that might be going out of bounds?
Joaquín M López Muñoz
Telefónica, Investigación y Desarrollo
|
|
|
|
|
To be honest with you, I have no idea where to even start debugging it.
My best guess right now is it has something to do with maybe the property sheet because this problem occurs after the user opens options.
Kuphryn
|
|
|
|
|
Okay. I have found the problem.
The problem has to do with the way I was determining the state of an item in a CListCtrl. I had to change the algorithm. Now the program no longer crashes.
MFC does some really weird stuff in the background. Be careful or you might end up with many problems.
Kuphryn
|
|
|
|