|
Prem Kumar wrote:
I think what u mean is not the cursor but the 'Caret',
yes u can get the position but to get the exact location
about where it is located viz line, char pos has to be loacted
by you.
Use 'GetCaretPos' to get the pt(co-ords) and convert it into the
character position u need.
Just out of curiosity why do u need this position
First of all thanks you, i want to get this position to display a listbox because i wanna make something just like the visual studio intellisense
Thanks for all
56Kbps of sighs
|
|
|
|
|
Hi All,
I've got an app that eeds to copy some data to the clipboard. I wrote some code to do this based on a couple of articles I found here, and implemented a copy to clipoboard functionlaity for plain text. So far, so good. But, no I need to copy the same data out as RTF also. Anybody know a simple way I can copy data to the clipboard in multiple formats? Here's sopme code that's not quite working, I am getting a debug assertion the second time through the loop, for the second clipboard format (RTF(:
void CClipboardItem::CopyToClipboard(HWND& hWndNewOwner)
{
// Open the clipboard
OpenClipboard(hWndNewOwner);
EmptyClipboard();
// For every format in the set of supported formats, render data
FormatIterator it;
UINT uFormat;
for(it = m_setFormats.begin(); it != m_setFormats.end(); it++)
{
// Create a shared memory file
CSharedFile sf(GMEM_MOVEABLE | GMEM_SHARE | GMEM_ZEROINIT);
// Render the clipboard data to te shared memory file for the given format
uFormat = *it;
RenderClipboardData(sf, uFormat);
SetClipboardData(uFormat, sf.Detach()); // OOPS! This asserts the second time
}
// All done, let go of the clipboard
CloseClipboard();
}
Any idea why this doesn't work?
|
|
|
|
|
Hey, I'm trying to use Message Reflection for a button I've derived from CButton which is Owner Drawn. I put this in my Message Map:
ON_NOTIFY_REFLECT(WM_MOUSEMOVE,OnMouseMove)
but when I try to goto ClassView it gives me this error:
Parsing Error: Illegal line encountered.
Input Line: ON_NOTIFY_REFLECT(WM_MOUSEMOVE,OnMouseMove)
What am I doing wrong? I'm new to this relecting deal, is there an alternatve?
|
|
|
|
|
Hey, I'm trying to use Message Reflection for a button I've derived from CButton which is Owner Drawn. I put this in my Message Map:
ON_NOTIFY_REFLECT(WM_MOUSEMOVE,OnMouseMove)
but when I try to goto ClassView it gives me this error:
Parsing Error: Illegal line encountered.
Input Line: ON_NOTIFY_REFLECT(WM_MOUSEMOVE,OnMouseMove)
What am I doing wrong? I'm new to this relecting deal, is there an alternatve?
|
|
|
|
|
ON_NOTIFY_REFLECT() only works for WM_NOTIFY messages.
If you've derived a class you don't need to use reflection anyway; just add ON_WM_MOUSEMOVE() and implement OnMouseMove() & you're good to go!
Sometimes i only remember, The days when i was young Nowadays no one remembers when they were young and stupid... ADEMA, The Way You Like It
|
|
|
|
|
Well I tried that but I put a break in the OnMouseMove function and it never gets there there?
|
|
|
|
|
Make sure:- the button is being created/subclassed correctly: do other message handlers in your CButton-derived class get called?
OnMouseMove() has the correct signature: void OnMouseMove(UINT nFlags, CPoint point); - you're moving the mouse over the button
Sometimes i only remember, The days when i was young Nowadays no one remembers when they were young and stupid... ADEMA, The Way You Like It
|
|
|
|
|
- Yes, DrawItem and OnCreate both get called (DrawItem repeatedly of course)
- No, OnMouseMove and OnTimer both do not work
- OnMouseMove does have that signature
- Of Course
I was led to believe that if the button was owner drawn it had to be reflected
|
|
|
|
|
Actually, when I turn OwnerDraw off the notifications get through just fine, so I think reflection is necessary...can you lead me through it? thanks in advance
|
|
|
|
|
Reflection is used by MFC to allow handling messages sent from a control to be handled by the control itself. WM_DRAWITEM is sent by the button control to its parent; however it is cleaner for the code to exist within a class derived from CButton, rather than wherever the CButton-derived class is used. So there is ON_WM_DRAWITEM_REFLECT() which causes DrawItem() to be called.
WM_MOUSEMOVE (OnMouseMove() ) and WM_TIMER (OnTimer() ) both are sent to the control itself, so they do not need reflection to be handled by the CButton-derived class.
None of this helps with your immediate problem, however
There's nothing special about an Owner-drawn button that keeps it from getting WM_MOUSEMOVE. Double-check (wait, i guess it'd be triple-check) that your class looks something like this:
BEGIN_MESSAGE_MAP(CButtonDerivative, CButton)
ON_WM_DRAWITEM_REFLECT()
ON_WM_MOUSEMOVE()
END_MESSAGE_MAP()
void CButtonDerivative::DrawItem(LPDRAWITEMSTRUCT lpDrawItemStruct)
{
}
void CButtonDerivative::OnMouseMove(UINT nFlags, CPoint point)
{
}
Sometimes i only remember, The days when i was young Nowadays no one remembers when they were young and stupid... ADEMA, The Way You Like It
|
|
|
|
|
I have a folder that i would like to password protect so you double click on it and you get a password box there needs to be one password that shows the folder and one that shows a different folder and anything else you put in stops you opening it?
How can this be done?
|
|
|
|
|
this sounds like a windows question more than a coding question? win NT lets you setup folder permissions if you are using NTFS, if your running win 9X then this isn't possible without a 3rd party peice of software
-dz
|
|
|
|
|
3rd party software like.....
|
|
|
|
|
Go search on download.com or some other site.. win9x uses fat16 or fat32 which has no security at all.. ntfs is the nt file system which lets you set read/write/edit/delete permissions for files or folders.. if you are on fat16 or fat32 then you have to get a piece of software which fakes this out.. but even this can easily be bypassed by just booting to dos and doing whatever you want with the files..
-dz
|
|
|
|
|
I'm a total virgin when it comes to shell extensions, but I think this is where they would come into play. Check under the Shell section. Mike Dunn has wrote some cool articles on Shell extensions which should get you well under way.
Cheers!
"An expert is someone who has made all the mistakes in his or her field" - Niels Bohr
|
|
|
|
|
I do not know, whether this can be helpfull, but according to msdn:
Multiple Data Streams
NTFS supports multiple data streams, in which the stream name identifies a new data attribute on the file. Each data stream is an alternate set of file attributes. Streams have separate opportunistic locks, file locks, allocation sizes, and file sizes, but files can be shared.
Maybe it is possible to define such stream as password-stream associated with given file system object
Mukkie
|
|
|
|
|
I am trying to implement a simple multithreading in my code. I have a dialog box where the user can search for stuff and get the result back in list control. However, if the search result takes too long, I would like to allow my user to stop the search by clicking on Cancel.
I have added a structure to my header which contains a handle to calling window and a few parameters that I need to pass between the worker thread and the display.
On the cpp side of things, I start my threading function when the user presses the search button:
HANDLE hHandle = ::AfxBeginThread(ThreadFunc, m_ptp);
Where m_ptp is defined as a pointer to my threading structure and Threadfun is my threading function.
Inside of my ThreadFunc, I make a query to the database and this query can take significant amount of time at times. I have tried with many different ways of putting an hour glass around this call, but it never shows up. FOr instance, I have tried the following and it doesn't work:
UINT ThreadFunc(LPVOID pParam)
{
THREADPARMS *ptp = (THREADPARMS*) pParam;
ptp->pWnd->BeginWaitCursor();
// Database call
ptp->pWnd->EndWaitCursor();
::PostMessage(hWnd, WM_USER_THREAD_FINISHED, 0, 0);
}
I have also tried starting the cursor in the calling function and it hasn't worked out for me. Any ideas?
|
|
|
|
|
Pointers to windows can't be used between multiple threads. Try passing just the window handle.
Tim Smith
I know what you're thinking punk, you're thinking did he spell check this document? Well, to tell you the truth I kinda forgot myself in all this excitement. But being this here's CodeProject, the most powerful forums in the world and would blow your head clean off, you've got to ask yourself one question, Do I feel lucky? Well do ya punk?
|
|
|
|
|
Is your window in the ptp structure part of your ThreadFunc, or the primary thread. Because it is generally not a good idea to call functions for a window, unless it is the same thread that owns the window. In most cases it will just not work.
Also, even if the function is setting the cursor to the wait cursor, the most likely reason that it is not showing is because the WM_SETCURSOR message handler is setting the cursor back the arrow.
What you can do is set a variable in your window object, then handle the WM_SETCURSOR message in your window. This message should call SetCursor() with the wait cursor while that certain bit is set, and pass the message to defwindowproc when that value is not set.
|
|
|
|
|
This is the exact solution that I need. Thank you, kilowatt!
|
|
|
|
|
Use something like:
::PostMessage(hWnd,WM_USER_THREAD_STARTED,0,0);
OnThreadStarted(...
{
BeginWaitCursor();
}
OnThreadfinished(...
{
EndWaitCursor();
...
}
|
|
|
|
|
I have written a TFTP server using CSocket, and CAsyncSocket. I have also re-written it using the SDK socket functions (no MFC). No matter what I do, a 6MB file is taking about 77 seconds (at 512 byte block sizes).
Unfortunately, I cannot make use of the Block Size option to gain speed. The client will not be able to handle it. Re-writing the client is not an option.
We tried a Linux TFTP server, and it transferred the file in about 12 seconds!
Any ideas on why there is such a big difference, or how I can speed things up?
I also tried playing with the thread priorities, and got no increase in performance.
I have tried other servers off the web, and they all perform the same.
Is it possible to get a TFTP server to transfer a file with speeds similar to Linux?
Thank you,
David
|
|
|
|
|
Those huge differences in performance are by no means justified. My hunch is you're doing something wrong. Maybe if you could post the code where you do the transfer we could see a little further.
Joaquín M López Muñoz
Telefónica, Investigación y Desarrollo
|
|
|
|
|
Here is where the code will spend most of it's time. This loop is sending the next block (512 byte size) of the file requested.
It calls SendBlock() listed below this loop.
The UpdateStatus, and all if it's formatting routines were disabled, just to see if that was the cause.
Sorry about the formatting, I can't seem to find the help on how to insert source code without losing the formatting from Visual Studio.
while (!m_bDone){
m_bCancelRetry = TRUE;
m_nRetryCount = 0;
//Sending a file
if (pbyData[0] == 0x00 && pbyData[1] == 0x04){
//ACK
if (pbyData[2] == HIBYTE(m_nBlockID) &&
pbyData[3] == LOBYTE(m_nBlockID)){
//ACK'd the last block we sent:
if (m_nBlockID == m_nLastBlockID){
m_nBlockID = -1;
AddReportString("Transfer complete.");
DWORD dwTime = GetTickCount();
CString szTime;
szTime.Format("Time to complete = %.2f seconds",(float) (((float)dwTime - (float)m_dwStartTime) / 1000));
AddReportString(szTime);
Abort();
}
else{
m_nBlockID++;
SendBlock();
}
}
else{
//Send the last block
//(no m_nBlockID++) increment here
SendBlock();
}
}
nResult = recvfrom(m_hSock,(char*)m_recvBuf,9126,0,&sockAddr,&nSockAddrLen);
if (nResult == SOCKET_ERROR){
DWORD dwErr = GetLastError();
CString szErr;
szErr.Format("RecvFrom() error = %08lX",dwErr);
AddReportString(szErr);
bErr = TRUE;
m_bDone = TRUE;
}
}
int CClientSock::SendBlock()
{
int nRet = 0;
m_bySend[0] = 0x00;
m_bySend[1] = 0x03; //Data
m_bySend[2] = HIBYTE(m_nBlockID);
m_bySend[3] = LOBYTE(m_nBlockID);
DWORD dwPos = (m_nBlockSize * (m_nBlockID - 1));
BYTE *pSrc = (m_FileData.GetData() + dwPos);
int nNum = m_nBlockSize;
if ((dwPos + nNum) > m_dwFileDataLength){
nNum = m_dwFileDataLength - dwPos;
}
memcpy(&(m_bySend[4]),pSrc,nNum);
sockaddr_in sockTo;
sockTo.sin_family = AF_INET;
int nToLen = sizeof(sockTo);
sockTo.sin_addr.s_addr = inet_addr((LPSTR)(LPCTSTR)m_szClientIP);
sockTo.sin_port = htons(m_nClientPort);
nRet = sendto(m_hSock,(char*)m_bySend,nNum + 4,0,(struct sockaddr*)&sockTo,nToLen);
if (nRet == SOCKET_ERROR){
DWORD dwErr = GetLastError();
CString szMsg;
szMsg.Format("Error %08lX found while sending file to client.",
dwErr);
AddReportString(szMsg);
}
else{
float pct = (float)(((float)dwPos / (float)m_dwFileDataLength) * 100.0);
CString szStat;
szStat.Format("%s: %lu bytes sent (%.0f%%)",m_szSendFile,dwPos,pct);
m_pServer->UpdateStatus(m_nSocketID,szStat);
}
return nRet;
}
|
|
|
|
|
I think I see the problem now. Thanks for taking a look at it.
|
|
|
|
|