|
I think i read somewhere that you need to initialize and uninitialize COM in every thread that will use it, so maybe try calling CoInitialize (and CoUninitialize) in your thread and see if it changes anything.
> The problem with computers is that they do what you tell them to do and not what you want them to do. <
|
|
|
|
|
OK, here's one for you Win32 die-hards...
How can I check if a window (specified by its HWND ) is a top-most window - i.e. one that was brought to the top by calling SetWindowPos (..., HWND_TOPMOST, ...) ?
Thanks,
/ravi
|
|
|
|
|
You can use GetWindowLong() function with parameter GWL_EXSTYLE and then check for style WS_EX_TOPMOST..
I hope it helps..
Regards,
Sandip.
|
|
|
|
|
Heh, no - that only checks the if the window was created with that style or if the style is modified. Changing a window's Z-order (by calling SetWindowPos() ) doesn't affect the window's style.
Nasty li'l problem there...
/ravi
|
|
|
|
|
Ravi Bhavnani wrote: hanging a window's Z-order (by calling SetWindowPos()) doesn't affect the window's style.
May be but documentation for CreateWindowEx does not say that...
From MSDN:
WS_EX_TOPMOST
Specifies that a window created with this style should be placed above all non-topmost windows and should stay above them, even when the window is deactivated. To add or remove this style, use the SetWindowPos function.
Regards,
Sandip.
|
|
|
|
|
Argh! I'm an idiot - I was checking GWL_STYLE instead of GWL_EXSTYLE . Thank you, thank you, thank you!
/ravi
|
|
|
|
|
Check out GetWindow()
Mark
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
Not quite - here's why: I'm writing an app (happens to be a C# app, so all calls to Win32 are PInvoked) that allows you to make any visible app window "always on top". Setting/unsetting a window's "always on top" state is easy.
What I want to do (or rather, would like to do ) is get the existing "always on top" states from each window instead of maintaining my own list of always-on-top windows (which could get out of sync). Hence the need to be able to check if a window is currently at the top of the Z order.
GetWindow() would allow me to get the collection of app windows (children of the desktop), but I'm already able to do this by iterating through the collection of running processes.
/ravi
|
|
|
|
|
How about iterating thorough the popup windows using GetNextWindow[^], and when there is no next window, then your current is at the top, right?
> The problem with computers is that they do what you tell them to do and not what you want them to do. <
|
|
|
|
|
No, because you can have several "always on top" windows (each belonging to a different app). What I'm looking for is a way to get the Z-order of any top-level window, i.e. a GetWindowPos() equivalent of SetWindowPos() .
/ravi
|
|
|
|
|
Am not sure what you mean, but even "always-on-top" windows are in the z-order, they are just kept over "non-always-on-top" windows, so one "always on top" window CAN overlap another "always on top" window.
> The problem with computers is that they do what you tell them to do and not what you want them to do. <
|
|
|
|
|
Code-o-mat wrote: one "always on top" window CAN overlap another "always on top" window.
Correct. "always on top" means always on top of all non "always on top" windows. But that doesn't help in identifying which windows exhibit the "always on top" behavior.
/ravi
|
|
|
|
|
And you are absolutely sure that what is suggested here[^] does not work? I did a little test, made a window, set it to topmost using SetWindowPos and then checked its ex-style and it did become WS_EX_TOPMOST set. Am i missing the point here?
> The problem with computers is that they do what you tell them to do and not what you want them to do. <
|
|
|
|
|
Argh! I'm an idiot - I was checking GWL_STYLE instead of GWL_EXSTYLE . Thank you, thank you, thank you!
/ravi
|
|
|
|
|
Ravi Bhavnani wrote: No, because you can have several "always on top" windows (each belonging to a different app).
But IIRC, the active apps windows will be at the front? So something like GetTopWindow(GetForegroundWindow()); should do? You'd need to check if the result of GetTopWindow was NULL, as that indicates a window with no child windows, so you would use the result of GetForegroundWindow instead.
HWND foreground = GetForegroundWindow();
HWND top = GetTopWindow(foreground);
top = top?top:foreground;
|
|
|
|
|
Better you use EnumWindows()[^] to enumerate all the windows and check the window handle you receive in the call back function with the handle retrieved with GetWindow()[^] function (by passing desktop window handle as first parameter and GW_CHILD as second parameter). Even you can compare the same handle with the handle returned by GetForegroundWindow()[^], but there could be chance that the foreground window isn't the topmost in the z-order.
|
|
|
|
|
I am currently working on a program which uses a GUI (written in C++ with MFC) to gather data from a user. When the user hits go, the program then analyzes the data and returns the results back to the user. The elapsed time between the time the user hits go and the results are returned is approximately 1 minute. In certain cases, it could be as high as 10 minutes. During that time, the program ignores any mouse clicks and when I bring up the Window’s task manager, the status of the program is that it is not responding. However, the calculations are complete, the program response as expected. However, for an end user, I do not believe that the program just hanging is acceptable. For example, if minimized and then restored it needs to be able to repaint the screen.
What should I do to remedy the situation? I am thinking that if I did the calculation in a separate thread that it would solve this problem. What do you think of this idea? Maybe somebody knows a better way to handle this situation.
Thanks
Bob
|
|
|
|
|
Hi! Since the data processing procedure is running in UI thread, so no message processing operation will be performed, and that is the reason of blocking of the user interface.
A simple solution is when user click the "Start" button, set the state of the UI elements (e.g. enable or disable) correctly to avoid invalid user operation and run the data operation from another thread. You can place a process bar on the form to indicat that the application is in "Busy" state while data processing is running.
|
|
|
|
|
Yes, doing the analysis in a separate thread is the way to go. See this[^] link.
/ravi
|
|
|
|
|
try "sleep(0)" this will make windows execute its message queue
here's msdn explanation:
A value of zero causes the thread to relinquish the remainder of its time slice to any other thread of equal priority that is ready to run. If there are no other threads of equal priority ready to run, the function returns immediately, and the thread continues execution.
A value of INFINITE indicates that the suspension should not time out.
|
|
|
|
|
dehseth wrote: try "sleep(0)" this will make windows execute its message queue
Actually it won't. You still need to manually flush the message queue by calling PeekMessage() in order to convey the impression of multi-threading.
/ravi
|
|
|
|
|
I am using visual c++ and using the numericupdown button to control the change of picturebox's image, I have set the numericupdown from 0 to 90 and set the program like the following, but then I discover that when I press up down button to change the value in numericupdown, 1 represent 0, 2 represent 1...the number is shifted(i use the textbox to check hte numericupdown->value)so,those image show in the picturebox are not in correct order.....How can I solve it??
private: System::Void numericUpDown1_ValueChanged(System::Object^ sender, System::EventArgs^ e) {
a = numericUpDown1->Text;
b=Int32::Parse(a);
switch (b)
{
case 0 : pictureBox1->Image = Image::FromFile("r1.jpg");
textBox1->Text=a;
break;
case 1 : pictureBox1->Image = Image::FromFile("r2.jpg");
textBox1->Text=a;
break;
default: pictureBox1->Image = Image::FromFile("r3.jpg");
textBox1->Text=a;
break;
}
|
|
|
|
|
Am not exactly sure i understand what you mean there, but i did run into the following "problem" with the up-down buttons: when you get the notification message from the control, the control's value did not get changed yet, only after the message. (So, if the control's value is 2, and the user presses the up button to increase it, you get a notification, if you ask the control about its current value in the message handler, you get 2, and then after the message handler has returned it will change to 3.). However, the notification message also has some parameters telling you weather the user increased or decreased the numeric value and you can use this to figure out the current number, look up the documentation for it and you will know what do to. Good luck and happy xmass.
> The problem with computers is that they do what you tell them to do and not what you want them to do. <
|
|
|
|
|
Hi,
I have a class with constant member variable. As constant member variables MUST be initialized in the constructor initializer list, how do I write an assignment operator for such a class. E.g.
class MyClass
{
public:
MyClass() : m_ConstantMember(0) - (1)
{}
MyClass(int intvar) : m_ConstantMember(intvar) - (2)
{}
MyClass(MyClass const& rhs) - (3)
: m_ConstantMember(rhs.m_ConstantMember)
{}
MyClass& operator = (MyClass const& rhs) -- (4)
{
if(this != &rhs)
{
m_ConstantMember = rhs.m_ConstantMember; -------- (4a)
//memcpy((void*)&m_ConstantMember,
(void*)(int*)&rhs.m_ConstantMember,
sizeof(m_ConstantMember)) ------------ (4b)
}
return *this;
}
private:
int const m_ConstantMember;
};
The above class has one constant member variable of type int. This variable MUST be initialized in the constructor initializer list. This is achieved in the above class by
1. No argument constructor
2. One argument constructor
3. Copy Constructor
For the assignment operator, if I write a statment as in 4a, the compiler complains. However if I write the statement as in 4b, the compiler is happy and I get the desired result.
So my query is whether the statement 4b is the correct way of writing an assignment operator for a class with constant member variable? If not can someone please tell me the correct way of writing the assignment operator.
Thanks and Regards.
|
|
|
|
|
Why are you trying to chqange the value of a const? Constants are constants because their value is constant, it does not change during their lifetime. The compiler complains about it because basicly you are telling it to: "make a constant whose value never changes once it is set, and now chane it.". if you want to change the value then don't make it const.
> The problem with computers is that they do what you tell them to do and not what you want them to do. <
|
|
|
|