|
|
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.
|
|
|
|
|
You call MoveFirst() which sets the pointer to the first record. A following call to MovePrev() will of course fail with DB_S_ENDOFROWSET because the pointer is already at the first position which is the end of the row set for backward scrolling operations.
I can't help further without knowing what you finally want to achieve (why do you want to scroll backwards). But moving backwards when already at the first position makes no sense.
|
|
|
|
|
I am inserting some values in MDB.
Lets say, after inserting 10 values, the pointer will be at 11 row since every time after inserting i will call movenext(). Now while inserting 11th value, i want to go to 10th row and delete the value in 10th row for which i need to call moveprev().
modified 12-Aug-18 7:35am.
|
|
|
|
|
This was not really clear from your question. To know what happens you should at least show some example lines. Note also that the behaviour depends on the used cursor type.
A common method to identify rows that has been inserted is using bookmarks which can be used later to select the row.
Maybe you should also rethink your design because inserting a row and deleting it within the same session makes no sense. Your code should detect that in advance so that there is no need to insert that row at all.
|
|
|
|
|
That was just an example i have given but not the exact requirement. But at any cost i want to perform this MovePrev() operation once at the end for my project requirement. But some how its failing (returning error code) even after setting the property on CBPropSet.
CDBPropSet cdbPropset(DBPROPSET_ROWSET);
cdbPropset.AddProperty(DBPROP_CANSCROLLBACKWARDS, true);
CCommand <CAccessor<CLabelsAccessor>,CRowset> cCommand;
hr = cCommand.Open(m_Session, csSQLQuery, &cdbPropset);
if( SUCCEEDED( hr ) )
{
hr = cCommand.MoveFirst();
for(int i = 0; i < 3; i++)
{
cCommand.m_labelvalueindex = 1;
cCommand.m_labellinenumber = 2;
hr = cCommand.Insert();
hr = cCommand.MoveNext();
}
cCommand.Close();
}
After the for loop i just want to perform Moveprev(). Can you tell me any wrong in above code.?
|
|
|
|
|
As already noted: Use bookmarks (see Using Bookmarks[^]).
Set the bookmark when at the position you want to access later where you can then use MoveToBookmark() .
|
|
|
|
|
Since my command class is CRowSet, there is no SetBookMark() method on it.
|
|
|
|
|
It is a CAccessor member.
|
|
|
|
|
Small correction in my question. The error code is -2147217837.
|
|
|
|
|
Sampath579 wrote: Can you tell me any wrong in above code.? Is there a need to call MoveNext() ? The for() loop is just inserting 3 rows, correct?
"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
|
|
|
|
|
If I don't call the movenext then pointer will be at one row and the data may overwrite.
In my requirement I want to moveprev one step and delete it.
|
|
|
|
|
Sampath579 wrote: If I don't call the movenext then pointer will be at one row and the data may overwrite. How have you verified 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
|
|
|
|