|
yogeshs,
I think you are confusing two things: Windows window with MFC object that is not a window.
MFC object encapsulates window handle and only after window handle is valid, such an object represent Windows window. There are three ways to make MFC object alive (assign a valid handle):
Calling member function Create for a given class
Calling Attach
Subclassing window
Only calling Create and Subclassing will allow MFC object handling messages of the attached window.
Calling Attach will not allow process any messages processing, since window procedure has not been replaced by the object’s window procedure.
You should post a snippet that shows a function where it assert. Your code snippet does not make much sense since the meaning of the GetDlgItemId is unknown. Regardless, it looks like you are trying to attach an object that is already alive, meaning Windows window has MFC object attached to it. MFC code does it for you.
Please answer one question that I have already asked: What version of Visual Studio you are using? Maybe taking it from here will be more beneficial for you.
JohnCz
|
|
|
|
|
I am using Vs2008 professional.
Thanks For Your Reply.
Trying To Understand.
Thanks
Yogesh
|
|
|
|
|
OK, that is good so far. If you have SP1 installed, why not to follow my previous advice (from my earlier response):
If you are using VS 2008 with feature pack or with SP1 use CMFCButton class. To set button face color, call SetFaceColor member. You have to set m_bTransparent to FALSE anf disable teaming by calling EnableWindowsTheming member and passing FALSE as parameter.
This is much easier than reinventing a wheel.
JohnCz
|
|
|
|
|
Hello JohnCz
I tried to use CMFCButton but there is no class in VS2008 prof.
Do i need to link up something?
Thanks Again.
Regards
Yogesh
|
|
|
|
|
yogeshs wrote: I tried to use CMFCButton... How? When you added a button to the dialog template and went to assign a variable to it, the Add Member Variable Wizard defaulted to CButton . All you need to do is change that to CMFCButton . The appropriate header file (i.e., afxbutton.h ) would have been added automatically, if it was not already included.
"One man's wage rise is another man's price increase." - Harold Wilson
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
"Show me a community that obeys the Ten Commandments and I'll show you a less crowded prison system." - Anonymous
|
|
|
|
|
Hi yogeshs,
You have to learn how to be patient and read all answers and documentation without skipping some parts.
I have already mentioned twice:
If you are using VS 2008 with feature pack or with SP1 use CMFCButton class.
You need Visual Studio SP1 installed.
Web installer[^]
ISO image[^]
Than you can subclass button using CMFCCustButton.
Subclassing is easy if you use wizard:
Right click on the button in the resource editor and choose Add Variable.
The only option you have is CButton, so select it.
After wizard closes, open dialog’s header file and change CButton to CMFCMenuButton.
JohnCz
|
|
|
|
|
yogeshs wrote: CColorbutton* pBtn = new CColorButton(); pBtn->Attach(GetDlgItemId( IDC_BUTTON_ID + ndx )->GetSafeHwnd());
It's highly unlikely that you would need to do this. Why not just replace CButton with CColorbutton in your dialog's .h file?
"One man's wage rise is another man's price increase." - Harold Wilson
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
"Show me a community that obeys the Ten Commandments and I'll show you a less crowded prison system." - Anonymous
|
|
|
|
|
Hello david
I didnt get your point.
Regards
Yogesh
|
|
|
|
|
Hi all,
i was just wondering if what are the advantages/disadvantages of a reference return vs a pointer return?
Suppose if we have a large vector of objects in terms of performance there is any difference between returning a pointer to a object or the object reference.
Thanks
|
|
|
|
|
What do you mean with 'reference' return?
Usually you obtain 'out' parameters as arguments passed by reference.
Moreover, there is no performance penalty in passing values by reference.
Veni, vidi, vici.
|
|
|
|
|
In terms of performance, they're identical.
In practise, references mean you can use the . operator instead of the -> operator to access member functions/variables.
While there are a considerable number of differences between the two (look into operator overloading - it relies on references), I've just concentrated on the difference as it relates to your question.
[EDIT:] What CPallini said, above.
|
|
|
|
|
There are loads of different rules you can apply here...
- Are you writing a member operator? Return *this by reference
- Are you writing a non-member operator? Return by value and either do your damnedest to trigger NRVO/RVO or write a move constructor in C++11
- Are you transferring ownership of something? Return a std::unique_ptr
- Do you want to read something that legitimately might or might not exist? Use a const pointer using 0 as an error value
- Do you want to read something that should exist and if it doesn't then the whole program's sunk? Return a const reference and throw if something goes wrong
- Are you returning a writable address or a reference to one or more of an object's data members? You are insane, please report to the funny farm
- Do you want to return a reference to an object to an automatic variable? See previous answer for details.
One thing to remember though is that sometimes you'll want to do something that's a bit unusual and you'll have to do something unusual to implement it.
Cheers,
Ash
|
|
|
|
|
Thanks for all the answers.
Giving an example:
vector<int> my_vec;
int* get_int(int positon) {
int* value = my_vec.at[position]
return value;
}
int& get_int(int positon) {
return my_vec.at[position];
}
So both cases will avoid a copy of the object and will be fast them passing by value but besides that what are the differences.
References cant be null so probably returning by reference will have to assure that case, but im more concern in vantages of one side to the other (if there are any).
Thanks
|
|
|
|
|
In both those case I'd return a value, not a reference or pointer. Unless you want to directly modify what's in the vector in which case you'd just use operator[].
Basically return by value first, if that's not what you want use pointers when failure isn't critical, references otherwise.
Cheers,
Ash
|
|
|
|
|
The example is for a vector<int> and in this case its better returning by value, but in cases where we have a vector<my_object> and the object class is big its better returning a reference or a pointer. Just would like to know in those cases which one is better?
Thanks
|
|
|
|
|
Neither - always return by value from a vector. Don't mess about with storing pointers or references. And if you have to store something by reference use a shared_ptr.
If you write the class being stored in the vector correctly (fast default construction, move constructor, transactional exception safe assignment operator, using named return values) copying objects out of collections is very fast.
Cheers,
Ash
|
|
|
|
|
If there are some directories and each directory contains some files then i want to make a program which will compare each file of any directory with each file of all directories.
Can someone suggest me a best approach which works faster and dont miss any comparision.
|
|
|
|
|
Hi friend,
use findfirstfile() and findnextfile()
msdn api's.....hope this will help you
|
|
|
|
|
Hi,
Thanks for your reply. FindFirst/Next file will give me file name.
Here i asked about the approach i.e. container and logic to implement comparision which should be faster and reliable.
|
|
|
|
|
It really depends on what kind a value you wish to return from the function.
For instance I can envisage two basic approaches - true/false for same/not same, or a -/0/+ value as strcmp does.
Here's an approach that just returns true/false.
I've timed it - it takes 6 seconds to compare a 347MB video file with itself - Win7 Home Premium x64, Intel i3 @ 2.13Ghz, 4GB ram - gcc 4.4.1
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
void loadFile(char *szFilename, size_t &sizeOut, char* &bufferOut)
{
FILE *fp;
fp = fopen(szFilename, "rb");
fseek(fp, 0, SEEK_END);
sizeOut = ftell(fp);
fseek(fp, 0, SEEK_SET);
bufferOut = (char*) malloc(sizeOut);
fread(bufferOut, 1, sizeOut, fp);
fclose(fp);
}
bool isSame(char *szFilename1, char *szFilename2)
{
size_t len1, len2;
long curPos;
char *buffer1, *buffer2;
bool result = true;
loadFile(szFilename1, len1, buffer1);
loadFile(szFilename2, len2, buffer2);
if (len1 == len2)
{
for (curPos=0; curPos<len1; curPos++)
{
if (buffer1[curPos] != buffer2[curPos])
result = false;
}
}
else
result = false;
free(buffer1);
free(buffer2);
return result;
}
int main()
{
if (isSame("testVideo.avi", "testVideo.avi"))
printf("Same\n");
else
printf("Not Same\n");
}
|
|
|
|
|
for SuperDuper[^] i did this:
0. build the list of files to compare.
1. read the first 1000 bytes of each file to compare.
2. from those 1000 bytes, generate an SHA1 hash.
3. store the hashes, file size, and file names in a list
4. sort the list by hash values. duplicates will clump together.
5. for hash matches, do a full file compare.
|
|
|
|
|
Chris Losinger wrote: 2. from those 1000 bytes, generate an SHA1 hash.
3. store the hashes, file size, and file names in a list
Why would you want to waste all those cpu cycles by calculating a SHA1 hash? If you know that the maximum number of bytes you're going to read is 1000 then you could have used an inexpensive hashing algorithm... there are dozens of inexpensive hash algorithms that will have a collision probability of zero within 1000 bytes. Your application would probably have a huge performance boost. Not to mention... the SHA1 hash will produce 20 bytes of data to store... you could reduce your database size by 50% just by moving to a more efficient algorithm.
Were you initially planning on hashing the entire file or something?
Best Wishes,
-David Delaune
|
|
|
|
|
it's actually an MD5, but can be switched to SHA1 or whatever, at compile time. (wrote the OP from memory, forgot the default).
Randor wrote: If you know that the maximum number of bytes you're going to read is 1000 then you could have used an inexpensive hashing algorithm.
probably. but the goal was to avoid collisions while using a hash method that was built into the .Net framework. this was a quick utility project. and really, calculating MD5 on 1K is definitely not the bottleneck here; the file scanning and open/read/close totally dominates the process - especially when those files are on a network drive somewhere.
Randor wrote: Were you initially planning on hashing the entire file or something?
actually, yes. (and that's what happens when the 1K scan finds matches). the partial hash pre-scan was a later addition, and i just reused the hash stuff that was already written instead of coming up with a new method.
modified 25-Apr-12 7:48am.
|
|
|
|
|
Hi friends,
I'm trying to create My own service for .exe.
my service create function successfully creates service but when i try to start to that service
then it gives error code 1053 which is ERROR_SERVICE_REQUEST_TIMEOUT. also i saw that startservice() fun goes in waiting for 30seconds
and then gives error 1053.
pls help,
here is my code for ur ref...
hServiceMGROpen=OpenSCManager(serverName,SERVICES_ACTIVE_DATABASE,SC_MANAGER_ALL_ACCESS);
if(hServiceMGROpen!=NULL)
{
hServiceOpen=OpenService(hServiceMGROpen,"myService",SERVICE_ALL_ACCESS);
if(hServiceOpen!=NULL)
{
succStart=StartService(hServiceOpen,0,NULL);
if(succStart)
{
printf("Service starts successfully ");
}
else
{
DWORD err=GetLastError();
printf("Error %d",err);
}
}
}
Thanks in advance...!!!
Sangam
modified 24-Apr-12 5:46am.
|
|
|
|
|
What does it mean:
here is my code for ur ref...
Anyway, ERROR_SERVICE_REQUEST_TIMEOUT, means that your ServiceControlHandler (or whatever name you have used to register handler callback) is not responding fast enough to the setvice start request, blocking StartServiceCtrlDispatcher. Or you did not call StartServiceCtrlDispatcher at all.
If you have to perform some lenghty procedure when the service starts, do it in the thread, or after setting service start status.
JohnCz
|
|
|
|