|
Not sure if this will help, however try supplying a return value to prevent the compiler from defaulting it to int. This behaviour was only supported in older compilers (I'm assuming you're using VC6)
template <typename T>
void perform(int iTotal)
{
vector<T> vec;
for(int i = 0; i < iTotal; i++)
{
vec.push_back(T());
}
} Make sure the constructor for T isn't doing anything it shouldn't - this won't be a problem if you're using double's however.
If you can keep you head when all about you
Are losing theirs and blaming it on you;
If you can dream - and not make dreams your master;
If you can think - and not make thoughts you aim;
Yours is the Earth and everything that's in it.
Rudyard Kipling
|
|
|
|
|
Hi
Thanks for the reply. I've tried supplying the void return value, but I still get the same error.
|
|
|
|
|
Do you have a complete compilable example to post?
Your function as it exists is obviously pointless, and even if it weren't is equivalent to calling resize on the vector , which seems rather more direct.
Paul
|
|
|
|
|
Hi
My intention was to analyze the performance of STL vector insertion, how long does it take to insert e.g. 10 million doubles, ints, strings, etc., hence the code.
|
|
|
|
|
I think your GPF is a consequence of the compiler rather than the code.
But I don't think you're going to learn anything interesting about vector per se from this type of test. The dominant factor will be allocation and reallocation. Any real usage where you know how big you want the vector would call reserve first. And if you want to get to very large arrays of ordinary types then reverting to new/delete and manual management of length is probably going to be notably more efficient.
Paul
|
|
|
|
|
Is it possible to handle the javascript resizeTo() and moveTo() events in a custom CWebBrowser2 control? I can not seem to catch this event. Any ideas?
|
|
|
|
|
Try this, but this is not CWebBrowser2 control. It is a custom view.
http://www.codeproject.com/dotnet/dhtmlview.asp
Sonork 100.41263:Anthony_Yio
|
|
|
|
|
Hey all.
I'm using CFile to access some files across a network share. It works great when the servers are all online, however if one of the servers goes offline, the CFile::Open will try to open the file across it for 30-60 seconds (which is too long for this app that I'm building).
I am wondering if there is a way to set a default open timeout .... so it will try for say, 5 seconds, and if it can't get it, it fails and returns false?
TIA!!
|
|
|
|
|
How about to use
_taccess(const char *path, int mode );
in io.h?
Sonork 100.41263:Anthony_Yio
|
|
|
|
|
Hi,
I assign a access key to a control, ex. &access.
But besides Alt-A and A, Ctrl-A ,Shift-A, and 1+A, ... all recive WM_COMMAND. Is this by default ? and how do I disable them?
|
|
|
|
|
(From MSDN)
The WM_COMMAND message is sent when the user selects a command item from a menu, when a control sends a notification message to its parent window, or when an accelerator keystroke is translated.
Accelerator keystrokes that select items from the window menu are translated into WM_SYSCOMMAND messages.
You can assign you own accelerator keystroke to other keys like Ctrl A to correspond to your needed menu?
Sonork 100.41263:Anthony_Yio
|
|
|
|
|
Thanks, but I need to disable ctrl- and shift- instead of enable them. All articles I searched about access key in MSDN, don't mention that ctrl- and shift- are access keys, so I doubt that ctrl- and shift- are by default.
|
|
|
|
|
Hello!
I've got this thread function and in the postmessage line i'd like to send a message to the main view of the program. (it's an MFC project).
<br />
DWORD WINAPI CHilos::ThreadProc(LPVOID objeto)<br />
{<br />
CHilos* thread=(CHilos*)objeto;<br />
while (thread->Alive)<br />
{<br />
while((thread->Alive)&&(thread->Active))<br />
{<br />
thread->Work();<br />
}<br />
}<br />
::PostMessage(HWND_BROADCAST, WM_ONFINISH, 0, 0);<br />
return true;<br />
}
The project is called hiloss, and in hilossView.cpp i declared in the message map:
ON_MESSAGE(WM_ONFINISH, OnThreadended)
and then in the same file there's the definition of the OnThreadended function.
The problem is with the postmessage is that the message never reaches the top window, actually when i debug the project, it never gets into the OnThreadended function.
Is HWND_BROADCAST ok? i think there's the problem. I want to send a message to the ChilossView class, which is the main window of the project, but i don't know how.
thanks!!
|
|
|
|
|
HWND_BROADCAST won't send the message to your view. It sends the message to all the top-level windows in the system. In MFC, this is the instance of your CMainFrame class. You'll either have to the send the message to your view directly, or handle the message in CMainFrame .
Hope this helps,
Ryan "Punctuality is only a virtue for those who aren't smart enough to think of good excuses for being late" John Nichol "Point Of Impact"
|
|
|
|
|
how could i send the message directly to the view?
thanks
|
|
|
|
|
When is OnThreadended been called? in WM_ONFINISH?
And the OnThreadended will call the ThreadProc which will post WM_ONFINISH?
Seems like an deadlock for me.
Sonork 100.41263:Anthony_Yio
|
|
|
|
|
Anthony_Yio wrote:
When is OnThreadended been called? in WM_ONFINISH?
yes.
Anthony_Yio wrote:
And the OnThreadended will call the ThreadProc which will post WM_ONFINISH?
no, OnThreadended does other things
thanks for answering!
|
|
|
|
|
Hey,
I am tring to teach my self C++ from a book. And it is not going as well as i planned. I am tring to make the first program in the book and I keep getting the same error. I am using Visual C++ 6 as my compiler. The Program is very simple (Not for me i guess haha):
// myfirst.cpp--displays a message
#include "stdafx.h" // a PREPROCESSOR directive // make definitions visible
int main() // function heading
{ // start of function body
cout << "Come up and C++ me some time."; // message
cout << "\n"; // start a new line
return 0; // terminate main()
} // end of function body
The Error I always get is:
myfirst.cpp
c:\Documents and Settings\Ben Quinn\My Documents\Visual Studio Projects\myfirst\myfirst.cpp(6) : error C2065: 'cout' : undeclared identifier
c:\Documents and Settings\Ben Quinn\My Documents\Visual Studio Projects\myfirst\myfirst.cpp(7) : error C3861: 'cout': identifier not found, even with argument-dependent lookup
I am using the 32bit App Option like the book said to use. there is one difference between mine and the book's code. Their's code says:
#include <iostream>
using namespace std;
But whenever I use that I get the Error:
Compiling...
myfirst.cpp
c:\Documents and Settings\Ben Quinn\My Documents\Visual Studio Projects\myfirst\myfirst.cpp(12) : fatal error C1010: unexpected end of file while looking for precompiled header directive
I hope some one can help me out. I really wana get past the first 3 pages.
Thx
- Hidden
|
|
|
|
|
what about at the top?
#include <iostream.h>
Teach Yourself C++ in 21 Days - Second Edition
is a good way to learn c++. It's free. look it up in google
|
|
|
|
|
|
Hi all!
I've been tring to put a bitmap background image on the main Dialog but nearest i can get is this:
CDC* pDC=GetDC();
CDC old; //New device context used as the source DC
//Creates a deice context compatible to pDC
old.CreateCompatibleDC(pDC);
CBitmap dlg_bmp;
CRect rect;
GetClientRect(&rect);
dlg_bmp.LoadBitmap(IDB_BITMAP3);
CBitmap* oldbmp= old.SelectObject(&dlg_bmp);
pDC->BitBlt(rect.left, rect.top, rect.Height(), rect.Width (),&old,0,0,SRCCOPY);
old.SelectObject(oldbmp);
dlg_bmp.DeleteObject(); //Deletes the bitmap
Invalidate();
when this runs the bitmap is loaded and it overrun the other controls hiding them
If some one help me i'd be very gratefull
AI_Warrior
|
|
|
|
|
You need to handle WM_ERASEBKGND and paint the bitmap in response to that message.
--Mike--
Personal stuff:: Ericahist | Homepage
Shareware stuff:: 1ClickPicGrabber | RightClick-Encrypt
CP stuff:: CP SearchBar v2.0.2 | C++ Forum FAQ
----
There is a saying in statistics that a million monkeys pounding on typewriters would eventually create a work of Shakespeare. Thanks to the Internet, we now know that this is not true.
|
|
|
|
|
try setting the background brush of the dialog box by usning the setclasslong method use GCL_HBRBACKGROUND as the index in the api.
|
|
|
|
|
Hi!
I have a problem with setting the character set in my ListBox (List). When I create a CFont object with a specific character set and I set that font in the Device Context recieved from the ListBox, then it is OK. I can write through that DC in the chosen charset. See Code :
CFont * font = new CFont;
CFont *oldFont;
CPaintDC dc( List );
font->CreateFont (28,0,0,0,700,0,0,0,
RUSSIAN_CHARSET, OUT_DEFAULT_PRECIS,
CLIP_DEFAULT_PRECIS, DEFAULT_QUALITY,
DEFAULT_PITCH|FF_DONTCARE, "Arial");
oldFont = dc.SelectObject( font);
dc.ExtTextOut(10,170,0,NULL,"some text",
strlen("some text"),NULL);
!!!!!!!!! BUT !!!!!!!!!
If I set that font right in my ListBox and want to have the text added with code :
<br />
List->SetFont( font, TRUE); <br />
List->AddString( "some other text" ); <br />
in the chosen charset, then it DOES NOT work !
However the added text has the other parameters of the chosen font ( Height and so on) but the charset is the original (standard) one
Does anyone know how to force the ListBox to accept the charset from the font also ? Or it might be a bug in my Visual Studio ?
PLEASE HELP!
|
|
|
|
|
I have been trying to have an Edit Box take the Tab key as a simple move off the control - just tab around all the controls with Tabstop set.
Currently the Tab acts as an end to data input (i.e. like a Return or Enter key pressed). I did start to Derive the Edit Box control, but got stuck, see code below!
<br />
#include "stdafx.h"<br />
#include "MyEdit.h"<br />
<br />
<br />
<br />
IMPLEMENT_DYNAMIC(CMyEdit, CEdit)<br />
CMyEdit::CMyEdit()<br />
{<br />
}<br />
<br />
CMyEdit::~CMyEdit()<br />
{<br />
}<br />
<br />
BEGIN_MESSAGE_MAP(CMyEdit, CEdit)<br />
ON_WM_GETDLGCODE() <br />
END_MESSAGE_MAP()<br />
<br />
<br />
<br />
UINT CMyEdit::OnGetDlgCode()<br />
{<br />
return DLGC_WANTTAB;<br />
}
Currently the Edit Box (MyEdit) only processes the TAB key, I want it to process all keys but with the Tab key just move on to the next tabstop.
Help!
grahamfff
|
|
|
|