|
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
|
|
|
|
|
I have a operation which writes a string to a ListBox. Followed by anther function. The problem is the other function starts before the string is displayed in the list box. i:e
plistbox.AddString("xyx"); // writes string to list box
if(!(my_function()))
{
// fail
}
else
{
// pass
}
How do I make sure the ListBox has been updated before the next function is called.
Any help would be appreciated
Thanks
The problem is the next process seems to start before the string is displayed in the ListBox.
Desmond Mardle
|
|
|
|
|
Your problem has nothing to do with overlapping processes or anything like that. Try calling plistBox.RedrawWindow() after adding the string (and before calling my_function .)
Joaquín M López Muñoz
Telefónica, Investigación y Desarrollo
|
|
|
|
|
Thanks for your help. Problem solved:
Desmond Mardle
|
|
|
|
|
If I understand the problem correctly try:
UpdateData(FALSE);
Between writing the string and calling the function.
Mike Mullikin - People demand freedom of speech as a compensation for the freedom of thought which they seldom use.
Soren Kierkegaard
|
|
|
|
|
Hello,
In this type of application where the left pane is a treeview and the right pane is a listview, how do you keep the input focus on the left pane?
Example, I need to be able to perform needed operations on the right pane while the item in the tree is selected.
Is this possible?
Thanks,
Frank
|
|
|
|
|
I'm trying to get a handle (no pun) on threads.
I've got a function that calls two functions one after the other then returns. I'd like to multithread it because the functions lock up the UI in my App.
So...Question #1: When multithreading a function are the actions performed in the functions called from that function also performed in the new thread?
Question #2: Whats the easiest way to implement something like this?
Frank
|
|
|
|
|
#1. Yes. The whole function is executed in the new thread, which exits when the function exits. For instance:
DWORD WINAPI MyThread(LPVOID arg){
function1();
function2();
return 0;
}
DWORD dwThreadId;
HANDLE hThread=CreateThread(
NULL,
0,
MyThread,
NULL,
0,
&dwThreadId
);
#2: The code above just answer this. For production level code you'll need some more stuff (to control when the thread exists, for instance) but this piece of code should get you started.
Joaquín M López Muñoz
Telefónica, Investigación y Desarrollo
|
|
|
|
|
Great! Thanks for the info.
Frank
|
|
|
|
|
I never want any scrollbars to show up in my MDI. Any way? I tried tthe cs but it want realy responsive. MAybe I didnt try enough? ?
Thanks,
ns
|
|
|
|
|
I am going to have to abandon my oh-so-cool MDI approach since I cant get around a movewindow issue which I'll describe in a bit. SO I am thinking SDi. But I need two views. Can an SDI handle two views?
The MDI dilemma:
Four edit boxes are supposed to hug the right edge always, even on resize. SO onsize I did movewindow setting the top y value to 10, 50, etc....
Fine. But if I scroll without resize, and some are off the visible part, then resize, they immediately pop back at 10, 50 etc from the top edge, leaving a big blank space above in the scrolled off portion. No matter whats the visible screen area, they alwyas show up at 10,50 etc from the top, on resize, leaving gaps where they should have been....
Any solution to this? I do like the MDI otherwise. LOts of hard work ahead if SDi wont do two views....
Thanks,
ns
|
|
|
|
|
Not sure exactly haw you are doing your scrolling, but when you do a resize, it seems to me you are not taking the scrolled distance into account when you calculate the new position of the edit controls, you are just simply placing them X distance from the top of your client area.
---
CPUA 0x5041
Sonork 100.11743 Chicken Little
Within you lies the power for good - Use it!
|
|
|
|
|
The scrollbars come up automatically since my CFormView is too big (by design) for the Client window.
I tried putting the repositioning in the OnScroll event as well, but now its as if theres no scrollability for those controls!!! So my fix is not right. Can I bother you for more hints on how to calculate how much I scrolled and take that into account? I cant quite see what I am to do here. I'd really really appreciate your help,
Thanks,
ns
|
|
|
|
|
My guess is that you are doing something like :
void CMyFormView::OnSize(UINT nType, int cx, int cy)
{
m_MyEditCtrl.MoveWindow(cx - EditCtrlWidth, 50, EditCtrlWidth, EditCtrlHeight);
... in order to place the edit control at the right edge, 50 pixels from the top.
What you have to do is call GetScrollPosition() to figure the scrolling into the calculation
void CMyFormView::OnSize(UINT nType, int cx, int cy)
{
int HScrollDistance = GetScrollPosition().y;
m_MyEditCtrl.MoveWindow(cx - EditCtrlWidth, 50 - HScrollDistance, EditCtrlWidth, EditCtrlHeight);
...
HTH
---
CPUA 0x5041
Sonork 100.11743 Chicken Little
Within you lies the power for good - Use it!
|
|
|
|
|
I am totally overwhelmed. I have been so stressed out over this, and was going to do a dialog based app instead of the cool mDI, and this was really distressing. I've tried your solution on one of my boxes and its behaving wonderfully. I wont breathe until I check it out on the whole UI but I am most hopeful!
You have saved my life literally! I am very grateful.
I had looked around for some function like this but it wasnt in the class wizard or in the members of the class CView either...where is it inherited from?
ANother associated question. This has been happening with my editboxes so I have to do something like(to prevent a debug assert). If I dont put your statement inside the if, it debug asserts. If I didnt have an editbox I was checking for, how would I have handled the assert? Which objects GetSafeHWnd would I test? I dont know if this is clear but its something I'd like to know about, if you have any ideas why....
if( NULL != m_editright.GetSafeHwnd() )
{
int VScrollDistance = GetScrollPosition().y;
m_editright.MoveWindow(cx - 200, 50 - VScrollDistance, 200, 200);
// m_editright.MoveWindow(cx-200,360,200, cy-60);
}
Thank you,
ns
|
|
|
|