|
If I do call this, I got exception.
|
|
|
|
|
Where does the exception occur? ...check to make sure you're not deallocating the same batch of memory twice within the object. Typically the DestroyWindow call will do just that, destroy the window, but the resources don't get deallocated until you delete the object... and if you explicitly called new then odds are you explicitly have to call delete , otherwise you'll be leaking memory. Exceptions to this rule occur when the framework itself deallocates the memory, in this case usually you can find info on the framework's website (MFC=>MSDN).
|
|
|
|
|
Use view->DestroyWindow(); to destroy the visible Window (or View) associated with the instance of your CView derived class. Then once the window has been disposed of properly you can use delete , if appropriate, to dispose of your view object.
I must get a clever new signature for 2011.
|
|
|
|
|
Hi ,
I am having a std map object. I have added key and value in the following order.
mymap.insert (pair<int,int>(10,20)) ;
mymap.insert (pair<int,int>(5,20)) ;
mymap.insert (pair<int,int>(104,20)) ;
mymap.insert (pair<int,int>(1,20)) ;
But while extracting the data from map I am getting this data in a sorted order (sorted by Key order). How can I prevent this . I am passing the data from this map to a device which needs the data as is from my map. Please help
|
|
|
|
|
maps are always sorted. the tree structure that they use internally requires it.
if you want an unsorted container, use a vector (or a list).
|
|
|
|
|
If you want to maintain the order of insertion, then you could create a list alongside your map. Each insert will give you an iterator in return, which references the newly inserted element. Store this element in your list, and you're done. If you want to retrieve your elements in order of insertion, use the list. If you want it ordered by key, or just want to retrieve a single object with a key, use your map.
class MyMap {
std::map<int,int> m_map;
std::list<pair<int,int> > m_list;
public:
typedef std::list<pair<int,int> >::iterator insert_iterator;
typedef std::map<int,int>::iterator key_iterator;
void insert(int key, int value) {
m_list.push_back(m_map.insert(pair<int,int>(key, value)));
}
insert_iterator ibegin() { return m_list.begin(); }
insert_iterator iend() { return m_list.end(); }
key_iterator kbegin() { return m_map.begin(); }
key_iterator kend() { return m_map.end(); }
};
Note that you will have to dereference your insert_iterator twice: once to get the list element which is an iterator to the map, and a second time to get the actual element of the map:
MyMap mymap;
mymap.insert(5, 15);
mymap.insert(100, 20);
mymap.insert(34, 30);
for (MyMap::key_iterator kit = mymap.kbegin(); kit != mymap.kend(); ++kit)
std::cout << (*kit).second << std::endl;
for (MyMap::insert_iterator it = mymap.ibegin(); it != mymap.iend(); ++it)
std::cout << (*(*it)).second << std::endl;
Of course, this mechanism breaks down once you start erasing elements from your map - the moment you do this, the accompanying iterators stored in the list will be invalidated! You could of course search for these elements and remove them from the list, but that would be very inefficient and might negate the efficiency that you gained from using a map in the first place.
In that case you might be better off to just use a list without a map, and sequentially search for the key when you want to retrieve a particular element. Note that you can use the std::find() methods to search for particular elements, you just have to provide a comparator that specifically compares the key. If you have a compiler that supports C++0x you might even use an unnamed lambda to provide the comparator instead of having to define a function object class.
|
|
|
|
|
Hello Friends
I am using drawImage from GDIPLUS in OnPaint().And Mine image is getting flickered too much.How can i reduce it?
Thanks & Regards
Yogesh
|
|
|
|
|
You may use double buffering technique. Have a look at (one of) the following CodeProject articles:
http://www.codeproject.com/info/search.aspx?artkw=double+buffering&sbo=kw[^].
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong.
-- Iain Clarke
[My articles]
|
|
|
|
|
+1 for using the CP search instead of google!
Watched code never compiles.
|
|
|
|
|
Thanks.
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong.
-- Iain Clarke
[My articles]
|
|
|
|
|
in addition, handle WM_ERASEBACKGROUND message and simply return TRUE from there without calling base class's message handler. This will discard the flickering due to background painting. Remember, you have to paint the background from OnPaint (use double buffering )
modified on Thursday, March 24, 2011 9:13 AM
|
|
|
|
|
Hi
Also create a memory DC and select this image to this DC. And use this DC as the Source in API BitBlt, StretchBitBlt etc.
Hope this helps
Nitheesh George
http://www.simpletools.co.in
|
|
|
|
|
this method works very well for drawing at high rates
|
|
|
|
|
The first step (before investigating possible solutions, such as double buffering) is to figure out why the flicking is occuring. Can you provide any more details? When does it flicker? Does the image resize if the window size is altered? Are you using the CS_HREDRAW and CS_VREDRAW[^] class styles?
Steve
|
|
|
|
|
hi,Its Flickering whenever some update happen like if i zoom,scroll etc.
It looks like tht OnPaint is calling and that is makeing flickering bcoz onpaint m using drawimage().
Regards
Yogesh
|
|
|
|
|
I am trying to insert a variable in a SQL string but am not having any success in finding the proper sytax. I am coding in C++. Listed below is code section I am trying to figure out. This code is part of an ADO routine that adds a field in an Access Database.
char Value[40];
printf("Input A String");
scanf("%s",Value);
sSQLCommand = L"ALTER TABLE TableIn ADD @Value nvarchar(20)";
com->CommandText = sSQLCommand;
Unfortunately what gets added to the database as a field is @Value.
|
|
|
|
|
wchar_t sqlCommand[1024];
wsprintf(sqlCommand, L"ALTER TABLE TableIn ADD %s nvarchar(20)", Value);
|
|
|
|
|
Superman,
Excellent! You pointed me in the right direction. After some modifications, the following code works:
char sSQLCommand[100];
char TempField[50];
printf("Input Field");
scanf("%s",TempField);
sprintf_s(sSQLCommand,"ALTER TABLE TableIn ADD %s nvarchar(20)",TempField);
|
|
|
|
|
Next, read about SQL injection[^] to understand why code like that is dangerous.
|
|
|
|
|
You should avoid this coding style as it may lead to some serious problems. Google SQL Injection, you yourself will understand.
|
|
|
|
|
I need an existing linkable chat control for client/server communication, which is readonly and text-only.
When users say something, chat contents are added to the control.
Texts displayed on the control have multiple types of links, such as user-name, comments, advertisements and something else. If clicking on those links, related events or messages are submitted to the control's parent or itself, so that I can show further info by types of those links, i.e. show pop-up menu or show some windows.
Thanks
BTW: or any idea to develop the control easily?
|
|
|
|
|
|
Hi, dear all,
I am creating a MFC DLL utility program that will be used by client application through exported functions in DLL.
Now I have to problem about how to create a modeless dialog in MFC dll. I searched some examples about creating modeless dialog in MFC exe application. Usually they create a dialog pointer in View class and initialize it as:
m_pDlg = new CMymfc9Dialog(this);
But my program is MFC DLL, there is no CView class, how can I initialize the m_pDlg? what argument should I pass to it?
Thanks!
|
|
|
|
|
You can simply pass NULL to CDialog constructor as parent window. In this case, MFC searches a proper one. If it doesn't find any, dialog's parent window is set to the main application window.
You also don't have to use above constructor for modeless dialog boxes. You can use default constructor then you can specify parent window later by Create() function.
m_pDlg = new CMymfc9Dialog();
m_pDlg->Create(IDD_MYMFC9DIALOG, NULL);
m_pDlg->ShowWindow(SW_SHOW);
|
|
|
|
|
Thanks!
Now I use pMatTable = new CMatTable(this->m_pMainWnd); pass main window as parent window, it works now.
|
|
|
|