不讓一個程序啟動兩次(變量不要與其他程序使用一樣):
//創建互斥量
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就可以了
桌面快捷方式建立:
//頭文件
#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();
}
}
摘自 破空的專欄