|
Aargh.. I'm too fast to post messages... memcpy is my solution.
Rickard Andersson
Here is my card, contact me later!
UIN: 50302279
Sonork: 37318
|
|
|
|
|
Hi There,
I am workin on a MDI Document. in that i have a view which will display a Bitmap Image. Every time i open my Bitmap image a new instance of Document class is being created. But what my requirement is that every time i open a Bitmap it should be opend in the Document instance that has been created at the starting of the application.
How can i do it. plz help me out its urgent.
Sreeramachandra G
|
|
|
|
|
I just want to know that how can we submitt our research papers to Microsoft so that it will publish it in its Journal.
God Knows Better
|
|
|
|
|
If you have a string:
char * pName="Paul";
You need to write a small code to reverse the string. The code must be as efficient as possible:
char * pReversedName;
int nLength=0;
nLength=strlen(pName);
pReversedName= new char[nLength];
//Just a simple byte-to-byte copy:
for(int i=0; i
|
|
|
|
|
c-strings are null terminated, always add one to the length of the string if you need to copy the whole string.
pReversedName = new char[nLength+1];
or better yet, use the STL string class (std::string)
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
|
|
|
|
|
Thanks. But besides that, do you think there's an even more efficient way of spelling a string backward? Using ANSI C++?
|
|
|
|
|
Yes. Use a single string.
char* myString = "Paul";
reverseString (myString);
void reverseString
(char* pString)
{
for (nIndex=0; (nIndex < strlen (pString)); nIndex++) {
long nTarget = strlen (pString) - nIndex - 1;
if (nIndex != nTarget) {
char chTemp = pString [nIndex];
pString [nIndex] = pString [nTarget];
pString [nTarget] = chTemp;
}
}
} /ravi
Let's put "civil" back in "civilization"
Home | Articles | Freeware | Music
ravib@ravib.com
|
|
|
|
|
You're version doesn't work because it goes to the trouble of reversing the string twice.
void reverseString (char* pString)
{
int nLast = strlen (pString) - 1;
for (int nIndex = 0; nIndex < nLast; nIndex++, nLast--)
{
char chTemp = pString [nIndex];
pString [nIndex] = pString [nLast];
pString [nLast] = chTemp;
}
}
Tim Smith
I'm going to patent thought. I have yet to see any prior art.
|
|
|
|
|
Argh! You're right, of course! I really shouldn't post this early in the morning.
/ravi
Let's put "civil" back in "civilization"
Home | Articles | Freeware | Music
ravib@ravib.com
|
|
|
|
|
char *pReversedName = _strdup(pName);
_strrev(pReversedName); Note that both _strdup and _strrev are in the standard C library. Using the library functions is 'small', both in terms of the code you write (two function calls) and the efficiency of the code (the library operations are probably optimized).
Software Zen: delete this;
|
|
|
|
|
Drat. I should have had coffee before posting my reply.
/ravi
Let's put "civil" back in "civilization"
Home | Articles | Freeware | Music
ravib@ravib.com
|
|
|
|
|
Well, if you drank the coffee I make, you would have had the solution too. My coffee has a pH of about 1.2, and requires a doctor's prescription.
(I'm on my third cup this morning, and it's a big cup)
Software Zen: delete this;
|
|
|
|
|
|
Can anyone tell me what's the most efficient way to retrieve the middle node from a link list, without having to count the nodes, for one?
Thanks!
|
|
|
|
|
If you have a pointer to the head and tail of the list, you can walk those pointers in opposite directions until they're equal. You're then pointing to the "middle" of the linked list. Of course, this only works when the number of elements in the list is odd.
/ravi
Let's put "civil" back in "civilization"
Home | Articles | Freeware | Music
ravib@ravib.com
|
|
|
|
|
|
Running count is sensible thing to do. But Traversing from both ends sounds like a very alternative option - I'll look into that. Just wondering if it's actually more efficient than keeping count.. Thanks!
|
|
|
|
|
It's definitely less expensive (timewise) but more expensive (storagewise) to keep a count. But in today's world, time is more valuable than space.
/ravi
Let's put "civil" back in "civilization"
Home | Articles | Freeware | Music
ravib@ravib.com
|
|
|
|
|
ok first, some info on this needs to be given before i
can illustrate my confusion...
bonus tho , if you have the patience to read thru this, you'll probably get a pretty good laugh at the end when you read the creative errors
i have managed to whip up while trying to learn the most basic of MFC
I have code to only allow one instance only of my application, like below
// limit to one instance
::CreateSemaphore(NULL, 1, 1, "blah");
if (GetLastError() == ERROR_ALREADY_EXISTS)
{
CString caption;
caption = "blah";
HWND myhand = ::FindWindow(0, caption);
::SetForegroundWindow(myhand);
::ShowWindow(myhand, SW_RESTORE);
return FALSE;
}
than, i have in my CDlgApp 's InitInstance code to detect a parameter called 'startup'
(example)...
// cool code project commandline object
// command line parameters
CCommandLine pCmd;
CString strFlag,strParam;
for( BOOL bRet = pCmd.GetFirstParameter(strFlag, strParam); bRet; bRet = pCmd.GetNextParameter(strFlag, strParam) )
{
if (strParam == "startup") {
// questions come around this areas desired functionality
SetRegistryKey("blah");
CBlahDlg dlg;
m_pMainWnd = &dlg;
int nResponse = dlg.DoModal();
return FALSE;
}
}
// otherwise no parameters, launch app as normal...
SetRegistryKey("blah");
CBlahDlg dlg;
m_pMainWnd = &dlg;
int nResponse = dlg.DoModal();
return FALSE;
now after that said, here comes my confusion ..
the purpose of the 'startup' parameter, and the functionality i need to build
when it detects strParam as 'startup' as in code above, is
1) the ability to create my main application window instance but NOT draw it.
2)While its hidden I need to call a function dlg.function() to enable some startup functionality,
and keep my window hidden...
This way , when a user runs the .exe, it will just execute the code code that limits to one instance, calling
'
::SetForegroundWindow(myhand);
::ShowWindow(myhand, SW_RESTORE);
'
on the hidden window thats already been initialized properly and running at startup.
(the only time it gets the parameter 'startup' is on system startup...)
The second part i worked around fairly easily (i dont know if what i did was 'proper', im a hacker by nature ) by
putting a public member variable 'int isStartupOperation' inside CBlahDlg.
Then , when i detected parameter 'startup' in CBlahApp, i create my main dialog,
and flagged dlg.isStartupOperation to 1.
In CBlahDlg InitDialog , I said if (this->isStartupOperation == 1) { this->function(); }
which allowed me to accomplish the first of my two needs, calling the dialog function without drawing the dialog.
the other need which is to hide the window without drawing I'm still having problems with, a direct result
of of my lack of knowledge about the way things work in this area.
i tried to put in CBlahDlg's OnPaint() operation something that says '
if (this->isStartupOperation == 1) {
CString caption;
caption = "blah";
HWND myhand = ::FindWindow(0, caption);
::ShowWindow(myhand, SW_HIDE);
this->isStartupOperation = 0;
}
'
but that doesnt work as I hoped. first problem with this approach of course, is it flashes the window on the screen before it hides it.
I prefer it is never drawn on screen until the .exe is run w/ no parameters, and the SW_RESTORE is given to than draw the
previously created hidden dialog instance.
second thing i realized is that the call to OnPaint() happens multiple times w/ one DoModal()
so if I say
if (this->isStartupOperation == 1) {
CString caption;
caption = "blah";
HWND myhand = ::FindWindow(0, caption);
::ShowWindow(myhand, SW_HIDE);
this->isStartupOperation = 0;
}
the window gets shown because it doesnt run the hide code after the first call, and it seems to always
be called more than once on the domodal.
if I take out the ' this->isStartupOperation = 0; ' like
if (this->isStartupOperation == 1) {
CString caption;
caption = "blah";
HWND myhand = ::FindWindow(0, caption);
::ShowWindow(myhand, SW_HIDE);
}
even when it runs the SW_RESTORE code , the OnPaint just hides it again and again, and I can never retrieve it...
(this error / discovery really sucked because the app also hides from task list / ctrl -alt -delete so i could get the window! I couldnt recompile code because of conflict w/ running hidden application.
i had to reboot before I could make changes. Than I forgot that the app was still in my startup in registry, so again after
the first reboot, i couldnt access application / recompile changes in code.
i deleted the registry startup call,
had to reboot again, than edited and recompiled my code, and will remember NOT to do that again )
anyway, thats where im at, what im doing, where im confused and need words of wisdom from the windows gods.
thus, i come to codeproject and ask
if anyone made it this far, id love some guidance
thanks all.
josh
todo....
:: insert inspirational text here ::
|
|
|
|
|
I created a Win32 Application project to test some code for display of Unicode. In the main file, i have included <string.h> and <stdio.h>, <stdlib.h>, while when compiling, compiler reports strcpy and strtol as undeclared identifier.
Could you enlighten me what happens here and how to solve this problem?
Regards
World on the way
|
|
|
|
|
C++ requires funcitons to be declared before being used.
The Declaration: describes the interfasce of the function, which parameter types it takes, which type it returns, etc.
C/C++ library functions are declared in the standard headers you need to include.
For the two functions inquestion it's
#include <string.h>
"Vierteile den, der sie Hure schimpft mit einem türkischen Säbel."
sighist | Agile Programming | doxygen
|
|
|
|
|
But i have already included string.h and other header files. This is the point it is so wired.
Regards
World on the way
|
|
|
|
|
Hmm... ok... 1st off, functions ARE identifiers, so nothing weird about that. Now to your problem.
You said you want to use strcpy for Unicode, the correct function is wcscpy . But better yet, if you want to be able to compile with or without Unicode use _tcscpy .
Search for String Manipulation in the documentation for all related functions.
Hope this helps,
-Luis
|
|
|
|
|
How does one move MFC 4.2 MDIChild windows outside the application frame, anhywhere on the desktop? This is being done in one application I know of.
|
|
|
|
|
You can't. The app you are seeing that appears to do this must be changing the window type, or it isn't an MDI child to beging with. Have a look at the window with Spy++.
Neville Franks, Author of ED for Windows. Free Trial at www.getsoft.com
|
|
|
|