|
i got it to work, thank you!
|
|
|
|
|
After hours of searching I finally found a solution being described by "DerMeister" in a post in the following forum (scroll down to post from 5/31/2003):
http://www.gamedev.net/community/forums/topic.asp?topic_id=159921
To quote him (1st example would be "best" in STL but 2nd example does work with Visual C++ 6.0):
[QUOTE]
At last!!! I found the way around it... I suggest anyone using VC 6 to read this. First I found that the "right" way to work with sorting STL lists is not supported by MSVC6.
With the right way I mean for example:
using namespace std;
struct compareByRS
{
bool operator()(const C3DObject* obj1, const C3DObject* obj2)const
{ return (obj1->rs) < (obj2->rs);}
};
list<c3dobject*> ObjsList;
//then I insert a few pointers to the list with random values in //the rs member (an int)
lst.sort(compareByRS()); //this would sort by rs
but, for the MS guys something should be done their way:
template<>
bool std::greater<c3dobject*>::operator()(C3DObject* const& p1, C3DObject* const& p2) const
{
return p1->rs < p2->rs;
}
list<c3dobject*> ObjsList
//I fill the list the same way
ObjsList.sort(greater<c3dobject*>());
//and use this horrible way to sort it... that's the MS way...
Anyway changing < to > sets the way to sort the list... I hope this is the only exception to work with STL under MSVC (which I doubt)...
Thanks to all who helped...
No matter where you go... &this
[/QUOTE]
gosh, you don't know how happy I am now ))
Bye,
T.T.H.
|
|
|
|
|
Currently writing a memory management system and I decided it'd be the logical thing to use stl maps to store various data. I'm very new to stl so I don't really understand the ins and outs of it yet, so I'm stuck on a problem which *should* be easy, but I'm doing something wrong.
I'm basically keeping a map of maps, with a unique string as the key to each of the maps. Here's one of my insert functions:
bool CHeapStore::_insert (heapHeader_t *header) {
map<int, heapHeader_t *> tmpMap;
pair< map<string, map<int, heapHeader_t *> >::iterator, bool> p;
tmpMap.insert(pair<int, heapHeader_t *>(header->id, header));
p = s_heaps.insert(pair<string, map<int, heapHeader_t *> >(header->name, tmpMap));
s_mmStashing = false;
return p.second == true ? true : false;
}
The program crashes on the s_heaps.insert() and returns the debugger to this in xtree:
_Pairib insert(const value_type& _Val)
{ // try to insert node with value _Val
_Nodeptr _Trynode = _Root(); // crashes here
What am I doing wrong? I've also tried other insertion methods, but this is the most direct one. The s_heap is an empty map when it crashes, it's the first call to the insert function.
Thank you so much for any help. btw, i'm using the default stl library that comes with MSVC .NET 2003.
-j
|
|
|
|
|
If you are using a map of maps and don't care about existence before inserting (you are willing to overwrite values if the keys match) then try the following:
declaration: map < string , map < int , heapHeader_t* > > storage.
To insert, just use the subscripts for access. If the items does not exist in the map, the map will automatically insert the item using the keys from the
subscripts.
storage[string][int] = headHeader_t* item;
But removing items from the map is different question.
Hopefully this is helpful.
Glenn
|
|
|
|
|
I converted your code into a small test program,
#include <map>
#include <string>
struct heapHeader
{
std::string name_ ;
int id_ ;
void * p_ ;
} ;
struct heap
{
std::map<std::string, std::map<int, heapHeader *> > s_heaps ;
bool insert ( heapHeader *header)
{
std::map<int, heapHeader *> tmpMap;
std::pair< std::map<std::string, std::map<int, heapHeader *> >::iterator, bool> p;
tmpMap.insert(std::pair<int, heapHeader *>(header->id_, header));
p = s_heaps.insert(std::pair<std::string, std::map<int, heapHeader *> >(header->name_, tmpMap));
return p.second ;
}
} ;
int main( )
{
heap h ;
heapHeader * ph = new heapHeader ;
ph->id_ = 0 ;
h.insert ( ph ) ;
return 0;
}
and it compiles and runs as expected. So I don't know what your problem is.
However I think your code is wrong. In the first place I wouldn't use a map where the key is embedded in the type, a set would be more efficient, you can create specific predicates to allow the object to be sorted according to its id or name. Secondly what if you insert a subsequent heapHeader with the same name? I assume this is legal? This way your maps of id-heapheader would have more than one member.
Anyway I would consider rewriting 'insert' along these lines,
void insert ( heapHeader *header)
{
std::pair< std::map<std::string, std::map<int, heapHeader *> >::iterator, bool> ;
p = s_heaps.insert(std::make_pair<std::string, std::map<int, heapHeader *> >(header->name_, std::map<int, heapHeader *> ()));
(*p.first).second.insert ( std::make_pair ( header->id_, header )) ;
}
Although perhaps the syntax could be tidied. The point is that std::map::insert never fails (other than through memory exhaution, in which case it throws an exception), it either inserts a new entry and returns 'true' in the second part of the pair, or returns false. In either case the first part of the return is an iterator to the appropriate entry.
Hope that made some sense.
Paul
|
|
|
|
|
Hi I am trying to extract image data from a binary file. I am new to
java and I am using eclipse in windows 2000.
there are a total of 9 images in the file out of which i am extracting
8.the images are littleendian.
The program always displays the last image. if i change
NUMOFIMAGES to 2 then it displays img[2] and if it is 7 displays
img[7] for all the images; Any ideas on this?
<br />
import java.io.*;<br />
import javax.swing.*;<br />
import java.awt.*;<br />
import java.awt.event.*;<br />
import java.awt.image.*;<br />
<br />
public class scanner3d extends JPanel {<br />
static Image img[] = new Image[10];<br />
<br />
public static void main(String[] args) throws IOException {<br />
scanner3d scner = new scanner3d();<br />
int WIDTH = 150;<br />
int HEIGHT = 200;<br />
int NUMOFIMAGES = 9;<br />
<br />
<br />
try {<br />
File file = new File("c:\\java\\15");<br />
FileInputStream fileInput = new FileInputStream(file);<br />
LEDataInputStream ledatainputstream =<br />
new LEDataInputStream(fileInput);<br />
float data[][][] = new float[NUMOFIMAGES][HEIGHT][WIDTH];<br />
float max = 0;<br />
for (int m = 0; m < NUMOFIMAGES; m++) {<br />
for (int k = 0; k < HEIGHT; k++) {<br />
for (int j = 0; j < WIDTH; j++) {<br />
float in = ledatainputstream.readFloat();<br />
if (in < 0)<br />
in = 0;<br />
if (in > max)<br />
max = in;<br />
data[m][k][j] = in; <br />
}<br />
}<br />
}<br />
int OneDimImage[] = new int[WIDTH * HEIGHT];<br />
<br />
for (int m = 0; m < NUMOFIMAGES; m++) {<br />
for (int k = 0; k < HEIGHT; k++) {<br />
for (int j = 0; j < WIDTH; j++) {<br />
int temp = (int) (data[m][k][j] / max * 255);<br />
int col = (255 << 24) | (temp << 16) | 0;<br />
OneDimImage[k * WIDTH + j] = col;<br />
}<br />
}<br />
img[m] =<br />
java.awt.Toolkit.getDefaultToolkit().createImage(<br />
new MemoryImageSource(<br />
WIDTH,<br />
HEIGHT,<br />
OneDimImage,<br />
0,<br />
WIDTH));<br />
<br />
<br />
}<br />
<br />
JFrame f = new JFrame();<br />
f.addWindowListener(new WindowAdapter() {<br />
public void windowClosing(WindowEvent e) {<br />
System.exit(0);<br />
}<br />
});<br />
f.getContentPane().add(scner);<br />
f.show();<br />
} catch (Exception r) {<br />
System.out.println(r);<br />
System.exit(0);<br />
}<br />
}<br />
public void paint(Graphics g) {<br />
super.paint(g);<br />
Dimension d = getSize();<br />
Insets i = getInsets();<br />
g.drawImage(img[0], 13, 15, 245, 190, this);<br />
g.drawImage(img[1], 263, 15, 245, 190, this);<br />
g.drawImage(img[2], 513, 15, 245, 190, this);<br />
g.drawImage(img[3], 763, 15, 245, 190, this);<br />
g.drawImage(img[4], 13, 211, 245, 190, this);<br />
g.drawImage(img[5], 263, 211, 245, 190, this);<br />
g.drawImage(img[6], 513, 211, 245, 190, this);<br />
g.drawImage(img[7], 763, 211, 245, 190, this);<br />
}<br />
}
Have Fun!!!
|
|
|
|
|
I'm using CSMTPConnection (ATL) in a send-mail program.
The mail server at the other end requires authentication. How do I get authentication using the CSMTPConnection class? Or do I have to use some other class?
|
|
|
|
|
You can't do it directly with CSMTPConnection . I suggest looking at "CDO for Windows 2000" (CDOSYS).
You could write the necessary extra code for CSMTPConnection ; the specifications are in RFC 2821[^] for SMTP itself, and RFC 2554[^] for the AUTH extension.
Stability. What an interesting concept. -- Chris Maunder
|
|
|
|
|
Hi respected ATL/WTL/STL people,
I need your heeeeeeeelp at once.
1. Tell me, or send me a good wtl tutorial, especially if it contains a comparison between usage of MFC and WTL.
or
2. If this look shorter and easier for u, first listen to this and then send me needed answers
I need to convert a program from MFC to WTL.
2.1.
How should I write this MFC code:
SetFont(GetStockFont(DEFAULT_GUI_FONT));
in WTL ?
It always tells me:
error C3861: 'GetStockFont': identifier not found, even with argument-dependent lookup
2.2.
What about this? :
CWnd* pWndOwner = GetOwner();
How should THIS ^ MFC line be written in WTL ?
2.3.
What does this means and what should I do if it writes to me:
error C3861: 'ASSERT': identifier not found, even with argument-dependent lookup
That's it
Would you be so kind to help me out with this?
Please send me the answer for me first and/or my second question at my e-mail: vuchko_@hotmail.com
Thank you very much for your help and for your time
Greatfull
Ajnstajn
|
|
|
|
|
Ajnstajn wrote:
1. Tell me, or send me a good wtl tutorial
Check out Michael Dunn's excelent series of "WTL for MFC Programmers" articles http://codeproject.com/wtl/wtl4mfc1.asp[^]
Ajnstajn wrote:
GetStockFont(DEFAULT_GUI_FONT));
You could try AtlGetStockFont(DEFAULT_GUI_FONT); If you look at it's source in atlmisc.h, you see that it's just a wrapper for ::GetStockObject()
Ajnstajn wrote:
2.2.
What about this? :
CWnd* pWndOwner = GetOwner();
How should THIS ^ MFC line be written in WTL ?
Well looking at the MFC source (it's always a good thing to install the MFC source when installing devstudio - you'll never know what you'll learn) CWnd::GetOwner looks like this
_AFXWIN_INLINE CWnd* CWnd::GetOwner() const
{ return m_hWndOwner != NULL ? CWnd::FromHandle(m_hWndOwner) : GetParent(); }
Depending on your situation, you could probably replace it with someing like
CWindow wndOwner = GetParent() . Presuming that you are in a CWindow object
Ajnstajn wrote:
'ASSERT': identifier not found
Use ATLASSERT
But seriously, check out Michael Dunn's articles, there all found in the WTL section here on CodeProject http://codeproject.com/wtl/index.asp#Beginners[^] You'll learn a lot.
[ Jason De Arte | Toy Maker | 1001010.com ]
|
|
|
|
|
|
with API use CreateFile , with traditional C++ use std::fstream
-Derick
|
|
|
|
|
Hai all,
I have a basic doubt when to use the Composite Design Pattern and When to use the Builder Design Pattern.
Do anyone explain me its difference with a scenario.
With Thanks,
Arun Chakaravarthy
|
|
|
|
|
You are referring to interface based design and template based design, correct?
COM is based on interface based design (composite) as an object and its type is only exist at runtime.
Template based design (builder) is known at compile-time.
Kuphryn
|
|
|
|
|
LPDRAWITEMSTRUCT lpdis;
In an Ownerdrawn menu handler WindowFromDC(lpdis->hDC) always return zero?
Any clues?
Thanks,
Derick.
|
|
|
|
|
And it always will.
HMENU's are the resource of a window - and never a true user accessable window themselves. It has something to do with the way that windows internally deals with menus - somehow that bit of geek trivia is lost to me & forgotten.
But I wouldn't wory about it, if you're doing an owner draw menu - all you need is the HDC anyways. If you need dimensions of the full menu for a side bar or something, I'd check out the multiple ownerdraw menu samples here on codeproject.
[ Jason De Arte | Toy Maker | 1001010.com ]
|
|
|
|
|
But I think I found the problem. It has something to do with mwnu animation. for animation purpouse, widows supplies another dc. This is what i think happens with a context menu.
-Derick
|
|
|
|
|
please help me .i wonder if the WTL is only used for the VC?
|
|
|
|
|
I 'am (beginner) in program ATL 7.0. I have made a ActiveX-control (with DirectX drawing a cruve,ATLserver, DLL) DirectX drawn also its own background. The control will be created with "CAxWindow"->CreateControl in the client window.
The problem is that the control first draw the background color and then DirectX draw also secondly its own background and the curve. I have tryed with WM_ereaseBkgnd (in ATL DLL) to prevent the first drawing background, but the routine will not be called.
Also the WM_ereaseBKgnd on the client side will not be called.
I don't know how prevent background drawing?
Theon
|
|
|
|
|
I wrote an Active X control using only ATL (no MFC), for use on a web page. When the control ends, it needs to go to another web page within the SAME IE browser window.
I am currently using:
ShellExecute(NULL,"open",NewPage,NULL,NULL,SW_SHOW)
to do this.
The problem is that this opens the new web page (whose URL is NewPage) in the default Browser, which isn't always always IE (it might be Netscape for example). It also opens a new IE window if the user has unselected "Reuse windows for launching shortcuts" in their IE Internet options. The most common problem, however, is that it opens a new "tab" in "Slimbrowser" and other "tab" based browsers.
The only solution seems to be to get a "IServiceProvider" pointer to the current browser window, then I can do a "IServiceProvider::QueryService" to get a "IWebBrowser2" pointer, and then use "IWebBrowser2::Navigate" to go to the new URL in the same window. This technique is described here: http://msdn.microsoft.com/msdnmag/issues/01/06/c/
However, I can't for the life of me figure out how to get the "IServiceProvider" pointer. In the above mentioned article, they said they got the pointer from the "Active Accessibility SDK", but not how. Also, I would prefer not to have to use this SDK.
I'm sure there is an easier way to do this. Remember that I can't use MFC!
Thanks in advance for any help you can give me!
|
|
|
|
|
You're on the right track. But missing one detail - IOleObject::GetClientSite
Here's a code snip that I used in a recent ATL based ActiveX control to get the IHTMLDocument2 interface of the parent IE WebBrowser. Sure it goes a little farther than what you want by getting the document (one extra call), but it demonstrates the concept.
inline HRESULT GetIEDocument(IOleObject* pObject, IHTMLDocument2 ** ppDocument2 )
{
CComPtr<IOleClientSite> spClientSite;
CComPtr<IServiceProvider> spSrvProv;
CComPtr<IWebBrowser2> spWebBrowser;
CComPtr<IHTMLDocument2> spHTMLDoc2;
if( !ppDocument2 || !pObject )
{
ATLASSERT(!"Bad pointer param");
return E_POINTER;
}
HRESULT hr = pObject->GetClientSite((IOleClientSite **)&spClientSite);
if( FAILED(hr) )
return hr;
hr = spClientSite->QueryInterface(IID_IServiceProvider, (void **)&spSrvProv);
if( FAILED(hr) )
return hr;
hr = spSrvProv->QueryService(SID_SWebBrowserApp, IID_IWebBrowser2, (void **)&spWebBrowser);
if( FAILED(hr) )
return hr;
hr = spWebBrowser->get_Document((LPDISPATCH*)&spHTMLDoc2);
if( FAILED(hr) )
return hr;
(*ppDocument2) = spHTMLDoc2;
(*ppDocument2)->AddRef();
return S_OK;
}
BTW, To the best of my knowlege ActiveX controls don't work in Nutscrape. Did you find a way for them to work?
[ Jason De Arte | Toy Maker | 1001010.com ]
|
|
|
|
|
Thanks Jason!
I only had to make a few changes to get your code working in my app.
I didn't need to pass the "IOleObject* pObject" object, since this code was in the same class as the main ATL ActiveX control. Aside from that, I just had to add the template definitions for the ATL classes used (IOleClientSite,IServiceProvider,IWebBrowser2). Also, "m_sLandingPage" is a global char* to the URL to navigate to. I think this code should work in almost any ATL ActiveX control.
And no, unfortunately, we weren't able to figure out a way to get ActiveX controls to work in Netscape, after much effort. The conclusion we came to was that it would require so much of Java wrapper that it was impractical.
<br />
bool Ccompctrl::LaunchURL()<br />
{<br />
CComPtr<IOleClientSite> spClientSite;<br />
CComPtr<IServiceProvider> spSrvProv;<br />
CComPtr<IWebBrowser2> spWebBrowser;<br />
<br />
HRESULT hr = GetClientSite((IOleClientSite **)&spClientSite);<br />
if( FAILED(hr) )<br />
return false;<br />
<br />
hr = spClientSite->QueryInterface(IID_IServiceProvider, (void **)&spSrvProv);<br />
if( FAILED(hr) )<br />
return false;<br />
<br />
hr = spSrvProv->QueryService(SID_SWebBrowserApp, IID_IWebBrowser2, (void **)&spWebBrowser);<br />
if( FAILED(hr) )<br />
return false;<br />
<br />
CComVariant vNull;<br />
CComBSTR bsLandingPage = m_sLandingPage;<br />
hr = spWebBrowser->Navigate(bsLandingPage, &vNull, &vNull, &vNull, &vNull);<br />
if( FAILED(hr) )<br />
return false;<br />
<br />
return true;<br />
}<br />
|
|
|
|
|
I guess the same thing happened to you that just happened to me. The the template definitions, which were inclosed in "<>" were lost because it was considered HTML.
Here are the correct first three lines :
CComPtr<IOleClientSite> spClientSite;
CComPtr<IServiceProvider> spSrvProv;
CComPtr<IWebBrowser2> spWebBrowser;
|
|
|
|
|
d'oh!
Updated.
[ Jason De Arte | Toy Maker | 1001010.com ]
|
|
|
|
|
How can i use this for MSFLEXGRID control?
I use this, but it has runtime error!
void CMyViewEx::OnInitialUpdate()
{
AddResizedControl(IDC_MSFLEXGRID1, TOP_LEFT, BOTTOM_RIGHT);
CResizableFormView::OnInitialUpdate();
AnchorControls(); //Error here
}
|
|
|
|
|