Create a TAnimate in Borland 2006 - c++

I have the following problem. I am using the Borland 2006 Compiler and I am trying to include an animation in my applicaton. First I added the TAnimate Object and then in the ObjectInspector under "FileName", every time I try to add an .avi, the Compiler says "AVI cannot be opened". Am I doing something wrong or isn't it that simple to just put a .gif or .avi into that Objectproperty?
Edit // Here ist Some CodeExample, everytime i press the button, it throws an exception and tells me that the avi File cannot be opened
void __fastcall THauptmenue_Login::Button1Click(TObject *Sender)
{
Animate1->FileName = ("C:\\Users\\Kevin\\Desktop\\C++ Gifs");
}

The FileName you showed doesn't look complete. It looks more like a path to a folder instead of a file.
In the Object Inspector, beside the FileName text box is a [...] button which brings up a file browser dialog which can add a full path and name to a file.
addendum:
If you are using the Object Inspector to pick a filename from the disk you do not need to specify a FileName property value in the code.
This overwrites any previous FileName property value.
Animate1->FileName = "C:\\Users\\Kevin\\Desktop\\C++ Gifs";

Related

wxWidgets include image during compile time

I've been trying to make a simple wxWidgets program with just a button with a picture on it. I've been able to make the button with the image on it easily enough, but my problem arises when including it.
So far, I've only been able to fetch the image during run-time (the image has to be in the same folder as the .exe file; otherwise, I get error 2: the system cannot find the file specified). With this method, I have no problems -- the program works just fine. What I'm trying to do, however, is to #include the file so that it is embedded during compile-time, so that it doesn't need to be available during run-time.
I've tried #including the file (both as .png and as .xpm), and I've also tried adding it to the resource includes (this is on Visual Studio 2017). Neither of these worked -- the first method still required the image to be in the same folder, and the second failed during compilation (as far as I can tell, it wasn't able to read the .xpm file).
Here is the relevant code, if it helps:
/*relevant includes*/
#include "happyFace.png" //this isn't working. the file is still needed
||
#include "happyFace.xpm" //ditto
/*I have also tried putting these lines in the resource includes.*/
/*code*/
wxInitAllImageHandlers();
wxBitmap bitmap("happyFace.xpm", wxBITMAP_TYPE_XPM); //only works in same directory at run-time
||
wxBitmap bitmap("happyFace.png", wxBITMAP_TYPE_PNG); //ditto
wxButton *button = new wxButton(this, ID_BMP_BUTTON);
button->SetBitmap(bitmap);
//the rest of the button programming and stuff
Sorry if I haven't provided enough information; I can provide more if necessary. I would really appreciate any help. Thanks!
Two possibilities... Number 1 is simplest. It's been a long time since I wrote the code I'm looking at, so the details are fuzzy.
In Visual Studio, Solution Explorer, add the image into the resource files. Assume the name of the resourse is sample.rc. Then it can be used like so to set the main icon...
SetIcon(wxICON(sample));
Method 1 must be used in order for MS Windows Explorer to display the main icon. I do not remember how to use .rc resources for other things, but it should be easy to figure out.
I did it this way before I discovered VS resource (.rc) files. Compile the file-image into the program "by hand." In other words, write a program that will read an image file and produce bit-for-bit copy in a .cpp file. Then compile that .cpp into the program. Here I have the file-image in memory as an object named dj::main_cursor. Note that the in-memory version is a bit-for-bit copy of a .cur file.
dj::captured_file &c1file(dj::main_cursor);
wxMemoryInputStream cistr(c1file.contents, c1file.size);
cursor1 = wxCursor(wxImage(cistr, wxBITMAP_TYPE_CUR));
FYI, I defined the structure dj::captured_file like so:
struct captured_file {
const char *name;
const unsigned long size;
const void *contents;
captured_file(const char*fn, size_t sz, const void*c)
: name(fn)
, contents(c)
, size(sz)
{}
};
See also, Embedding PNG Images into Windows RC Files
I found some other documentation.
Resources and Application Icon All applications using wxMSW should
have a Windows resource file (.rc extension) and this file should
include include/wx/msw/wx.rc file which defines resources used by
wxWidgets itself.
Among other things, wx.rc defines some standard icons, all of which
have names starting with the "wx" prefix. This normally ensures that
any icons defined in the application's own resource file come before
them in alphabetical order which is important because Explorer
(Windows shell) selects the first icon in alphabetical order to use as
the application icon which is displayed when viewing its file in the
file manager. So if all the icons defined in your application start
with "x", "y" or "z", they won't be used by Explorer. To avoid this,
ensure that the icon which is meant to be used as the main application
icon has a name preceding "wxICON" in alphabetical order.
http://docs.wxwidgets.org/3.1.0/page_port.html
Here is how you should do it:
#include "happyFace.xpm"
wxBitmap bitmap = wxBitmap( happyFace ); // assuming the variable name is "happyFace" inside the xpm
Then you will use bitmap object just like usual. Assuming that the file happyFace.xpm is available for compilation.

QFile: directory not found

I need to write a console application that takes a file, it opens it, and then it calls another procedure based on the information inside the text file.
The only problem is that QFile::errorString() returns:
No such file or directory.
I have been using this implementation in all the programs I had to, and yes, the file exists at that directory.
The code is:
QFile fileName("D:/file.txt");
QString read_from_file;
if(fileName.open(QIODevice::ReadOnly)){
QTextStream in(&fileName);
while(!in.atEnd())
{
read_from_file = in.readLine();
qDebug()<<read_from_file;
}
fileName.close();
}
qDebug()<<fileName.errorString();
Make sure that the file really exists.
QFile::exists("D:/file.txt") – This will return true if the file exists.
QDir("D:/").entryList() – This will return the list of the files and directories located at the specified path; the needed file should be in the list.
As you pointed out in the comments, the problem was the hidden file extensions on Windows.
Open Folder Options by clicking the Start button, clicking Control Panel, clicking Appearance and
Personalization, and then clicking Folder Options.
Click the View tab, and then Advanced settings <...>
To show file name extensions, clear the Hide extensions for known file
types check box, and then click OK.

Displaying a PDF file inside a form using visual c++

I'm using visual c++ and i am totally new on it.
I have a form with a button, how when i click on it the file will open in new form?.
I tried to find a solution around but in vain.
First you need to add Adobe Reader COM component to your Toolbox.
Than drag it (like a simple button )into your "Form2" and name it AdRead for example.
In your first Form insert this code to your button so you can open "Form2"
Form2 ^ anyname = gcnew Form2();
anyname->Show();
this->Hide();
And put this code into AdRead
String^ Path ="here put the path of your specific file";
AdRead->src=Path;
Your path should be like "c:\\folder\\folder\\File.pdf"

Qt remembering the last open folder

I am using QFileDialog::openfilename for taking a file from user as input and I have specified the default folder which is to be shown when user open dialog.
But qt is somehow remembering the last open folder when filedialog is opened multiple times. But I want the default folder to be the the initial folder shown to the user not the last opened folder. In this, I am doing nothing explicitly to store the last opened information anywhere.
Please tell me what is the problem here and how to fix this.
It is clearly documented here. The third parameter to getOpenFileName is dir.
The file dialog's working directory will be set to dir. If dir includes a file name, the file will be selected.
Use this. setDirectory(str); install default path and you never get the last opened directory.
void MainWindow::on_pushButton_clicked()
{
QFileDialog dia;
dia.setDirectory("D:/");//or another default folder
QString path1 = dia.getOpenFileName(this,"Choose file");
}
Try Qsettings with rewritting them down, you'll need a initialize with param path
void camera_index::writesetting_window() {
//camera_index page
QSettings settings("Moose Soft", "Clipper");
settings.setValue("set_FOCUS", ui->camera_focus->value());
}
void camera_index::readsetting_window() {
QSettings settings("Moose Soft", "Clipper");
int FOCUS = settings.value("set_FOCUS").toInt();}
basically just set a fix value would help

Programmatically selecting file in explorer

In my application I can programmatically open explorer and select a file using the following code:
void BrowseToFile(LPCTSTR filename)
{
CString strArgs;
strArgs = _T("/select,\"");
strArgs += filename;
strArgs += _T("\"");
ShellExecute(0, _T("open"), _T("explorer.exe"), strArgs, 0, SW_NORMAL);
}
My problem is that if I call this function a second time with a different file, but in the same folder, the selection in explorer does not change to the new file, but remains on the previous file.
For example, if I call my function with C:\path\to\file1.txt, a new explorer window will open and file1.txt will be selected. If I call my function a second time with C:\path\to\file2.txt, the existing explorer window will be activated, but the selection will still be on file1.txt.
Is there a way to force explorer to update the selection or a better way to accomplish this?
EDIT:
The behavior mentioned above was on Windows XP. It seems the behavior on Vista / Win7 is different. Each call will open a new instance of explorer and select the file.
My main goal is to replicate the Visual Studio option to Open Containing Folder of a document. This feature in Visual Studio behaves the same on XP, Vista, and Win7. It will not create a new instance if another instance with the same folder is already open, but it will update the selection to the new file.
If anybody knows how Visual Studio accomplishes this I would love to know about it.
Found the answer to my question. I need to use the shell function SHOpenFolderAndSelectItems. Here is the code for the function if anybody is ever interested:
void BrowseToFile(LPCTSTR filename)
{
ITEMIDLIST *pidl = ILCreateFromPath(filename);
if(pidl) {
SHOpenFolderAndSelectItems(pidl,0,0,0);
ILFree(pidl);
}
}
Try the '/n' option. This will, however, open a new folder - perhaps already opened. But, at least, the file you specify is selected.
/n,/select,<path_and_filename>
SHOpenFolderAndSelectItems always fails in my case and I can't figure out why. Btw, you must call CoInitialize/CoInitializeEx before calling this one.
In the case you outlined it appears the file window only selects the file when it's initialized instead of when activated.
Although this feels like a kludge, you could detect XP and only for that OS close the dialog using its handle and open a new one to target another file with.