|
http://www.codeproject.com/dialog/dlgboxtricks.asp[^]
A little over half way down the page. The method described works with dialogs, and should also work with form views.
CPUA 0x5041
Sonork 100.11743 Chicken Little
"So it can now be written in stone as a testament to humanities achievments "PJ did Pi at CP"." Colin Davies
Within you lies the power for good - Use it!
|
|
|
|
|
I have a class that is a data consumer with an identification number, when an object is instantiated a temporary ID is assigned to the object until it can dynamically aquire it's "real" number.
I have a CListCtrl that displays a list of these objects with their IDs as the label. As an object is created it needs to be displayed in this control so obviously the temporary ID is used until the real one comes along. The control is updated every second and when the new ID gets updated in the obj I need to be able to update the control to reflect this change without adding an additional line and leaving the old one hanging around. What I've done is, because the ojects are stored in a CMap, I store the key for each object in the ItemData of the list item. But when I go to pull the item data out, I don't always get the data I put in there. My code is below:
POSITION Pos = m_IndexToObjectMap.GetStartPosition();
long key = 0;
CString name = _T(" ");
CString id = _T(" ");
CDataClass Obj;
while(Pos != NULL){
bool bItemInList = false;
m_IndexToObjectMap.GetNextAssoc(Pos, key, Obj);
if(GetId(key) < 1)
continue;
id.Format("%.0f", GetId(key));
name = GetName(key);
for(int i = 0; i < m_List.GetItemCount(); i++){
if(key == (long)m_List.GetItemData(i)){
m_List.SetItemText(i, 0, id);
m_List.SetItemText(i, 1, name);
bItemInList = true;
break;
}
}
if(!bItemInList){
m_List.InsertItem(0, id);
m_List.SetItemText(0, 1, name);
m_List.SetItemData(0, (DWORD) key);
}
}
Any assistance is greatly appreciated,
John
|
|
|
|
|
Hi, i want to display a .jpg file in my SDI application. can anybody tell me how to do that? Just i could display .bmp files. Thank you in advance
|
|
|
|
|
Have a look at paintlib...It was very helpful when I was developing a PICT file decoder
http://www.paintlib.de/paintlib/
Gary Kirkham
A working Program is one that has only unobserved bugs
I thought I wanted a career, turns out I just wanted paychecks
|
|
|
|
|
|
|
Since I am new to programming I am learning about my big mistakes gradually. My recent paranoia is memory leaks. When I declare local variables in Dialog Procedures or even WndProc (that go before WM_INITDIALOG and WM_CREATE) do they need to all be static so they don't get declared again. I don't quite understand how these functions work / get called. For example a dialog procedure gets called many times but does it end between those different calls or does the function get stuck in the message loop until the user terminates the dialog? Either am I be safe by using HWND hwnd, or int iNumber or do I specifically need to declare them as static? I learned Win32 from Petzol's book and I noticed he doesn't declare everything as static and I am quite confused as to which variables should be static and which not. Anyone have any advice for me?
|
|
|
|
|
( assuming it's in plain C )
variable declared on the stack (internally inside a function )( not thrue new/malloc ) will be freed when the function ends ( goes out of scope ).
if you need to have a variable that's shared between functions, you need to create a static variable in the implementation, if it's needed somewhere else, you need to put it in a header file.
Max.
|
|
|
|
|
georgiek50 wrote:
When I declare local variables in Dialog Procedures or even WndProc (that go before WM_INITDIALOG and WM_CREATE) do they need to all be static so they don't get declared again.
Only declare variables as static if you need to preserve their values between function calls. If the value is used temporarily inside the function, then just leave them as local (auto) variables.
georgiek50 wrote:
I don't quite understand how these functions work / get called. For example a dialog procedure gets called many times but does it end between those different calls or does the function get stuck in the message loop until the user terminates the dialog?
It gets called many times, or more accurately, every time a message is sent to your dialog box. It behaves just like any regular function call, the difference is that it's Windows that calls it for you.
georgiek50 wrote:
Either am I be safe by using HWND hwnd, or int iNumber or do I specifically need to declare them as static? I learned Win32 from Petzol's book and I noticed he doesn't declare everything as static and I am quite confused as to which variables should be static and which not. Anyone have any advice for me?
Again, just think of static variables as variables that are defined only once and then stay around forever, until the program ends. Compared to regular (local) variable, they offer no performance benefit. They actually cause your program to consume more memory since they don't go away until the program ends. Local variables are only loaded into memory when they're needed, such as when the function is called, and then their memory is automatically reclaimed.
Note that neither of these types of variables cause memory leaks. Those are caused by memory that's repeatedly allocated on the heap (with malloc), and never freed. This causes the program to eventually run out of space on the heap and crash.
Regards,
Alvaro
Well done is better than well said. -- Benjamin Franklin
(I actually prefer medium-well.)
|
|
|
|
|
Thanks guys, I think I got it...use static only when you must, the rest of the time just you plain old variables...
|
|
|
|
|
Dear All,
Good Day...
I built a PropertyPage withen a propertySheet and I need to add the Scrolling Capability to the PropertPage I added the style for adding the scroll to the dialog but when I run the Program the Scroll bars are not Shown how can i solve this problem.
Thank you very much all for your help .
Best Regards,
Mohammad Zakarni
|
|
|
|
|
Hi,
Your question is not clear. Explain more.
Abbas Riazi
|
|
|
|
|
Hi,
Am trying to add the Scroll Bars to a PropertPage dialog.
i Added the Scrolling from the styles of the dialog, when i test the dialog the Scroll Bars appears but when i run the PropertyPage ofcourse its liked to a PropertySheet the ScrollBars doesnt appear. this is the problem.
thank you very much for your help.
|
|
|
|
|
It seems like that one of my programs disables Drag&Drop after running some time on a Win2000 machine, i've seen it also on one Win98 machine, but its running without this problem on 100's of other installations ?
This happens if a user is working for some time with the program, he's doing nothing special, but than "double click" and Drag&Drop on the desktop isnt working anymore. If you stop the program in this situation you can not restart this programm, but you get the following windwos message "Windows Explorer - Unable to run this command"
Only a windows-restart solves the problem
|
|
|
|
|
At the moment problem occurs
1. Start Task Manager
2. View->SelectColumns. Select "USER Objects", "Handle Count",
"Thread count", "GDI Object"
3. Note the numbers for each of the columns above
Repeat the test, see if you reach a "limit" on any of them. Limits are not documented in MSDN, but I know for sure "USER Objects" can not be more than 10000. I suspect that other columns have some kind of limit per process as well. Watch memory usage as well.
|
|
|
|
|
thanks, i've already done that, all this values remain
more or less the same. 150 handles, 150 user objects, 6 threads, 300 gdi.
memory is growing a little bit, but not as much that this could be the
problem.
the other problem is that i cannot reproduce this problem on one of my
machines, but some of my costumers can do that. ok i can ask them to send
me there resources if this problem occurs.
any other ideas, dll's, i've static linked the mfc libs.
|
|
|
|
|
Can somebody tell me how to insert a CView in another CView or many CView in another one CView?
And how to switch from a CView to another?
Best regards,
Margaria Ivano
|
|
|
|
|
CSplitterWnd might be what you are looking for, see MSDN for sample code.
|
|
|
|
|
I know, thanks.
I have an SDI application. My application use the CSplitterWnd. I'm a beginner in C++ programming and I have no experience, but these Views aren't on a CView, altought on a CFrameWnd.
Sorry for my English.
Best regards
Margaria Ivano
|
|
|
|
|
Hi all,
It looks like a simple question, but I can't find a clean answer.
How is it possible to get in the cleanest way as possible a pointer to the active document (as it is a SDI, only one!) from everywhere, especially from the class associated to a dialog (CDialog).
Thank you,
loic
|
|
|
|
|
Uhm... would this be of any help?
CYourApp* theApp;
theApp = (CYourApp*)AfxGetApp();
CYourView* pView = (CYourView*) ((CFrameWnd*) theApp->m_pMainWnd)->GetActiveView();
CYourDoc* pDoc = pView->GetDocument();
First get a pointer to the application, then with that a pointer to the active view, and through the view pointer to the document.
Or did you say the cleanest possible way?
------------------------------------------
Experience is the name every one gives to their mistakes.
-- Oscar Wilde
Experience is one thing you can't get for nothing.
-- Oscar Wilde
|
|
|
|
|
In fact, if you take your code and put it in a new app, this is not fun...
I keep this reciep for next time, but here I found the way to do that. I just store a pointer to the document in a member var of my dialog class at creation time in CMainFrame or whatever, so I can directly access it after.
Thank you for your answer, it gives me also the links from theApp to pDoc...
loic
|
|
|
|
|
I am writing an AddIn for Visual Studio ver 6.0 running on Windows 98.
Part of my AddIn needs to search through files. However it is only able to search through the current working directory. I need it to look under all the other directories. I know one can set the search directories for include files under the Tools.. Options.. settings in the IDE.
I have tried using _searchenv(filename, "INCLUDE", pathbuffer) but this seems to only work for the current working directory.
Has anybody got any ideas or answers.
|
|
|
|
|
There's also
Project Settings -> C/C++ (tab) -> Preprocessor (Category) -> Additional includes directories:
Maybe you could build your own environment variable with SetEnvironmentVariable() called MYINCLUDES by collecting the directory settings from Tools, Project Settings, and the current directory and then use
_searchenv(filename, "MYINCLUDES", pathbuffer)
Todd Smith
|
|
|
|
|
The problem is that this is to be used in an AddIn that anybody can use so I can't hardcode my directories in.
|
|
|
|