 |
|
This is my "how to" area for questions about c++. Hope it helps!
If you don't want to show any TForm when launching your Borland project...
in your constructor or formcreate() do the folowing:
Application->ShowMainForm=false;
Borland C++: using dynamic RTL or not?
If you are using dynamic RTL you need to ship Borlands memory dll's with your application.
The static RTL is built within your exe file.
Be aware that you cannot use static RTL when you are using dll's in your project which are accessing variables from another part of your project (e.g. the main exe) or the other way around, and so on, because the memory manager doesn't know everything about the variables (every dll/exe has its own memory manager then, accessing foreign variables, that's why they don't know)!
Calling a function "dynamically"
void (*myfunction)(int myparameter);
...
void thisisfunction1(int p)
{
... do something with p :-)
}
void thisisfunction2(int p)
{
... do something else
}
...
myfunction=thisisfunction1;
//now you can call myfunction!
myfunction(i);
...
How to get version information of a specific exe file (e.g. from the application itself)?
string GetFileVersion(string exeName)
{
char *ExeName =(char *) malloc(exeName.size());
strncpy(ExeName,exeName.c_str(),exeName.size());
DWORD n = GetFileVersionInfoSize(ExeName,&n);
if (n > 0)
{
char *pBuf = (char *) malloc(n);
GetFileVersionInfo(ExeName, 0, n, pBuf);
VS_FIXEDFILEINFO *pValue;
UINT Len;
if (!VerQueryValue(pBuf, "\\", (void**)&pValue, &Len))
{
free(pBuf);
free(ExeName);
return "";
}
string retVal=itos(HIWORD(pValue->dwProductVersionMS))+(string)"."+
itos(LOWORD(pValue->dwProductVersionMS))+(string)"."+
itos(HIWORD(pValue->dwProductVersionLS))+(string)"."+
itos(LOWORD(pValue->dwProductVersionLS));
free(pBuf);
free(ExeName);
return retVal;
}
free(ExeName);
return "";
}
How to get the path from a filename?
string GetPathFromFileName(string filename)
{
string::size_type pos=filename.find_last_of("\\");
if (pos!=string::npos)
{
filename.erase(pos);
return filename;
}
return "";
}
How to show a balloon/bubble at your tray icon?
NOTIFYICONDATA trayicon;
trayicon.cbSize = sizeof(NOTIFYICONDATA);
trayicon.hWnd = this->hwnd; // handle of your window, e.g. mainform->Handle;
trayicon.uID = 100; // id of your tray icon
trayicon.uFlags = NIF_INFO;
trayicon.uCallbackMessage = WM_TRAYNOTIFY; // user defined message id
trayicon.dwInfoFlags = NIIF_INFO;
trayicon.szInfoTitle="bold paint title of bubble";
trayicon.szInfo="this is the text.\nwrite anything"; // be aware that there is a limit of length
trayicon.uTimeout = 10000; // in milliseconds
Shell_NotifyIcon(NIM_MODIFY, &trayicon);
How to split a ::std::string like php does?
vector<string> split(string input, string seperator)
{
string::size_type pos1 = 0;
string::size_type pos2 = 0;
vector<string> result;
while ((pos2 = input.find(seperator, pos1)) != -1)
{
result.push_back(input.substr(pos1, (pos2-pos1)));
pos1 = pos2 + seperator.length();
}
result.push_back(input.substr(pos1, (input.length()-pos1)));
return result;
}
string sep=",";
string what="one,two,three,four";
vector<string> splitted = split(what,sep)
Borland doesn't let you change the application icon? Your Application only has the standard icon?
This seems to happen if you create a console application. Simply create a .res file with an icon in it (e.g. with XN Resource Editor) and add it to your project. Delete the one which already existed. Now the icon of your application should be the one in the .res file.
Be aware that windows might not always update the exe file icon on pressing F5.
You need to make your own version strings if you want them. When you change the project options it will recreate the old .res file. You have to remove it again.
|
|
|
 |
 |
|