|
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.
|
|
|
|
|
GetForegroundWindow doesn't give a rats if your dialog has focus or not. At a guess you have the dialog in modal mode and the message queue is shutdown and your code isn't executing when it isn't focused
https://msdn.microsoft.com/en-us/library/windows/desktop/ms633505(v=vs.85).aspx[^]
It is quite specific it's the window that's currently getting input regardless of its relationship to the calling thread (aka your little APP). It has two choices the focus window (or the windows that contains the focus window depends on class) or null if the desktop itself has focus.
If you doubt it download and use spy++ and click on the focus window with the mouse to get its details
Introducing Spy++ - Visual Studio | Microsoft Docs[^]
You should also be able to confirm it with GetLastActivePopup.
GetLastActivePopup function (Windows)[^]
The call they have closed down is its sister call SetForegroundWindow() to steal focus from another process (unless that process has explicitly given permission via AllowSetForegroundWindow) because lots of web browser popups were abusing it.
In vino veritas
modified 12-Aug-18 22:40pm.
|
|
|
|
|
I've look at different (many) suggested solutions but they are always failing me in some regards.
I have a list control in report mode with the "always show selection" flag set in the resource editor.
I have a button that will set the selection on a item in the list (a row).
The code to set the selection is :
m_PositionListBox.SetFocus();
m_PositionListBox.SetItemState(nItem, LVIS_SELECTED, LVIS_SELECTED);
m_PositionListBox.SetItemState(nItem, LVIS_FOCUSED, LVIS_FOCUSED);
When I do the above, I see the selection change (highlighted), but then just disappears.
Am I missing something ?
I'd rather be phishing!
|
|
|
|
|
Something seems amiss here. I dummied up a project with VS2008 and your code seems to do what is expected.
CONTROL "",IDC_LIST1,"SysListView32",LVS_REPORT | LVS_SHOWSELALWAYS | LVS_ALIGNLEFT | WS_BORDER | WS_TABSTOP,14,15,278,153
...
BOOL CTempDlg::OnInitDialog()
{
CDialog::OnInitDialog();
m_PositionListBox.InsertColumn(0, _T("Name"), LVCFMT_LEFT, 100);
m_PositionListBox.InsertItem(0, _T("Ford"));
m_PositionListBox.InsertItem(1, _T("Chevrolet"));
m_PositionListBox.InsertItem(2, _T("Honda"));
m_PositionListBox.InsertItem(3, _T("Toyota"));
m_PositionListBox.InsertItem(4, _T("GMC"));
m_PositionListBox.InsertItem(5, _T("Jeep"));
return TRUE;
}
...
void CTempDlg::OnBnClickedSet()
{
int nItem = 3;
m_PositionListBox.SetFocus();
m_PositionListBox.SetItemState(nItem, LVIS_SELECTED, LVIS_SELECTED);
} When I click the Set button, item #3 (Toyota) is selected (blue). If I then press the Tab key, focus goes to the OK button but item #3 stays selected (gray).
"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 9:43am.
|
|
|
|
|
THanks, I will bake a dummy project on my side either, see if there's something different.
I'd rather be phishing!
|
|
|
|
|
I've got it working with
m_PositionListBox.SetItemState(-1, 0, LVIS_SELECTED| LVIS_FOCUSED);
m_PositionListBox.SetItemState(currentStep - 1, LVIS_SELECTED| LVIS_FOCUSED, LVIS_SELECTED| LVIS_FOCUSED);
Thanks.
I'd rather be phishing!
|
|
|
|
|
I want to use recursive descent algorithm to compute an arithmetical expression, but I can't get the right value,so please tell me how to write the code
here is my grammar
E→E+T|E-T|T
T→T*F| T/F|F
F→(E)|i
the following is my code
<pre>
#include<stdio.h>
#include<string>
using namespace std;
int pos = 0;
string str = "1+2*3-4";
double E();
double T();
double F();
int main() {
double v = E();
printf("%f", v);
getchar();
return 0;
}
double E() {
double v = 0;
char c = str.at(pos);
if (c == '+') {
pos++;
v = E() + T();
}
else if (c == '-') {
pos++;
v = E() - T();
}
else {
pos++;
v = T();
}
return v;
}
double T() {
double v = 0;
char c = str.at(pos);
if (c == '*') {
pos++;
v = T() * F();
}
else if (c == '/') {
pos++;
v = T() / F();
}
else {
pos++;
v = F();
}
return v;
}
double F() {
char c = str.at(pos);
if (c == '(') {
pos++;
double v = E();
c = str.at(pos);
if (c == ')') {
pos++;
return v;
}
}
else {
string s = "";
while (true) {
c = str.at(pos);
if (c >= '0' && c <= '9') {
s += c;
pos++;
}
else {
break;
}
}
return atoi(s.c_str());
}
return 0;
}
modified 9-Aug-18 2:57am.
|
|
|
|
|
You are not checking for '-':
if (c == '+') {
pos++;
v = E() + T();
}
else if (c == '+') { pos++;
v = E() - T();
}
You are also incrementing the value of pos if the operator is not one of the two you test for. So when you call the next function it will see the next character rather than the current one. You could improve this by replacing all these functions with a single switch block.
|
|
|
|
|
The logic in your parse functions is flawed: it first looks for the operator, and only then looks for the arguments. This would only work for an expression like "+ 1 2" rather than "1 + 2".
You have to change your code to first split it into tokens and then check the second (and maybe following) token(s) of the remaining part of your expression string for operators, before passing the first token(s) and the rest of the tokens (after the operator) on to the next recursion step.
P.S.: It is always a bad idea to use global variables in a program. But it is especially devastating when using recursive functions! I don't see any reasonable way to implement E(), T() and F() without passing the part of the string that needs to be analyzed. The advantage is that you don't need to split the whole string into tokens up front as I suggested at first. Instead each function just searches its part of the string for the operators that it can interpret, extract the arguments of that operator accordingly, and pass those into further recursive calls.
P.P.S.: example for function E():
double E (const std::string& str) {
size_t op_pos = str.find_first_of("+-", 1); if (op_pos == std::string::npos) { return T(str);
}
std::string first_operand = str.substr(0, op_pos);
std::string second_operand = str.substr(op_pos+1);
return (str.at(op_pos) == '+')
? E(first_operand) + T(second_operand)
: E(first_operand) - T(second_operand)
}
GOTOs are a bit like wire coat hangers: they tend to breed in the darkness, such that where there once were few, eventually there are many, and the program's architecture collapses beneath them. (Fran Poretto)
modified 9-Aug-18 4:43am.
|
|
|
|
|
Have you seen this?
"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
|
|
|
|
|
|
Hi
In my MFC application i am reading and MDB file using CCommand as follows:
CDBPropSet cdbPropset;
CCommand <CAccessor<CMyClass>, CRowset> cCommand;
cdbPropset.AddProperty(DBPROP_CANSCROLLBACKWARDS, true);
cCommand.Open(m_pSessionManager->m_Session, csSQLQuery);
hr = cCommand.MoveFirst();
hr = cCommand.MovePrev();
In above code MovePrev() always throwing 265926 error code which is End Of RowsSet.
Can any on let me know whats wrong in my code.? Why record is not moving to previous row?
Thanks for the help.
modified 8-Aug-18 2:40am.
|
|
|
|