If you use MFC, IMO the easiest method is to use a frame window for the main window and use
a modeless dialog as the client window (or you could even use a CFormView). MFC handles window
decorations like toolbars and status bars and does the layout of the client window - makes it real
easy to code.
I have an app which will have a lot of controls on it, and will probably make it a dialog based app for easy layout of these controls
For that kind of app, I prefer to use a SDI application where the view is a CFormView. The CFormView has an associated dialog resoruce - lay out your controls on that as you would for a dialog. The rest of the framework handles the menus and toolbars and such for you so you get a nice merging of dialog capabilities and "normal" window-based capabilities.
I'm still learning C and C++. I found this magical bit of code that will give the number of elements in an array without knowing it's type. Can anyone explain this in terms mere mortals can understand?
In WinNT.h, around lines 939:
//<br />// RtlpNumberOf is a function that takes a reference to an array of N Ts.<br />//<br />// typedef T array_of_T[N];<br />// typedef array_of_T &reference_to_array_of_T;<br />//<br />// RtlpNumberOf returns a pointer to an array of N chars.<br />// We could return a reference instead of a pointer but older compilers do not accept that.<br />//<br />// typedef char array_of_char[N];<br />// typedef array_of_char *pointer_to_array_of_char;<br />//<br />// sizeof(array_of_char) == N<br />// sizeof(*pointer_to_array_of_char) == N<br />//<br />// pointer_to_array_of_char RtlpNumberOf(reference_to_array_of_T);<br />//<br />// We never even call RtlpNumberOf, we just take the size of dereferencing its return type.<br />// We do not even implement RtlpNumberOf, we just decare it.<br />//<br />// Attempts to pass pointers instead of arrays to this macro result in compile time errors.<br />// That is the point.<br />//<br />extern"C++"// templates cannot be declared to have 'C' linkage<br />
template <typename t,="" size_t="" n=""><br />
char (*RtlpNumberOf( UNALIGNED T (&)[N] ))[N];<br />
#define RTL_NUMBER_OF_V2(A) (sizeof(*RtlpNumberOf(A)))</typename>
Can anyone explain this in terms mere mortals can understand?
i think the following is too descriptive for mere mortals.
Glenn Sandoval wrote:
I found this magical bit of code that will give the number of elements in an array without knowing it's type.
I can see three magics. 1 ) one taking advantage of sizeof(char) as 1, 2)taking advantage of const parameter in template declaration to deduce the size of array.
3) sizeof() operator only bothers type, it won't execute function
1) use of sizeof(char)
(*RtlpNumberOf(A)) effectively has the return type as the charater array type with the equal number of elements that of the Array passed, since sizeof (char) is 1, the sizeof (character array) will be the number of elements.
ie; if you pass <array of anytype>, then return type of RtlpNumberOf is char(*), so sizeof(* char(*)) = sizeof(char) = 128 * sizeof(char) = 128
char (*function()); function returning pointer to character array(as function cannot return array so pointer to array)
sizeof(*function()) = sizeof(*char(*)) = sizeof(char) = 10 * sizeof(char) = 10;
// note sizeof operator uses dereferenced return type. (*function())
2) use of const parameter in template
template <size_t N>
void func(char (&arr)[N]); // function taking reference to array.
here the constant parameter N is deduced to number of element of array.
so char cArray; func(cArray) will deduce N as128;
putting it togetter,
template <typename T, size_t N>
char (*func(T (& )[N]))[N]
func has return type char (*)[N] which sizeof() operator considers.
3) use of sizeof() operator won't execute function.
So definition of function is not needed. at the point of template instantiation, N is deduced to the number of element of array, function is not executed, returns the number of elements.
advantage of this over sizeof(array)/sizeof(array) is,
1) unnamed struct cannot be used.
2) pointer which may not be an array cannot be used.
i'm trying to code a small encryption application, which encrypts files with different algorithms. i'm using crypto++ lib for the encryption part, and qt for the gui part. now after struggling with the encryption for a while, i found an example via google that i'm using now to encrypt files. its like this:
While the encryption seems to work (i admit that i dont really know what i'm doing..), i was wondering if there is any way to monitor encryption progress. i want to implement a progress bar in the program, so you can see how far your 2gb file is encrypted already. my current idea is to watch the destination file with a QFileSystemWatcher, and set the current size of the destination file as progress. this would probably work, however the file size of the destination file stays 0 until the encryption is finished, even if the file is quite large.
is there any way to have crypto++ stream the encryption right to the hdd, so the file size grows?
if not, maybe someone has an idea of how to implement a progress-monitor function? in the application, the main thread runs the gui stuff, whereas the encryption is done in a separate thread.
also, since i'm still having issues with crypto++, anyone knows a site thats showing examples with file encryption?
i know this has been done, ive seen examples i just cant seem to figure it out, how if at all can i create an object outside the form, say on the desktop? any help is appreciated, thanks. Oh i use Borland if that helps any...
I have written an application using Visual Studio 6 C++, targeted for Windows XP and 2000. How do I detect/prevent multiple instances of my program?. I only want a single instance running and every time I click the shortcut, I get another instance launched (Duh!).
CreateMutex(NULL, TRUE, _T("Unique_String_Identifying_The_Application"));
if (GetLastError() == ERROR_ALREADY_EXISTS)
//Do whatever you have to do if one instance is already running and exitreturn;
You can place this code in InitInstance() for example.
Last Visit: 31-Dec-99 18:00 Last Update: 23-Sep-23 12:24