|
|
Thanks Anders,
It worked!!
BRs.
|
|
|
|
|
I just converted to VS7 and had to change some things around.
My good old #include <fsream.h> did not work anymore, so I converted to CStdioFile.
the problem is that now, the "\n" is not being printed out to the file, even though the microsoft site claims WriteString shoud do it.
Here is my code:
<br />
CStdioFile log_file (_T(file.txt"),CFile::modeWrite | CFile::modeCreate | CFile::typeText);<br />
<br />
CString h="Hello\nThere";<br />
log_file.WriteString (h);<br />
<br />
The expected output is:
Hello
There
But I get:
HelloThere
|
|
|
|
|
I think you get the output that way 'cos the file was opened in typeText.
I'd be interested to know if it worked with
"Hello\r\nThere".
Clinton
|
|
|
|
|
Are there example on DrawDragRect?
I need one specific dealing when the object is drag outside the window.
Case 1: Assume L mouse click is release when it's outside the window
Case 2: Don't assume mouse is release. Check mouse status when it reenters the window.
The other thing I would like to do is change mouse icon if it's drag outside the window range with L mouse click still down.
Thanks
|
|
|
|
|
|
The following code works but not like the examples I have reviewed on this site. Please provide comments on improving and/or explanations on comments. The OnClose() function in my class is getting the WM_CLOSE message before my DoModal loop sees it.
The CRpt class is used in a generic class and therefore is not a child of the main window. I may also want to create a CRpt in a console application, therefore I need a message loop or the CRpt window opens and immediately closes.
Any help would be appreciated.
Class CRpt : public CWnd
{
...
public:
int DoModal(HWND parent=NULL);
bool isClosed; // set to false in constructor, set to true in OnClose
...
}
int CRpt::DoModal(HWND parent)
{
//ASSERT(::IsWindow(m_hWnd));
//parent = AfxGetMainWnd()->GetSafeHwnd(); 'from calling procedure'
ShowWindow(SW_RESTORE);
if(parent!=NULL) ::EnableWindow(parent, FALSE);
for(bool finished = false; !finished && !isClosed; WaitMessage()) {
MSG msg;
while(PeekMessage(&msg, 0, 0, 0, PM_REMOVE)) {
if(msg.message==WM_QUIT) {
AfxMessageBox("WM_QUIT"); // <--never gets here
finished = true;
::PostMessage(NULL, WM_QUIT, 0, 0); //PostMessage(WM_QUIT, 0, 0);
break;
}
if(!isClosed) { // <--set to true in OnClose(); needed or i get assert on next line!?!
if(!IsDialogMessage(&msg)) { //::IsDialogMessage(m_hWnd, &msg)
::TranslateMessage(&msg);
::DispatchMessage(&msg);
}
} else {
finished = true;
break;
}
}
}
//AfxMessageBox("Exiting DoModal");
if(parent!=NULL) {
::EnableWindow(parent, TRUE);
//::ShowWindow(parent, SW_SHOWNORMAL); // <--not working!?!
::ShowWindow(parent, SW_MINIMIZE); // <--needed or SW_RESTORE doesn't work!?!
::ShowWindow(parent, SW_RESTORE);
}
//DestroyWindow(); // called in OnClose()
return 0;
}
|
|
|
|
|
are there any "known' caveats when using _malloc_dbg ?
do I have to use the _free_dbg ?
from the small tests I did, seems I can use _malloc_dbg and simply use free.
Thanks.
M.
Maximilien Lincourt
Your Head A Splode - Strong Bad
|
|
|
|
|
the docs on msdn say that you must use _free_dbg.
Thank You
Bo Hunter
|
|
|
|
|
|
peterchen wrote:
guard bytes,
Sir,If you don't Midn please tell me What is Guard bytes
-----------------------------
"I Think this Will Help"
-----------------------------
Alok Gupta
visit me at http://www.thisisalok.tk
|
|
|
|
|
No need for the Sir, Sir
malloc_dbg calls malloc, but requests a few more bytes. These bytes are filled with a predefined value. free_dbg then checks if these extra bytes still hold this value. If they did, you probably wrote beyond the allocated memory (The VC Runtime prints a diagnostic message to the debug output)
Typical implementations add 4 bytes at the end. In this case, using free instead of _free_dbg is often not a problem, but depending on the implementation, it might leak the guard bytes.
But if an implementation adds guard bytes *before* the memory provided to you (to detect underflows, which are less common), using free instead of -free_dbg is likely to corrupt the heap.
we are here to help each other get through this thing, whatever it is Vonnegut jr. boost your code || Fold With Us! || sighist | doxygen
|
|
|
|
|
Yeah Right,
I understand _malloc_dbg and _free_dbg thanks.
About
peterchen wrote:
Sir
That a way to Show Respect to Elder.
Thanks Again Sir!!!
-----------------------------
"I Think this Will Help"
-----------------------------
Alok Gupta
visit me at http://www.thisisalok.tk
|
|
|
|
|
Hi
Can someone tell me how to program an alt+tab replacement similar to the one microsoft uses in the powertoys?
Capturing Alt+Tab probably won't be the problem, but how to I replace the dialog in the center of the screen with my own?
See http://www.microsoft.com/windowsxp/downloads/powertoys/xppowertoys.mspx
regards
modified 12-Sep-18 21:01pm.
|
|
|
|
|
Here is an article that demonstrates XP Visual styles but also has examples of the code you are looking for...
ALT-TAB enhanced with XP styles[^]
Alex Korchemniy
|
|
|
|
|
That's great, thanks a lot!
modified 12-Sep-18 21:01pm.
|
|
|
|
|
Thanks for the info. I suspected this was not possible but it would have been so handy.
Yarp
http://www.senosoft.com/
|
|
|
|
|
You can use the functions: _splitpath and _makepath or _fullpath.
Or their Generic-Text Routine Mappings: _tsplitpath, _tmakepath, _tfullpath.
In order to break the path apart and put it back together. Thats easier than trying to break it up youself. Of you cource you could just copy the module path into a temporary buffer, search for myAppName.exe and replace it, but that is not generic.
INTP
"The more help VB provides VB programmers, the more miserable your life as a C++ programmer becomes."
Andrew W. Troelsen
|
|
|
|
|
I'm trying to update a text file by overwritting a part of the text in the middle of the file. I'm using the fwrite function.
I manage to overwrite something unfortunately the new text overlaps the text of the contiguous line when it is longer than previous text.
For example:
My first line
Line to override
My next line
Gives:
My first line
Overriden line which is longer
ext line
I wonder if it is possible to insert longer than previous line text with fwrite and if so how to do, if not how to do
I don't have the code here but it is something like the folowing (assuming you are reading line 2 only):
<br />
fFile = fopen("myfile.txt", "r+");<br />
...<br />
fgets(pBuffer)) {<br />
ftell();<br />
fWrite("new text");<br />
fflush(fFile)<br />
...<br />
}<br />
fclose(fFile);<br />
Sorry for the code, if you want more I can post it later.
Yarp
http://www.senosoft.com/
|
|
|
|
|
No, you cant do that way, you have to read the whole file into a buffer, make the change in the buffer and then write to the file.
for safetly you write it to a temp file and if the write succeeds then rename it to the original file name ofcource delete the first one.
or if you are not too bother about data in the file and would like to take a change, then write it to the same file.
-prakash
|
|
|
|
|
hi folks,
First, just to let you know that I use g++ to compile the src containing following code segments. Now lets start the business.
This is a templated class method I got:
template<class T>
void
SynchList<T>::Apply(void (*func)(T))
{
lock->Acquire();
list->Apply(func);
lock->Release();
}
and this is the function pointed by the function pointer:
void
SimpleThread(Thread *tmpThread)
{
int num;
for(num = 0; num < 5; num++)
{
cout << "***thread " << tmpThread->GetId() << " looped " << num << " times" << endl;
kernel->currentThread->Yield();
}
}
I have "bathList" as a pointer to SynchList<Thread *>:
SynchList<Thread *> *bathList = new SyncList<Thread *>;
and this is how I implement it (@ line 494 of the src):
bathList->Apply((void) (SimpleThread)(Thread *));
but I get this error msg everytime I try to compile the code:
../threads/thread.cc:494: parse error before '*'
Any help would be greatly appreciated.
Thank you all,
James
|
|
|
|
|
Lucky you I just wrote at least a dozen template classes and template functions the take function pointers as arguments so this should help!
Your function pointer agument must match the actual function pointer that is passed (C++ is far more picky than C):
LONG (*Func)(A1,T*) != LONG (WINAPI *Func)(A1,T*)
void (*Func)(T) != void (_cdecl *Func)(T) // THIS PROBABLE THE PROBLEM
void (CDECL *Func(T*) == void (_cdecl *Func)(T*)
Here is a partial example of a templated function that takes a function pointer as an argument (Note the template take the function pointer argument not the function that is produced):
template<class T, class A1, LONG (WINAPI *Func)(A1,T*)>
T* my_Get1(A1 Arg1)
{
...
T* pData = new T;
nResult = Func(Arg1,&pData);
...
return pData;
}
void someFunc()
{
...
MYTYPE pT = my_Get1<MYTYPE,ARGTYPE,MyFunc>(Arg1);
...
delete pT;
}
Have fun!
INTP
"The more help VB provides VB programmers, the more miserable your life as a C++ programmer becomes."
Andrew W. Troelsen
|
|
|
|
|
with all do respect,
I reckon the pointer argument I pass to the method matches to the actual function pointer argument.
Given the function signature is:
void
SynchList<T>::Apply(void (*func)(T))
and I implement it as:
bathList->Apply((void) (SimpleThread)(Thread *));
where bathList points to "SynchList<Thread *>" , "SimpleThread" is a funciton name, and "Thread *" is same as in "SynchList<Thread *>"
Is there anything else that I probably didn't notice causing the error ?
Your kindness is truly appreciated !
|
|
|
|
|
If you wrote the function like so:
void SimpleThread(Thread* pThread)
{
...
}
The try the following:
bathlist->Apply(SimpleThread); // The name SimpleThread is the pointer
INTP
"The more help VB provides VB programmers, the more miserable your life as a C++ programmer becomes."
Andrew W. Troelsen
|
|
|
|
|
thank you John,
bathList->Apply(SimpleThread) actually works !!
I did what I did to try to follow the signature and didn't even notice that the argument (Thread *) itself is illegal at all. I think template instantiation takes care of that by induction, and since "SimpleThread" is already a void function, so no need to re-cast (void) again ?
Am I heading the right direction ?
Thanks again.
James
|
|
|
|