|
Sorry. I started computer programming in the late 1960's, when computer storage was much smaller (80,000 words memory was big), under early compilers such as Atlas Autocode and Basic, and I got accustomed to one-letter and two-letter variable names.
Thanks for your help.
modified 15-Aug-18 12:02pm.
|
|
|
|
|
Anthony Appleyard wrote: I got accustomed to one-letter and two-letter variable names.
I confirmed that it compiles in Visual Studio 2017. I am calling it "C Notation" naming convention.
#define C 256
int Ƈ(HWND č, int c, char* Ç, ...)
{
char ₵[C];
va_list Ĉ;
va_start(Ĉ, Ç);
GetDlgItemText(č, c, ₵, C);
₵[C] = 0;
return vsscanf(₵, Ç, Ĉ);
}
If you use this... your coworkers will pick you up and throw you out of the office.
Best Wishes,
-David Delaune
|
|
|
|
|
There is something truly sublime about that code. 
|
|
|
|
|
I started in 1966 and the only time I used single letter names was when coding in Fortran IV.
|
|
|
|
|
Hi, I read a block of code, like:
class Graph
{
public:
int V; vector<int> *adj;
Graph(int V);
void addEdge(int x, int y);
bool isRoute(int x, int y);
};
Graph::Graph(int V)
{
this->V = V;
this->adj = new vector<int>[V];
}
void Graph::addEdge(int x, int y) {
adj[x].push_back(y);
}
int main() {
Graph g(6);
g.addEdge(5, 2);
g.addEdge(5, 0);
g.addEdge(4, 0);
g.addEdge(4, 1);
g.addEdge(2, 3);
g.addEdge(3, 1);
}
I wonder the adj is a pointer that points to a Vector object, and a vector object I think it's like an one-dimensional array, but the addEdge() operation, adj[x].push_back(y),it make another array[x,y].
in Main(), the structure of the vector object, seems like:
[5,2,0]
[4,0,1]
[2,3]
[3,1]
Then this is not an one-dimensional array.so this is a Vector object, or 4 vector objects?
Thanks
|
|
|
|
|
Not sure what any of that means. But why not use a POINT structure (or create your own), and then you can have a vector of points?
struct POINT
{
int x;
int y;
};
vector<POINT> pointList;
|
|
|
|
|
focusdoit wrote: I wonder the adj is a pointer that points to a Vector object
No, it's an array of vectors with V elements. So it's a two-dimensional data structure.
|
|
|
|
|
vector<int> *adj; //adjacency list
is it point to an Vector object?
|
|
|
|
|
Yes, it's a pointer to a vector, but you are trying to assign an array of vectors to it. Why not use the suggestion I offered above?
|
|
|
|
|
Thanks, I am reading the program.
Just try to understand why a pointer to an array, be used as an array of vectors.
|
|
|
|
|
It's not a pointer to an array, it's a pointer to a vector (singular). If you want a pointer to an array of vectors then you need something like:
vector<int> *varray[];
Then each element of varray will need to be a vector<int>* , that is, a pointer to a vector. A vector is an instance of the vector class so each pointer will point to a single vector.
|
|
|
|
|
is it similar to a pointer that points to an integer.
like:
int a = 0;
int *ip = &a;
then (ip+1) point to an integer too. but do we need to allocate memory space to it?
|
|
|
|
|
Yes, you must always allocate memory if you intend to read from or write to it. A pointer declaration does not allocate any memory, it is just a single variable that can be used to address individual items. But the memory space to hold the items must be allocated before you use the pointer.
|
|
|
|
|
Memory is allocated in the constructor:
this->adj = new vector<int>[V];
|
|
|
|
|
|
Hi. How can I retrieve the HWND of a control inside CDialog, and this control has the focus ? To get the next HWND control I can use GetNextWindow[^], but I can retrieve the HWND of the next or previous control that has the focus ...
In fact, I wish to use (while I am in CDialog):
HWND hWnd = ::FindWindow(NULL, _T("Some dialog"));
if(NULL != hWnd)
{
::SetWindowText(GetFocus()->GetSafeHwnd(), sText);
}
but without GetFocus ...
modified 10-Aug-18 9:32am.
|
|
|
|
|
_Flaviu wrote: How can I retrieve the HWND of a control inside CDialog, and this control has the focus ? Does the control have a member variable associated with it?
_Flaviu wrote:
but without GetFocus ... What is your aversion to using GetFocus() ?
"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
"You can easily judge the character of a man by how he treats those who can do nothing for him." - James D. Miles
modified 10-Aug-18 10:00am.
|
|
|
|
|
No. In fact, it a CDialog which belong to another app.
|
|
|
|
|
"What is your aversion to using GetFocus()?"
Because this dialog is not belong to my app, and if there is another window in foreground, this GetFocus() will not work.
modified 13-Aug-18 7:58am.
|
|
|
|
|
Understood.
Does this thread even remotely talk about what it is that you are attempting to do?
"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
"You can easily judge the character of a man by how he treats those who can do nothing for him." - James D. Miles
|
|
|
|
|
GetForegroundWindow and GetActiveWindow are the goto functions.
GetActiveWindow give you the active window of your app if it was activated and topmost.
GetForegroundWindow function is the special function specifically designed for obtaining windows from other processes. It is the windows system topmost window, so if a window has focus it will be that window.
All windows recieving focus get WM_SETFOCUS messages and those losing it receive WM_KILLFOCUS messages which is the other way to track focus changes.
In vino veritas
|
|
|
|
|
GetForegroundWindow and GetActiveWindow are doing the job when this dialog has the focus ... but in my case this dialog is very possible to haven't focus, and
::SetWindowText(GetFocus()->GetSafeHwnd(), sText);
is not working ... and I guess GetForegroundWindow and GetActiveWindow are useless ...
|
|
|
|
|
|
I have tried:
HWND hWnd = ::FindWindow(NULL, _T("Dialog Test"));
if(NULL != hWnd) {
CString sTemp;
hWnd = ::GetTopWindow(hWnd);
while(NULL != hWnd)
{
hWnd = ::GetNextWindow(hWnd, GW_HWNDNEXT);
int nID = ::GetDlgCtrlID(hWnd);
if(1001 == nID) {
::SetWindowText(hWnd, _T("ABC ABC"));
sTemp.Format(_T("%d"), nID);
MessageBox(sTemp);
}
}
}
but ::SetWindowText simply not set the text (is not changing the text) ... strange ...
|
|
|
|
|
Some comments:
1.) If you are not the author of the target process then from a purely conceptual point of view you are attacking the process. The modern UWP applications will limit these types of cross process interactions. You should check if the target process supports Active Accessibility, UI Automation, or IAccessibleEx.
2.) If you need to send input such as WM_CHAR to a window owned by another process you may need to use the AttachThreadInput function before sending the WM_CHAR or other input messages.
3.) The SetWindowText function can only be used in the current process. It cannot be used to set the text in a window owned by another process.
4.) To set the text of a window in another process you will need to send the WM_SETTEXT message directly.
5.) The SendMessage function can cause your program to hang. Use SendMessageTimeout instead.
6.) You will need to make sure that the process setting the text is of greater or equal integrity levels. For example... a process running at medium level cannot set the text in a window owned by a process running at high integrity level.
Best Wishes,
-David Delaune
P.S. The solution to your problem is in bold.
|
|
|
|