|
Yes, this is correct.
Joaquín M López Muñoz
Telefónica, Investigación y Desarrollo
|
|
|
|
|
Joaquin to the rescue again
Thanks!
|
|
|
|
|
it may be correct. but it is an absolutely horrible thing to do, IMO.
To explain Donald Knuth's relevance to computing is like explaining Paul's relevance to the Catholic Church. He isn't God, he isn't the Son of God, but he was sent by God to explain God to the masses. /. #3848917
|
|
|
|
|
how so? What would be a better technique???
|
|
|
|
|
it's true that std::vector is actually spec'd in such a way that running memset on it is perfectly legal, i don't argue that. and, i'm sure it was spec'd that way to specifically allow it to be used as a solid chunk of memory.
but to me, using memset is an abuse of the idea of a vector as an abstract container class. plus, there is an accepable STL/OOP friendly way to do what you're describing:
this will create a vector of 20 bool's all set to false.
std::vector<bool> m(20, false);
-c
To explain Donald Knuth's relevance to computing is like explaining Paul's relevance to the Catholic Church. He isn't God, he isn't the Son of God, but he was sent by God to explain God to the masses. /. #3848917
|
|
|
|
|
I wasn't asking about using memset, I was asking what to use to _replace_ memset on a C array.
I'm assuming using m_abMatched.assign( m_abMatched.size(), false ) would be a little bit quicker (and clearer) than m_abMatched = std::vector<bool>( m_abMatched.size(), false), right?
Thanks,
Pete
|
|
|
|
|
ah
yeah, that was my evil twin, trying to toss some confusion into other people's lives.
i'll send him away
-c
To explain Donald Knuth's relevance to computing is like explaining Paul's relevance to the Catholic Church. He isn't God, he isn't the Son of God, but he was sent by God to explain God to the masses. /. #3848917
|
|
|
|
|
Damn those evil twins. Mine causes no end of trouble
Anyways, std::fill() is more understandable than std::vector::assign() in this case
Pete
|
|
|
|
|
This is a more understandable form:
std::fill(v.begin(),v.end(),false); Nevertheless, the latter is less advisable in some pedantic subtle way, namely that std::vector::assign could be partially specialized to perform faster on some primitive types (not that VC++ does it, anyway.)
Joaquín M López Muñoz
Telefónica, Investigación y Desarrollo
|
|
|
|
|
more understandable, and safer...
it's pretty easy to see memset flying off the end of the vector and writing into the stack somewhere.
-c
To explain Donald Knuth's relevance to computing is like explaining Paul's relevance to the Catholic Church. He isn't God, he isn't the Son of God, but he was sent by God to explain God to the masses. /. #3848917
|
|
|
|
|
?? Maybe you have misread the guy's question. He was asking about the suitability of
m_abMatched::assign(m_abMatched.size(), false) as a replacement of memset . And this (assign ) is perfectly safe.
Joaquín M López Muñoz
Telefónica, Investigación y Desarrollo
|
|
|
|
|
Hello,
I have a few questions I'd like to ask and see if anybody knows anything about this.
First of all, my MDI project starts with an open window. This is great. I want this window to be uncloseable. How do I disable the X (close) button? I want this window never to close.
Second, I get live images in one window, but I'd like to snap and have the image appear in a new window. Right now, the snap appears in the same type of window, so the same type of options apply to it (chaning the contrast or brightness or any example you can think of). I want the snap window to have a different set of avaible drop down options (i.e. I'd like to make some grayed out or unusable).
So I am thinking using a new document template would be the way to go here.
What do you guys think about that? And if you could answer how to gray out the options and how to make sure my first window never closes, I'd sure like to know how to do that. Pleas let me know if I am on the right track with using a new Document Template.
Thanks guys,
NickOne
You guys rock!
p.s. How can I tell if there is a memory leak? Sometimes my program, when I try to close the window crashes and becomes unresponsive. This is a feature I sure don't like!!! Any ideas?
Thanks again!!
|
|
|
|
|
NickWhoForgotHisPasswordToLogIn wrote:
NickWhoForgotHisPasswordToLogIn
Lookup your password here
Jon Sagara
"Me fail English? That's unpossible."
"Hello Supernintendo Chalmers. I'm lernding."
--- Ralph Wiggum ---
|
|
|
|
|
In response to your p.s., memory leaks do not usually manifest the way you describe. In debug mode, MFC apps come with a built-in leak detector: upon exiting, the leaks detected are reported to the debug output window of Visual Studio.
Joaquín M López Muñoz
Telefónica, Investigación y Desarrollo
|
|
|
|
|
Hi,
In my application I need to create an empty window just to receive messages and treat them. I wrote the following code:
HINSTANCE hApi = (HINSTANCE) GetModuleHandle(NULL);
if (! hApi) ...// manage error
CHAR * WindowClassName = "MyWindowClass";
WNDCLASS WindowClassInfo;
if (! GetClassInfo(hApi, WindowClassName, &WindowClassInfo))
{
WindowClassInfo.hCursor = NULL;
WindowClassInfo.hIcon = NULL;
WindowClassInfo.lpszMenuName = NULL;
WindowClassInfo.lpszClassName = WindowClassName;
WindowClassInfo.hbrBackground = NULL;
WindowClassInfo.hInstance = hApi;
WindowClassInfo.style = CS_OWNDC | CS_VREDRAW | S_HREDRAW;
WindowClassInfo.lpfnWndProc = (WNDPROC) MyProc;
WindowClassInfo.cbClsExtra = 0;
WindowClassInfo.cbWndExtra = 0;
if (! RegisterClass(&WindowClassInfo)) ...//manage error
}
HWND hWnd = CreateWindow(WindowClassName,
"MyWindow",
WS_OVERLAPPEDWINDOW,
0,
0,
CW_USEDEFAULT,
CW_USEDEFAULT,
NULL,
NULL,
hApi,
NULL);
if (! hWnd) ...//manage error
But, unfortunately, CreateWindow return NULL and GetLastError return 0 !!!
Did anybody could help me ?
Thanks in advance.
Robin.
|
|
|
|
|
Everything seems OK. The only possible problem I can think of is that MyProc is not properly declared as a WINDPROC should. Could you show us this function?
Joaquín M López Muñoz
Telefónica, Investigación y Desarrollo
|
|
|
|
|
MyProc is declared in a header as following:
LRESULT CALLBACK fidLinkEventProc(HWND _hWnd, UINT _iMsg, WPARAM _wParam, LPARAM _lParam);
and MyProc is defined in a .c file:
LRESULT CALLBACK MyProc(HWND _hWnd, UINT _iMsg, WPARAM _wParam, LPARAM _lParam)
{
switch (_iMsg)
{
...
}
return 0;
}
|
|
|
|
|
Try this, if it work, check your WindowProc function like Joaquim suggested:
LPCTSTR szWindowClassName = _T("MyWindowClass");
WNDCLASS WindowClassInfo;
if (!GetClassInfo(hApi,szWindowClassName, &WindowClassInfo))
{
WindowClassInfo.hCursor = NULL;
WindowClassInfo.hIcon = NULL;
WindowClassInfo.lpszMenuName = NULL;
WindowClassInfo.lpszClassName = szWindowClassName;
WindowClassInfo.hbrBackground = NULL;
WindowClassInfo.hInstance = hApi;
WindowClassInfo.style = CS_OWNDC | CS_VREDRAW | CS_HREDRAW;
WindowClassInfo.lpfnWndProc = (WNDPROC) ::DefWindowProc;
WindowClassInfo.cbClsExtra = 0;
WindowClassInfo.cbWndExtra = 0;
if (!RegisterClass(&WindowClassInfo))
{
TRACE( " ERROR \n");
}
}
HWND hWnd = CreateWindow(szWindowClassName,
"MyWindow",
WS_OVERLAPPEDWINDOW,
0,
0,
CW_USEDEFAULT,
CW_USEDEFAULT,
NULL,
NULL,
hApi,
NULL);
ASSERT( hWnd != NULL );
|
|
|
|
|
Thank for your help. I solved my problem: MyProc was always returning 0 whatever the message was, whereas it has to treat Windows messages such as "WM_CREATE", ... (traditional messages to create a window).
Now, I use "return DefWindowProc(_hWnd,_iMsg,_wParam,_lParam)" when I receive a Windows message different from my messages.
|
|
|
|
|
Hi! I'm new at Visual C++, and i was trying to use a CListBox with multicolumn features, but i cannot find a way to include the column's labels.
I guess this must be a easy task for most of you, but i'm really having dificulties in implementing this.
Can anyone help me? Please...
Thank you in advance
|
|
|
|
|
Do you mean CListBox or CListCtrl ? If the former, then all the columns of a single row are inserted at a time by calling AddString with a string where columns are separated by tab characters:
m_list.AddString("Column 1\tColumn 2\tColumn 3");
Joaquín M López Muñoz
Telefónica, Investigación y Desarrollo
|
|
|
|
|
Thank's Joaquín, i guess i'll use the CListCtrl once i need the headers to sort data, can you tell where to find some good examples how to use this object?
Thank you
|
|
|
|
|
Here at CP. For instance, Matt Weagle's article Using the List Control.
Joaquín M López Muñoz
Telefónica, Investigación y Desarrollo
|
|
|
|
|
Hi,
I am deriving my class from CFileDialog. My application should open files with extension ".crm" only. The default extension is being restricted to ".crm". If the user enters wrong file extension, then I have to clear the file name in the 'FileName' edit box.
I am overriding the virtual function OnFileNameOK. But this function is getting called during Save but not during Open.
How can I clear the text in the edit box?
Thanks
Sreenivas
|
|
|
|
|
Have a class that i derived from CWnd. I want to put a toolbar at the bottom of the window. Can somebody help me get started with this?
thanks
Scott
|
|
|
|
|