|
Hi again,
I'm still having trouble getting rid of flicker from my MFC program (on VC++NET but started on VC++6). I am trying to "simply" display 2 alternating, monochrome bitmaps using an off-screen memory dc buffer and bitblting the reuslt. I have (I think) overriden the OnEraseBkgnd calls, returning TRUE and doing nothing else.
The thing is, I call my Paint function directly, rather than invalidating the window, so (I think) I'm bypassing the messages from being sent anyway. The flicker does not look to be the background colour being painted anyway, it seems that the two images kind of take turns in "dominating" the window. I actually display the images on a microdisplay as an input to an optical system, where a camera grabs a resulting pattern every frame (which is why I'm confident it is the images merging and not the background colour of the window being painted). The problem works itself out over a few thousand frames and then reappears periodically.
Could it be the way I'm bypassing the messages that is causing the problem or something else? Any suggestions greatly appreciated!
|
|
|
|
|
I think there is a problem in your design. I believe that the windows api is not gauranteed to sync windows on the vertical blank so that it is possible to have part of both images on the screen at the same time. This is one problem that is solved with direct draw in which you can tell the blt to wait for the vertical blank signal.
John
|
|
|
|
|
Thanks very much for the replies - could you please tell me more about how to do the direct draw method? Best regards
NICK
ps I'm on WinNT 4, I believe that may not run the latest versions of DirectX?
|
|
|
|
|
Also, you should not call your OnPaint directly especialy if your using a CPaintDC. Windows does soem extra setup/tear down for on apinf stuff. You should write a Draw() procedure which you pass a HDC to and then use a function which uses GetDC() relaseDC() to call you paint function.
If you vote me down, my score will only get lower
|
|
|
|
|
This has been bugging me for years.
In Visual Studios 6, if I go to the frame menus and go [edit] -> [Find] and enter some text and hit "mark all" button, this all works fine. BUT how do you clear the bookmarks where the text has been found????
This is a problem because if I perform another search and select "mark all" again, the bookmarks from the previous search remains. You get bookmarks everywhere.
Any help appreciated, thanks
IGeorgeI
George W
Software Developer
www.zsystems.ca
|
|
|
|
|
IGeorgeI wrote:
...how do you clear the bookmarks...
Ctrl+Shift+F2.
"When I was born I was so surprised that I didn't talk for a year and a half." - Gracie Allen
|
|
|
|
|
Thankyou
ARSALAN MALIK
|
|
|
|
|
does anyone know how many bytes are the header for an mpeg file? I'd like to take the first 20 bytes (or however many) of an existing mpeg of about 500 MB, then take the remaining chunks in 50 MB increments, append the appropriate header info to them all, so that I can split the mpg up into 10 smaller files.
[insert witty comment here]
bdiamond
|
|
|
|
|
|
MPEG doesn't have file headers. The file is a sequence of blocks, each with its own header. Just split at block boundaries and the resulting files will be playable.
|
|
|
|
|
thanks. A friend of mine had a little .exe that he got off of planetsourcecode.com that allows you to do what I was talking about. It seems to work fine. Since I have one, there's no need to write one now!!;P
[insert witty comment here]
bdiamond
|
|
|
|
|
I've got a VC++ program in which I need to determine the dotted-numeric IP address of the PC its running on. What's the best/simplest way to do this?
Thanks for any ideas,
Craig
|
|
|
|
|
Call gethostname() followed by gethostbyname() .
"When I was born I was so surprised that I didn't talk for a year and a half." - Gracie Allen
|
|
|
|
|
Ok...can anyone help me with this problem. I"m havinng troulbe to figure out how to use the data members and fill them both completely with zeros while initiallize them in the default constructor.
Here is what I have so for the my header (.h) file...
class ConnectFour
{
private:
//date members
int board[12][13];
int numChips[7];
public:
ConnectFour();
//default constructor
};
And here is what I have in my .cpp file....
ConnectFour::ConnectFour()
{
board[12][13] = 0;
numChips[7] = 0;
for(int i=0; i < 12; i++)
{
for(int j=0; j<13; j++)
{
board[i][j] = 0;
}
}
for(int i=0; i<7; i++)
{
numChips[i]= 0;
}
}
IS THIS RIGHT?....BELOW IS HOW IT IS SUPPOSED TO BE DONE ON THE DIRECTIONS FOR THIS PROGRAM!
THANKS GUYS ..YOU GUYS SAVE MY LIFE
Data Members:
1.)a 2-dimensional array to hold the board – To make it easier to check for wins you chould use a board that has 12 rows and 13 columns. Only rows 3 – 8 and columns 3 – 9 will actually hold the board (which has 6 rows and 7 columns). The remaining cells will always contain zeros.
2.)a single-dimensional array of 7 ints to hold the number of chips dropped into each column of the board.
Methods
1.)a default constructor to initialize both arrays – filling them both completely with zeros
|
|
|
|
|
(duh to myself )
board[12][13] = 0;<br />
numChips[7] = 0;
Think harder, how are arrays indexed in C++ ( or C ).
you're getting there ... hang tough ...
Maximilien Lincourt
Your Head A Splode - Strong Bad
|
|
|
|
|
Maximilien wrote:
(duh to myself )
It's been a hard day ??
|
|
|
|
|
ISUstudent wrote:
board[12][13] = 0;
numChips[7] = 0;
Remove this two lines: you are writing a zero outside the arrays (numChips[6] is the last cell of your array because it is zero indexed).
Otherwise it is correct.
|
|
|
|
|
And, does it work? Looks good so far. You may also want to use memset.
memset( board, 0, sizeof( board ) );
Hardy.
|
|
|
|
|
Instead of the for loops, you could simply call memset() . Other than that, what you have so far is okay.
"When I was born I was so surprised that I didn't talk for a year and a half." - Gracie Allen
|
|
|
|
|
sweet. i just didn't know if i could have for loops and such in my defalut constructor
|
|
|
|
|
I have a Linked list with the following functions:
Add, Get, Delete.
For thread safe implementation I use a CRITICAL_SECTION handle in each function and everything work well.
The question is:
How I can avoid use of CRITICAL_SECTION on Get function?
Because Get function is called on many threads the performance is low, each thread wait the previous thread to finish Get.
Add and Delete are called rarely.
Thanks!
|
|
|
|
|
yes you can
I've already thought about this problem, too, and I found a very fast solution.
Lock the list by using interlocked functions, which use a LONG member variable of the class (I assume you use a list class) to synchronize access.
Don't try it, just do it!
|
|
|
|
|
I have used 2 interlocked vars and a semaphore. Below is a schematic of the code.
In this case the Get Thread has a very high access on the resource at 2 - 3 mil. of gets/sec
towards 20 - 50 of add and del /sec
If you have a better idea please tell me.
Thank you.
Get()
{
InterlockedIncrement(&_read);
while(_write > 0) Sleep(0);
CList::Get();
InterlockedDecrement(&_read);
}
Add()
{
while(_read > 0) Sleep(0);
InterlockedIncrement(&_write);
WaitForSingleObject(_sem,INFINITE);
CList::Add();
ReleaseSemaphore(_sem,1,NULL);
InterlockedDecrement(&_write);
}
Delete()
{
while(_read > 0) Sleep(0);
InterlockedIncrement(&_write);
WaitForSingleObject(_sem,INFINITE);
CList::Add();
ReleaseSemaphore(_sem,1,NULL);
InterlockedDecrement(&_write);
}
|
|
|
|
|
You can safely eliminate the CRITICAL_SECTION in your Get function if you make sure that your program is playing by the rules: as many threads can have read-only access to the list as long as none of them does an insertion or deletion. This usually involves some other synchronization mechanisms, although at a higher level than on the linked list itself, which presumably will yield better performance.
If you cannot guarantee this behavior in your program, another possibility is to protect access by means of a read/write lock. Such a lock allows multiple threads to enter for read access, except if some thread has reclaimed write access. A web search gives the following article[^] by Ivan Krivyakov on implementing read/write locks in Windows.
Joaquín M López Muñoz
Telefónica, Investigación y Desarrollo
|
|
|
|
|
Hi.
A fast way to ensure synchronised access and update, is to use a simple 'mutex' that all three access/update methods conform to, ( as long as it is not a multi processor platform ).
If you do not care about the specific order in which access and/or update is performed, ie) its a free for all, then a simple WaitForSingleObject() on the mutex should provide a simple and fast mechanism.
James.
|
|
|
|