|
You want to use the function GetWindowRect to get the window coordinates. From that you can then call
SetCursorPos and apply the correct offsets.
x_coord+=x_offset;
y_coord+=y_offset;
Search for GetWindowRect on google and it should take you to the msdn page for that function.
Chipper Martin
|
|
|
|
|
Gday everyone,
Please help me.
How to read and write a pointer of character to a file in C?
Thanks in advance.
Eric
eric
|
|
|
|
|
You don't write the pointer to a file. You write the data which the pointer points to.
char* string = ...;
FILE* pStream = fopen("file", "w");
fwrite(string, 1, strlen(string), pStream);
--
Mit viel Oktan und frei von Blei, eine Kraftstoff wie Benziiiiiiin!
|
|
|
|
|
Hi,
I'm trying to write a program that can copy a file URI into any window by drag and drop.
The problem lies in C++, so far i've found only two methods:
GetLogicalDrives and GetLogicalDriveString.
In .NET there is this eqivalent:
Environment.GetLogicalDrives and
DriveInfo.GetDirectories.
Im wondering if there is any eqivalent in Visual C++
Thanks
Tom
|
|
|
|
|
What does a URI have to do with GetLogicalDrives() or GetLogicalDriveString() ? How does drag/drop relate to all of this? Please explain what it is that you are after.
"Talent without discipline is like an octopus on roller skates. There's plenty of movement, but you never know if it's going to be forward, backwards, or sideways." - H. Jackson Brown, Jr.
"Judge not by the eye but by the heart." - Native American Proverb
|
|
|
|
|
DavidCrow wrote: What does a URI have to do with GetLogicalDrives() or GetLogicalDriveString()? How does drag/drop relate to all of this? Please explain what it is that you are after.
Ok, My app is supposed to display a tree view of the file system, you can then select the file you want. Then you drag a cross hair like in Spy++, to the window and it will copy the absolute path of the file to the location you dragged the crosshair to.
I know that can be done without an app been written, but in some windows that don't support drag/drop operations, eg. Lan Connections Screen in Internet Options.
Dragging the cross hair over the selected area will retreive the handle of the control and send a WM_PASTE message to that control and paste the file path into the selected window.
Tom
|
|
|
|
|
As soon as you start dragging from your tree control, are you sending a TVN_BEGINDRAG notification message?
"Approved Workmen Are Not Ashamed" - 2 Timothy 2:15
"Judge not by the eye but by the heart." - Native American Proverb
|
|
|
|
|
DavidCrow wrote: As soon as you start dragging from your tree control, are you sending a TVN_BEGINDRAG notification message?
I don't think you understand!
You don't drag from the tree view, you drag the crosshair like in Spy++ (See The Window Finder Article)
They'd be a cross hair in the bottom of the screen, then when you drag the cross hair onto the window, eg. Textbox , it would copy and paste the file path from the tree view into the window control that you dragged the cross hair.
Thanks
Tom
|
|
|
|
|
So what exactly is the problem? Implementing the crosshair? Figuring out what is selected in a tree control? Setting the text of an edit control?
"Approved Workmen Are Not Ashamed" - 2 Timothy 2:15
"Judge not by the eye but by the heart." - Native American Proverb
|
|
|
|
|
DavidCrow wrote: So what exactly is the problem? Implementing the crosshair? Figuring out what is selected in a tree control? Setting the text of an edit control?
The exact problem is implementing the drag and drop procedure so it works out of the current program, the cross hair needs a function that returns the window handle or control handle, so I can send a WM_PASTE message to the necessary control.
Tom
|
|
|
|
|
Tom Moore wrote: ...the cross hair needs a function that returns the window handle or control handle, so I can send a WM_PASTE message to the necessary control.
From the article:
Whenever the mouse moves, get the screen position of the mouse (GetCursorPos() )
Get the HWND of the window beneath the mouse (WindowFromPoint() )
"Approved Workmen Are Not Ashamed" - 2 Timothy 2:15
"Judge not by the eye but by the heart." - Native American Proverb
|
|
|
|
|
i want to post a thread message that contain a CString variable like this:
<br />
PostThreadMessage(m_pThread->m_nThreadID,WM_MSG,0,(LPARAM)sString.GetBuffer(sString.GetLength()));<br />
and then handle the msg at the Thread side to process this CString variable
like this:
<br />
CString s = (LPTSTR)pMsg->lParam;<br />
AfxMessageBox(s);<br />
the code compile without errors but the data displayed in the Message box is not the same CString variable that have been sent
so i wanna know wat is wrong with this code
thnx 4 ur time and concern
|
|
|
|
|
singersinger wrote: PostThreadMessage(m_pThread->m_nThreadID,WM_MSG,0,(LPARAM)sString.GetBuffer(sString.GetLength()));
u pass a pointer to the function. Some times by the time the message was recieved by the thread, sString have got desctructed. So the memory that the lParam was pointing will b a invalid one.
Try the bolow approch.
LPTSTR lpMessage = new TCHAR[sString.GetLength()];
_tcscpy( lpMessage , sString);
PostThreadMessage(m_pThread->m_nThreadID,WM_MSG,0,(LPARAM)lpMessage);
and in the thread side
LPTSTR lpMessage = (LPTSTR)pMsg->lParam;;
CString s = lpMessage;
delete lpMessage;
AfxMessageBox(s);
nave
|
|
|
|
|
thnx alot 4 ur fast reply
this code solved the problem
thanks agian ;)
|
|
|
|
|
If you post a message, you can never be sure when in time the message will arrive on the other side. As such, you cannot use a CString object, unless you know for sure that will be alive when it arrives at the message's recipient. Consider this:
{
CString str = ...;
PostThreadMessage(m_pThread->m_nThreadID, WM_MSG, 0, LPARAM(str.GetBuffer());
}
LRESULT Handler(UINT nMsg, WPARAM wParam, LPARAM lParam)
{
LPCTSTR lpsz = LPCTSTR(lParam);
DoStuff(lpsz);
} Can you see the race condition? This will work, if and only if, the Handler() function gets to execute before the str goes out of scope (by which time it's destructor is called). Chances are (very likely) that the str object has been destroyed before Handler() is called. You passed a pointer to the internal string buffer inside the str object. That internal string buffer is deleted in the destructor of the str object. So, Handler() will receive a dangling pointer...
It is much safer if you do this:
{
CString str = ...;
TCHAR* copy = new TCHAR[str.GetLength() + 1];
lstrcpy(copy, str.GetBuffer()); str.ReleaseBuffer();
PostThreadMessage(m_pThread->m_nThreadID, WM_MSG, 0, LPARAM(copy));
}
LRESULT Handler(UINT nMsg, WPARAM wParam, LPARAM lParam)
{
LPTSTR lpsz = LPCTSTR(lParam);
DoStuff(lpsz);
delete [] lpsz;
} You allocate a copy of the string in the which you pass to the handler. It is then up to the handler to delete the string.
--
Mit viel Oktan und frei von Blei, eine Kraftstoff wie Benziiiiiiin!
|
|
|
|
|
Jörgen Sigvardsson wrote: lstrcpy(copy, str.GetBuffer()); str.ReleaseBuffer();
There is no need to call GetBuffer here. Just use the CString's implicit cast to LPCTSTR.
If you decide to become a software engineer, you are signing up to have a 1/2" piece of silicon tell you exactly how stupid you really are for 8 hours a day, 5 days a week
Zac
|
|
|
|
|
singersinger wrote: PostThreadMessage(m_pThread->m_nThreadID,WM_MSG,0,(LPARAM)sString.GetBuffer(sString.GetLength()));
I agree what Navin has said.
sString is destroyed by the time you tried to access it.
One more thing, GetBuffer call must accompanied by ReleaseBuffer to avoid memory leak.
|
|
|
|
|
prasad_som wrote: One more thing, GetBuffer call must accompanied by ReleaseBuffer to avoid memory leak.
No, that is not true. The CString object's methods are however not safe to use before a matching call to ReleaseBuffer().
--
Mit viel Oktan und frei von Blei, eine Kraftstoff wie Benziiiiiiin!
|
|
|
|
|
i have defined two class that you see below:
class Row
{
private:
char *termState;
int *terms;
public:
Row(int length,int mTCount);
};
class Table
{
private:
Row *rows;
public:
Table(int);
}
in Table() constructor i need to creat an array of Row objects dynamically like this :
Table::Table(int n)
{
rows = new Row[n];
}
how i can call the Row() constructor for this array? is this possible?
more information :
in Row() constructor i want to allocate memory for (char *termState) and
(int *terms) dynamically;
|
|
|
|
|
just a guess, why don't you use std::vector<> ?
|
|
|
|
|
i never used it.
can you give me a link for this topic?
|
|
|
|
|
MSDN : std::vector [^]
std::vector<CMyType> vec;
CMyType o1, o2;
vec.push_back(o1);
vec.push_back(o2);
std::vector<CMyType>::iterator iter;
for (iter = vec.begin(); iter != vec.end(); iter++) {
CMyType obj = *iter;
}
|
|
|
|
|
thanks toxcct
I'll try it
|
|
|
|
|
Alternatively, he could use the boost/tr1 array template as well.
If you decide to become a software engineer, you are signing up to have a 1/2" piece of silicon tell you exactly how stupid you really are for 8 hours a day, 5 days a week
Zac
|
|
|
|
|
erfi wrote: how i can call the Row() constructor for this array? is this possible?
It is possible to call the constructor of the row class. It get's invoked automatically on creation of an object.
ex: This code is not optimized. You should be using destructor of the classes to free the total amount of memory being allocated in this process.
#include "stdafx.h"
#include <iostream>
using namespace std;
class Row
{
private:
char *termState;
int *terms;
public:
Row(int length,int mTCount);
void Display();
};
Row::Row(int a,int b)
{
cout<<"Constructor of the row class is invoked"<<endl;
termState=new char[a];
terms=new int[b];
}
void Row::Display ()
{
cout<<"Display of row class";
}
class Table
{
private:
Row *rows[5];
public:
Table(int);
};
Table::Table(int a)
{
for ( int i=0;i<5;i++)
{
rows[i]=new Row (5,10);
rows[i]->Display();
}
}
int _tmain(int argc, _TCHAR* argv[])
{
Table t(10);
return 0;
}
Somethings seem HARD to do, until we know how to do them.
_AnShUmAn_
|
|
|
|