repeat a video in WMP in c++ - c++

I want a video to be repeated infinite number of times till i press enter key or anyother key stroke.
The event part can be handled easily. What im worried about is how to repeat or loop the video continuously.
A little research showed me that the IWMPSettings has a SetMode function which can be used in following manner to loop video
SetMode("loop",true); But however, this doesnt work as i think this function works only if u have playlist.
Is there no alternative to run a single video continuously without using PlayList? If not, how do i create playlist?

It's hard to say whether this is viable since the constraints of your problem aren't known, but it may be easier just input the corresponding keyboard shortcuts for whatever you want to do in wmp.
http://windows.microsoft.com/en-us/windows/media-player-keyboard-shortcuts

Related

I'm making a roguelike in visual c++ 2010, how can I speed up the print rate?

I'm trying to make a roguelike game in visual c++ 2010, which involves printing out a screen every time the player makes a move. Unfortunately, it uses 8000 characters, and so it takes a second or so to print them out every refresh. It might not seem like much, but given the number of moves involved in the game, it adds up.
I've tried unsyncing with stdio, compiling all the characters into a string and then printing the string with cout, and printing the characters with _putch();, but there was still a significant printing time for each method. I tried printing out an unchanging string repeatedly to test if it was something else causing the delay, but there was still a delay when the only task was printing.
My question is, is there anything I could try that could potentially speed up the process? A friend of mine suggested ncurses, would that be worth a try? If so, how would I do it, and if not, what else could I try?
I would agree with cornstalks. However if you are looking to make a pure console game I would suggest you take advantage of the built in ctime library. Learn from a library (such as SDL1.2) or a source on how to handle hard-coding time based events with entity systems. There are many efficient ways to store these characters and print them in a jiff. Or you can use SDL and make the game window seem like a console and handle everything as raster-graphics.

c++ ubuntu detecting real time keypress event

I'm writing a program that needs to respond towards a key press (say by printing "hello key press") in real time (the program runs in a giant loop that takes around 2 seconds to complete). I have found one potential answer Detecting keydown and keyup events on Linux C++ but the answers weren't very clear to me (I also looked into the 4 answer that are linked via duplicates). Can somebody please provide a simple code example of how to make a linux program respond towards a keypress by printing a single line (or doing whatever) without having to check for it each loop?
Take a look at SDL Input events. Simple DirectMedia Layer (SDL) provides a cross platform API developed for things like gaming. It does provide a lot of low level keyboard, mouse etc functionality. A link can be found here.
There are essentially to ways:
If the long loop is long in time, but short in code (that is: it contains another working inner loop that keeps all the time) you can place a event presence check in the most inner loop.
If you cannot rework the long loop, you have most likely to split the application in two distinct threads: one performing event detection and immediate actions, and another one to which to delegate the lengthy operations.

Async Console Output

I have a problem with my application win32 console.
The console is used to give commands to my application. However, at the same time it is used to output log messages which mostly comes from asynchronous threads. This becomes a problem when the user tries to write some input and simultaneously an async log message is printed, thus thrashing the display of the users input.
I would like to have some advice in regards to how to handle such a situtation?
Is it possible for example to dedicate the last line in the console to input, similarly to how it looks in the in-game consoles for some games?
You can use SetConsoleMode to disable input echo and line editing mode. You can then echo back input whenever your program is ready to do so. Note that this means you will need to implement things like backspace manually. And don't forget to reset the mode back when you're done with the console!
This is possible using the Console API, but it involves quite a bit of work and all the threads that use the console will have to cooperate by calling your output method rather than directly calling the Console API functions or the runtime library output functions.
The basic idea is to have your common output function write to the console screen buffer, and scroll the buffer in code rather than letting the text flow onto the last line and scroll automatically. As I recall, you'll have to parse the output for newlines and other control characters, and handle them correctly.
You might be able to get away with using "cooked" console input on the last line, although in doing so you risk problems if the user enters more text than will fit on a single line. Also, the user hitting Enter at the end of the line might cause it to scroll up. Probably best in this situation to use raw console input.
You'll want to become very familiar with Windows consoles.
Any time you have asyncronous threads trying to update the same device at once, you are going to have issues like this unless something synchronizes them.
If you have access to everyone's source code, the thing to do would probably be to create some kind of sync object that every task must use to access the console (semaphore, etc).

Why is my paintBox Canvas being erased when my program is "Not Responding"?

I have written a small program using Borland's C++ builder, and along the way, everything seemed fine. My program has a map window and a table window, and when a user presses a button, a long process is started that reads in all the map and table information and then displays that. Every time i ran it through the debugger, I had no issues. Then today, I decided to test it without running it through the debugger. To my horror, The program reads in the map information and then displays it on the paintbox canvas without a problem, but when it loads the information for the grid, the map gets erased!!! It appears to happen during the load phase for the table. this takes about 4 seconds, and during which time, the window tells me that it isnt responding. This is when the map gets erased. Anyone have any ideas on why this is happening? Its driving me nuts, and I dont really understand whats going on under the hood here.
UPDATE:
I have fixed the problem to some degree. I was poking around and found this: Avoiding "(Not Responding)" label in windows while processing lots of data in one lump
I added the code to run once in the middle of the data read in for the table. this fixed my problems. however, I was wondering if anyone knows why this is the case? why does my program going unresponsive cause my canvases to be erased?
Marcus Junglas wrote a detailed explanation of the problem, which affects both Delphi and C++Builder.
When programming an event handler in
Delphi (like the OnClick event of a
TButton), there comes the time when
your application needs to be busy for
a while, e.g. the code needs to write
a big file or compress some data.
If you do that you'll notice that your
application seems to be locked. Your
form cannot be moved anymore and the
buttons are showing no sign of life.
It seems to be crashed.
The reason is that a Delpi application
is single threaded. The code you are
writing represents just a bunch of
procedures which are called by
Delphi's main thread whenever an event
occured. The rest of the time the main
thread is handling system messages and
other things like form and component
handling functions.
So, if you don't finish your event
handling by doing some lengthy work,
you will prevent the application to
handle those messages.
You can reduce the problem by calling Application->ProcessMessages(), while loading your map data, however I recomend using a separate thread to load the data.
I have never used C++ Builder, but i used Delphi. I think the libraries are the same.
Does that component you use store the image data? It may only draw to the screen. Try covering the window of your app with another window. If it erases it, you have to use a component which stores the image.
See this, it is for Delphi, but it may help. There should be a Image component in C++ Builder. Try using that instead of PaintBox.
You can solve the unresponsivenes problem by running the time consuming task in a separate thread or calling some function that processes the window's messages.

How to make windows media player go to previous song in playlist?

I am writing a simple Windows app in c++, that will be able to send commands to windows media player. My problem is that I want my app to move to the previous song in the playlist.
IWMPControls::previous() seems to do the job, but its behavior differs from what is written in msdn. In fact this function rewinds current media to the beginning and then (if current position is less than 2-3 seconds) it switches to the previous song.
I would like to implement two different buttons (please, don't ask me why :)) - one for rewinding to the beginning, and one - to moving to previous song. Is there any easy way to do this through IWMPControls (or any other WMP-related COM interface)?
p.s. I could handle this if I could get the position (index) of the current song in the list. But as far as I read MSDN, it seems to me that there is no easy way to get the current item index from playlist...
I think, the easiest way to control a WMP application from outside is by sending messages. So, you stick to basic WinAPI and you have to get your WMP window handle.
After you've retrieved it's handle, it's easy to transfer certain commands to it using plain Windows messages.
Basically, you just invoke SendMessage to retrieved earlier HWND wmp_windows_handle. The control messages are generally a WM_COMMAND messages where a wParam specifies what you want your player to do.
For example, Stop command can be transfered if you specify 0x00004979 as your wParam.
Stick to Google or Windows Media Player SDK for more specific information on these command codes and you'll definitely find what you are looking for.
Also to mention, I'm not proficient with that IWMPStuff you described above, so if I were you and I wanted a concrete answer about it, I would probably refer to it's SDK.
Well, I think I figured it out. You can force the previous song by 1) first calling IWMPControls::put_currentPosition(0.0), 2) then calling IWMPControls::previous().
There can be some problems, as it seems that some time must pass between 1) and 2). The obvious solution is to use ::PostMessage() inside your program (NOT ::PostMessage to WMP), so you make step 1), then PostMessage and, while processing your message, make step 2).