不让一个程序启动两次(变量不要与其他程序使用一样):
//创建互斥量
HANDLE hMutexWF = CreateMutex(NULL, FALSE, "WFBsNavRunOnlyOneInstance");
if (hMutexWF == NULL || ERROR_ALREADY_EXISTS == ::GetLastError())//限制双启动
{
if (hMutexWF != NULL)
{
CloseHandle(hMutexWF);
}
return false;
}
c++builder 禁止拉伸:
将Form的属性BorderStyle设成bsSingle或者bsDialog就可以了
//屏蔽WebBrowser右击
Application-> OnMessage=AEMessage;
Form释放:
~Form()
{
Form2 = NULL;
delete Form2;//释放内存
}
或重写close()
void __fastcall TForm2::FormClose(TObject *Sender, TCloseAction &Action)
{
Action = caFree; //new出来当然直接用delete来KO
}
桌面快捷方式建立:
//头文件
#include <registry.hpp>
//使用
CreateLnk(Application->ExeName , "名字");
//方法
//----------------------------------------------------------------------
void __fastcall TForm2::CreateLnk(String FilePath, String FileName) {
LPMALLOC ShellMalloc;
LPITEMIDLIST DesktopPidl;
char DesktopDir[MAX_PATH];
if (FAILED(SHGetMalloc(&ShellMalloc))) {
return;
}
if (FAILED(SHGetSpecialFolderLocation(NULL, CSIDL_DESKTOPDIRECTORY, &DesktopPidl))) {
return;
}
if(!SHGetPathFromIDList(DesktopPidl, DesktopDir)) {
ShellMalloc->Free(DesktopPidl);
ShellMalloc->Release();
return;
}
ShellMalloc->Free(DesktopPidl);
ShellMalloc->Release();
IShellLink* pLink;
IPersistFile* pPersistFile;
if (SUCCEEDED(CoInitialize(NULL))) {
if (SUCCEEDED(CoCreateInstance(CLSID_ShellLink, NULL, CLSCTX_INPROC_SERVER,
IID_IShellLink, (void **) &pLink))) {
pLink->SetPath(FilePath.c_str() );
if (SUCCEEDED(pLink->QueryInterface(IID_IPersistFile, (void **)&pPersistFile))) {
WideString strShortCutLocation = DesktopDir;
strShortCutLocation += "\\"+FileName+".lnk";
pPersistFile->Save(strShortCutLocation.c_bstr() , 0);
pPersistFile->Release();
}
pLink->Release();
}
CoUninitialize();
}
}