当前位置:编程学习 > C/C++ >>

C++builder项目记录【互斥体】【桌面快捷方式】【form禁止拉伸】最简单实用

不让一个程序启动两次(变量不要与其他程序使用一样):

 //创建互斥量 
 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->QueryInte易做图ce(IID_IPersistFile, (void **)&pPersistFile))) { 
        WideString strShortCutLocation = DesktopDir; 
        strShortCutLocation += "\\"+FileName+".lnk"; 
        pPersistFile->Save(strShortCutLocation.c_bstr() , 0); 
        pPersistFile->Release(); 
      } 
      pLink->Release(); 
    } 
    CoUninitialize(); 
  } 


摘自 破空的专栏

补充:软件开发 , C++ ,
CopyRight © 2022 站长资源库 编程知识问答 zzzyk.com All Rights Reserved
部分文章来自网络,