|
First I want to populate a combobox with data from a recordset (I imagine I can store the strings in an array). Next I want a certain item (specified by name ) to be selected - I think that will make it show up in the editbox part. Then if I run down my list and click on another item, I want a certain function to run..
I checked the CComboBox class and its got index based function SetCUrSEl, not textstring based .
Is InitStorage necessary? Is this doing memory allocation like "new" does?
Aaargh! I wish I could get all the info clearly from MSDN.....
Thanks
Appreciate your help,
ns
|
|
|
|
|
Yeah, sure you read the docs...
AddString()?
FindStringExact()?
SetCurSel()?
GetCurSel()?
And for a wild guess, trapping ON_CBN_SELCHANG???
And you know what? IT IS IN THE DAMN DOCS.
(Sorry for being such an a**hole but lazy people are just driving me nuts)
"Well I'm just a hard working corporate slave, my mind should hate what my body does crave.
Well I'm just a humble corporate slave, driving myself into a corporate grave"
Corporate Slave, SNOG
|
|
|
|
|
I think what he meant is that the MSDN can be hard to understand sometimes...Unbelievably resourceful but the writer(s) often start talking about something and you understand what you have to put into your program but by then end of the sentence you have changed your mind because what you just read could mean one thing or another depending on how you look at it. At least in my opinion,
|
|
|
|
|
Basic design info:
Dialgo app, main window always up and one secondary dialog window can be broght up one at a time from the main window. Each window has a timer that updates based on data read from another computer. Most of the controls are buttons based on CButtonST. I use the m_MouseOnButton in the control to turn it on or off, thus this enables me to set the color and text on the button (is there a better way to do this????)
Problem: After this program runs for awhile it stops drawing the CButtonST subclassed controls and some of the drop downs start displaying a "6" instead of the down arrow. All the static and straight Visual Studios controls don't seem to have this problem (they are alway visable).
I've had this problem for quite some time now and have tried just about everything to make it go away. I thought that I was on to something when I slowed the timers and the problem took much longer to happen. So I figured that I was telling windows to draw too much. To many WM_PAINT messages, is this possible? Do VS controls have priority over subclassed controls? Does each item that has changed create a WM_PAINT message? Is this bad? Is there a better way?
Thinking along these lines I went into the code for every page and made it so that the controls would only be changed if the data received from the other computer had changed, thus it stopped drawing every cycle of the timer. This seem to help as now it really takes a long time for the problem to show up, but when it does it doesn't go away until I re-start the application.
This is my first VS MFC application and I've done it all with the help of this forum. So there is a good chance that maybe I overlooked something or am doing something that I shouldn't.
Any help would be much appriciated!!!!
Thanks!
|
|
|
|
|
It sounds to me like you are using up GDI resources and not freeing them. Have you done a Debug build and checked for memory leaks when your app closes?
Also try the www.GlowCode.com demo, which does a good job of reporting leaks. There are probably other apps around which help you track leaks as well.
Neville Franks, Author of ED for Windows. www.getsoft.com
Make money with our new Affilate program
|
|
|
|
|
I have been using the debugger and checked for memory leaks...haven't found any. I've also been watching the memory usage and CPU Time in the Windows Task Manager and the memory doesn't seem to change much and it doesn't just keep building...it uses some then it frees it when it's done.
Thanks I'm going to give the GlowCode a shot.
If I find the problem I'll let you all know...
Thanks!
|
|
|
|
|
DC and HANDLE leaks etc. won't show up as memory leaks, so you need other tools for these types of problems. I hope Glowcode helps you find the problem.
Neville Franks, Author of ED for Windows. www.getsoft.com
Make money with our new Affilate program
|
|
|
|
|
Try opening Task Manager and selecting the Processes tab. Open the View menu and choose 'Select Columns...'. Check the 'GDI objects' item. This will display a column for the number of GDI objects your application is using.
Software Zen: delete this;
|
|
|
|
|
I went and checked the GDI objects on the task manager and found that when I close the secondary window that I just opened the GDI object count doesn't decrease by the amount that was taken and will continue to grow as I open and close the page.
When I close the page I'm doing:
DestroyWindow();
PostNcDestroy();
My objects on the page are created using:
CButtonST Satus_RX;
CButtonST Satus_DUP;
CButtonST Satus_16F;
CButtonST Satus_16R;
etc.....
Then in InitDialog() I subclass them using:
Satus_RX.SubclassDlgItem(IDC_ALQ122_RX,this);
Satus_DUP.SubclassDlgItem(IDC_ALQ122_DUP,this);
Satus_16F.SubclassDlgItem(IDC_ALQ122_16F,this);
Satus_16R.SubclassDlgItem(IDC_ALQ122_16R,this);
Thus I'm under the impression that these will be delete with the window, am I wrong? What should I do now?
Also, I was looking at CButtonST and it appears that if m_MouseOnButton = 1 then it will re-draw the item every time. I set the button to 1 as this is how I display info from the other computer. example: if the other computer is ON then I set the mouse button to 1 so that its text displays "Running" and the Color is Green. If the other computer is off then the button is set to 0 and displays "OFFLINE" and the button is colored Red. Is this the wrong way to handle this?
Thanks for all the help guys. I've tried to download the GlowCode but haven't been able to yet....
|
|
|
|
|
You shouldn't be calling PostNcDestroy() yourself; it's called by the framework. Child windows are deleted by Windows when their parent is deleted.
I haven't used CButtonST . You might post/email a question to the author of the article it came from.
Software Zen: delete this;
|
|
|
|
|
Please let me know if you have any questions about using GlowCode, or about downloading an evaluation from www.glowcode.com/eval.htm.
Barbara Shafer
VP, Product Management
Electric Software, Inc. ~ developer of GlowCode
www.glowcode.com
|
|
|
|
|
In
int Box::AddString(LPCTSTR str)
{
if( _tcslen(str) == 0 )
why the tcslen? WHy not strlen? If I wanted to use wcslen (says its for wide characters) what would my argument look like?
Appreciate your help,
ns
|
|
|
|
|
ns wrote:
_tcslen
is the generic form of the command. It works for ANSI and UNICODE. If you compile for UNICODE it uses the wide character form of the strlen function, and for ANSI the strlen form.
So basically it future proofs your application. Its good practice to get into now.
Roger Allen
Sonork 100.10016
WHats brown and sticky?
A stick or some smelly stuff!
|
|
|
|
|
Good to know. MAny thanks. I did look in the MSDN but it was obtuse...
Appreciate your help,
ns
|
|
|
|
|
I read about _T in MSDN but am not clear :
It says _T is ignored in rgComboBox[index]->SetWindowText(_T("")); so why do it at all? Then when is it necessary to use L("")...I've seen that as well...
Appreciate your help,
ns
|
|
|
|
|
Basically, every (almost) type which starts with T , functions which start with _t are ANSI/UNICODE related.
#ifdef UNICODE
typedef wchar_t TCHAR;
#else
typedef char TCHAR;
#endif
typedef TCHAR* LPTSTR;
typedef const TCHAR* LPCTSTR;
size_t _tcslen(LPCTSTR);
LPTSTR _tcsdup(LPCTSTR);
You get the picture...
--
Eventhough the forrest is full of trees, there's still no tree between the trees.
|
|
|
|
|
|
You know how in IE (for example in my Favorites menu item), if you have too many items that go off the screen, it has a little downward pointing arrow at the end and if you hover on it, the menu items scroll up automatically....
Well, in my MFC project I created a submenu flyout which has 200 items in it. SO when I hover on the submenu the flyout shows up with the downward pointing arrow at the bottom where the list has gone off the screen. But it only moves upward if you press on this arrow, one item at a time, rather than the smooth automatic scroll one expects with windows stuff.....
Is there some sort of flag I can set when I create the popUpMenu that will allow this to happen?
Appreciate your help,
ns
|
|
|
|
|
I don't know the answer I'm afraid, but I can tell that I wouldn't be using an app that had 200 items on a menu.
Neville Franks, Author of ED for Windows. www.getsoft.com
Make money with our new Affilate program
|
|
|
|
|
I know - its goofy! THe items are merely informative...they dont respond to clicking. But I am considering saying in the flyout "All selected" (it reflects user choices). But I'm not the ultimate decider....
Then when the user does make a reasonable numbe rof selections the flyout can echo that.....
Appreciate your help,
ns
|
|
|
|
|
Got a quick question the following code works in the OnInitDialog function of CPropertySheet, however the same code does nothing in the OnInitDialog function of the CPropertyPage?
// CPropertySheet OnInitDialog code
CRect rect;
CPropertyPage *pPage = GetActivePage();
pPage->GetWindowRect(&rect);
ScreenToClient(&rect);
rect.right += 50;
rect.bottom += 50;
pPage->MoveWindow(&rect);
// CPropertyPage OnInitDialog code
CRect rect;
GetWindowRect(&rect);
ScreenToClient(&rect);
rect.right += 50;
rect.bottom += 50;
MoveWindow(&rect);
Now i know it shouldn't matter to me cause i got it working in the sheet, but it's driving me crazy knowing that this should work in each individual page as well!! Help me understand this craziness
|
|
|
|
|
ok, i have a CFormView that is displaying a form image in the background, and placing text on top of it, this is called CDisplayPrintTemplate, I implemented a dragging hand (like adobe's) which works fine.
now i have a new class which is derived from CDisplayPrintTemplate that puts CEdits on the form. When i try to drag the view the form and the text scroll still, but the CEdits just sit still. I have tried moving the dragging code into my new derived class, but the same thing still happens.. I can drag the scrollbar and scroll the window fine..
void CGAFormsView::OnMouseMove(UINT nFlags, CPoint point)
{
if (m_bDown == TRUE)
{
int nYPos = CFPCF::_round(((m_nStartDragY - point.y)) + m_nStartScrollPosY);
if (nYPos > GetScrollLimit(SB_VERT))
nYPos = GetScrollLimit(SB_VERT);
if (nYPos < 0)
nYPos = 0;
this->SetScrollPos(SB_VERT, nYPos, TRUE);
this->RedrawWindow();
}
else
{
::SetCursor(AfxGetApp()->LoadCursor (IDC_HAND_OPEN));
}
}
so what is different about how i am using SetScrollPos() versus how the scrollbar uses it (the scrollbar works fine)? any idea why can't i update the window without RedrawWindow() which causes everything to flicker?
still a newb.. cut me some slack :P
-dz
|
|
|
|
|
In my mainframe i have:
int nIndex2 = m_wndToolBar1.GetToolBarCtrl().CommandToIndex(ID_COMBO1);
int nIndex = m_wndToolBar1.GetToolBarCtrl().CommandToIndex(ID_SLIDER1);
if (!m_wndToolBar1.CreateSlider(m_wndToolBar1.m_slider1, nIndex, ID_SLIDER1, 100, 100))
{
TRACE0("Failed to create toolbar's slider\n");
return -1;
}
int nIndex1 = m_wndToolBar1.GetToolBarCtrl().CommandToIndex(ID_SLIDER2);
if (!m_wndToolBar1.CreateSlider(m_wndToolBar1.m_slider2, nIndex1, ID_SLIDER2, 100, 100))
{
TRACE0("Failed to create toolbar's slider\n");
return -1;
}
I just added the combobox to my class which had sliders before. But in the resource editor I put the ID_COMBO1 at the very end of all the buttons, and when I debug, nIndex2 is indeed as it should be.
However when I run it, the combobox shows up as a blank white space (sort of like an edit box), and its replaced another button that I had in the toolbar!!!!!!
ANy ideas on how to make this behave?
Appreciate your help,
ns
|
|
|
|
|
Its so bizzare! When I reloacted the segment of code that creates the combobox to after the creation of the sliders, it came up in the right place!!!! Strange since I was positioning it by CommandToIndex.....
Appreciate your help,
ns
|
|
|
|
|
My program is running on a Pocket PC and receives some characters, better say a string (like "grün" - thats the german word for GREEN) from a device.
I save the string in a CString . The problem is that when I display the string on my dialog I will see a wrong character for the 'ü' character of the string.
The asci code of the received character is 0x81, but that's the wrong character on my Pocket PC, the asci code für 'ü' on my Pocket PC should be -4 (= 252 = 0xFC).
How can I convert some characters?
Daniel
---------------------------
Never change a running system!
|
|
|
|