|
I would use a different approach:
- Have an event queue (practically - a single element) that contains pairs - <player, time="" of="" move="">
- When a player makes a move, insert a <player, time="" of="" move=""> pair into the queue
- Have a timer thread that updates the clock display every <tbd> milliseconds
- Before updating the clock, it:
4.1 Reads the current time using the same clock used by the player threads
4.2 Checks the event queue to see if a move was made, and when it was made
4.3 If a move was made, it updates the players' times, stops one clock, and starts the other
There will always be an unavoidable lag in the visual display of the clock because of the O/S's scheduling requirements, but the internal counts will be accurate.
Freedom is the freedom to say that two plus two make four. If that is granted, all else follows.
-- 6079 Smith W.
|
|
|
|
|
Having a timer activate every millisecond involves using something like sleep_for, right? Is that less susceptible to delays than wait_until is? Either way, it does certainly having the advantage that any timer-related delays won't block the main thread.
|
|
|
|
|
Hi,
I doubt your condition_variable::wait_until code is causing the redraw delay based on what you've shown.
Invalidating the rect simply creates an update region and then marks an internal 'dirty bit' associated with the window. The operating system is somewhat lazy updating the window... it could be redrawn a few milliseconds later... or several seconds later depending on how many messages are in the message queue.
If you want an immediate redraw add a call to the UpdateWindow function immediately following your invalidation.
Best Wishes,
-David Delaune
|
|
|
|
|
While I must admit that I don't know how to gracefully debug the timer, I'm pretty sure the join call is producing at least some of the noticeable delays. I tried just adding an UpdateWindow call after the InvalidateRect call in turnTimer as a simple test, but that deadlocked the program, which led me to read about how it's flatly incorrect to do a lot of kinds of window manipulations from another thread. I'm not sure if InvalidateRect is one of them and I just kept getting lucky with the original implementation, which also called it from the timer thread, but I suppose the fact that I'm not sure is enough reason to switch to something like Daniel described even if I weren't getting the lags. I'll try it and see what happens.
modified 16-Dec-18 22:25pm.
|
|
|
|
|
Hi,
Yep, Daniel gave you some great advice. You don't really need a second thread.
My assessment is the same... InvalidateRect does not redraw the window, it simply marks it as dirty. Your main source of visual delay is most likely waiting for a WM_PAINT message.
If you use the event driven model Daniel suggested maybe you could add a redraw event handler that invalidates and redraws the window.
Best Wishes,
-David Delaune
|
|
|
|
|
I've implemented this approach, and it's working for me. It proved to be easier to factor for multi-platform support than what I had before would have been, too.
|
|
|
|
|
I'm happy to have helped.
Freedom is the freedom to say that two plus two make four. If that is granted, all else follows.
-- 6079 Smith W.
|
|
|
|
|
I'm looking for a way for my application to receive a notification whenever the PC connects to a WiFi network. I need to know the name of the network so that I can configure stuff differently depending upon which network the user is connected to.
I found this on MSDN: AddConnectNotify function | Microsoft Docs[^]
However, it looks like that function is for receiving notification of connections to network resources on the network that you're already connected to. It is not for receiving a notification of actually connecting to the network itself.
Does anyone know what I'm looking for?
Thank you.
SOLUTION:
I found this function which is exactly what I'm looking for: WlanRegisterNotification function | Microsoft Docs[^]
The difficult we do right away...
...the impossible takes slightly longer.
modified 14-Dec-18 22:29pm.
|
|
|
|
|
Hi,
Program is throwing exceptions "This command is not available" while calling "Editpaste" and "Editreplace" functions from code in Word automation. This is happening sporadically not every time. Any suggestions please?
|
|
|
|
|
narasingubhanu wrote: Any suggestions please? Those commands are not working correctly. Exactly why is a mystery, as we have no idea what your code is doing.
|
|
|
|
|
Yes. its mystery on Windows 10 only . My code will edit word document with some values and it gives to printer.
|
|
|
|
|
I hope this is not going to be another one of "read the book" discussion.
( And if you already do not like my remark, do not read the rest of this post)
This is very simple , but as always I am not sure about using correct terminology.
The attached code , struct variable , is taken from C code tutorial.
gcc++ compiler generates this error
sorry, unimplemented: non-trivial designated initializers not supported
Mrs Google say it is because gcc++ does not like C style "reference" "." It also say not to use "=" , but use ":" .
OK, I generally can follow instructions , BUT
If I do not use "." my IDE won't supply all available "options" anymore.
No big deal, in this case, however I like to know if I can change some options in gcc++ or if this a IDE "issue".
struct spi_ioc_transfer tr = {
tx_buf:(unsigned long)tx,
this works fine no error
};
|
|
|
|
|
You have either set the C++ standard flags low or the default on your compiler is not c11++ or greater
I have no issue with GCC or VS2017 taking structs like that.
try the flag
-std=c++11
or I would probably try and see if it is available
-std=c++20
BTW if it is actually a C file you need different flag .. I know you were playing with C files before
-std=c11
Now that I think about that I am guessing that is the issue you are compiling C files with G++ .. don't
Setup your make file to send C files to the c compiler gcc, you can make a rule based on the extension .c vs .cpp
.c files => gcc
.cpp files => g++
Visual Studio actually does exactly that it uses the filename extension to decide on c vs c++ compiling, which is why it works on it.
In vino veritas
modified 12-Dec-18 12:51pm.
|
|
|
|
|
Is there any method to list files from local HDD into a CListView, but, most important, have two points:
1. Have an item icon just like you see in standard windows explorer.
2. Have right click menu just like you have in standard windows explorer.
modified 11-Dec-18 7:42am.
|
|
|
|
|
|
No, there is no problem listing files found on HDD, but setup them an icon (in CListView of course) just like Windows Explorer does, and then have the same contextual menu like Windows Explorer has ...
|
|
|
|
|
Windows Explorer uses a splitter window. The left hand pane is a TreeView and the right is (usually) a ListView. Both Windows controls are clearly documented on MSDN.
|
|
|
|
|
_Flaviu wrote:
1. Have an item icon just like you see in standard windows explorer. See here.
_Flaviu wrote:
2. Have right click menu just like you have in standard windows explorer. See here.
"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
|
|
|
|
|
I am really sorry because I was not clear on my first post.
Let say I list a text file in my CListView. And I must setup an icon to that item, but that icon should be exactly like in windows explorer. I mean, if a text file in windows explorer has a Notepadd++ icon, I wish the same icon to my CListView. The same matter if I list a pdf file ... if this file has a pdf icon in windows explorer, I wish to have the same icon to the item that list that pdf file in my CListView.
And if I see in windows explorer a contextual menu, I wish to have the same contextual menu in my CListView.
|
|
|
|
|
For icons, see here and here.
"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
|
|
|
|
|
Ok, thank you, I guess I am on the right road regarding icons ... remain only context menu
|
|
|
|
|
I have an owerdraw ComboBox When a user selects an Item I want to Display the Detail info
I figure I could use the same Dialog for Background
So for the 6 CStatic and Their 6 Labels I do ShowWindow(SW_HIDE)
I saw the following post on how to drive DrawItem by Calling invalidate an the SetWindowText
Getting owner draw child control to paint when calling SetWindowText - vc.mfc[^]
So I create my own derived CStatic
class MyStatic : public CStatic
{ DECLARE_DYNAMIC(MyStatic)
public:
MyStatic();
~MyStatic();
void SetWindowText(LPSTR);
void DrawItem(LPDRAWITEMSTRUCT pdis);
};
This my SSetWindowText
void MyStatic::SetWindowText(LPSTR lpsz)
{
Invalidate();
CStatic::SetWindowText(lpsz);
}
two bad things on the way to getting where I want
1) I get an exception in wincore.cpp at the retrun ::CallWindowProc
RESULT CWnd::DefWindowProc(UINT nMsg, WPARAM wParam, LPARAM lParam)
{
if (m_pfnSuper != NULL)
return ::CallWindowProc(m_pfnSuper, m_hWnd, nMsg, wParam, lParam);
WNDPROC pfnWndProc;
if ((pfnWndProc = *GetSuperWndProcAddr()) == NULL)
return ::DefWindowProc(m_hWnd, nMsg, wParam, lParam);
else
2) After the exception my Drawitem is called however ItemData doesn't have the String pointer and and is NULL
Thanks
|
|
|
|
|
Didn't have a message map entry from my Derived CStatic
also the text of the Static control isn't set in the itemData you have to a GetWindowText to get it
with those two fixes everything worked
|
|
|
|
|
有什么学习MFC的途径和论坛,我是MFC软件开发的。
|
|
|
|
|
Member 14076567 wrote: What are the ways and forums for learning MFC, I am developing MFC software.
This is an English-language site. Please post questions in English.
Via Google Translate:
这是一个英语网站。 请用英文发布问题。
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|