|
Thanks. It compiled OK. What should this become?
int discanf(HWND db, int c, char*fmt, ...) {
char C[256];
GetDlgItemText(db, c, C, 256);
C[255] = 0;
return vsscanf(C, fmt, (&fmt) + 1);
}
|
|
|
|
|
Anthony Appleyard wrote: What should this become?
Come on man, this is something that you can easily figure out. You've been a member here for over 10 years.
You know the old Chinese proverb?
If you give a man a fish he is hungry again in an hour. If you teach him how to catch a fish you feed him for his lifetime.
You've already had your daily fish. I highly encourage you to figure it out yourself. If you get stuck feel free to come back for more fish.
Best Wishes,
-大衛王
|
|
|
|
|
For a start having an int variable called c , and a char array called C is bad enough in the same module. But in the same function it is beyond ridiculous. Use proper meaningful unique names for all your variables.
|
|
|
|
|
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 ...
|
|
|
|