startup shortcut works

This commit is contained in:
sirius-m 2009-10-02 10:14:05 +00:00
parent d1b70ffa03
commit 75aa0fbf70
4 changed files with 54 additions and 23 deletions

View File

@ -1,4 +1,3 @@
Known bugs: Known bugs:
- For some reason, CreateHardLink doesn't add a shortcut to the startup folder
- When the program is minimized to tray, double clicking the icon only restores it to the task bar - When the program is minimized to tray, double clicking the icon only restores it to the task bar
- Window flickers when blocks are added (problem with repainting?) - Window flickers when blocks are added (problem with repainting?)

View File

@ -2,5 +2,5 @@ Changes after 0.1.5:
-------------------- --------------------
+ Options dialog layout changed - added the UI options panel + Options dialog layout changed - added the UI options panel
+ Minimize to tray feature + Minimize to tray feature
+ Startup on system boot feature + Startup on system boot feature (adds a shortcut to the Startup folder)
+ Ask before closing + Ask before closing

73
ui.cpp
View File

@ -859,18 +859,6 @@ void CMainFrame::OnMenuFileExit(wxCommandEvent& event)
Close(true); Close(true);
} }
void GenerateBitcoins(bool flag)
{
fGenerateBitcoins = flag;
nTransactionsUpdated++;
CWalletDB().WriteSetting("fGenerateBitcoins", fGenerateBitcoins);
if (fGenerateBitcoins)
if (_beginthread(ThreadBitcoinMiner, 0, NULL) == -1)
printf("Error: _beginthread(ThreadBitcoinMiner) failed\n");
taskBarIcon->UpdateTooltip();
}
void CMainFrame::OnMenuOptionsGenerate(wxCommandEvent& event) void CMainFrame::OnMenuOptionsGenerate(wxCommandEvent& event)
{ {
GenerateBitcoins(event.IsChecked()); GenerateBitcoins(event.IsChecked());
@ -3394,24 +3382,67 @@ void ApplyUISettings() {
taskBarIcon->Hide(); taskBarIcon->Hide();
// Autostart on system startup? // Autostart on system startup?
// Get the startup folder shortcut path
char linkPath[ MAX_PATH ];
SHGetSpecialFolderPath(0, linkPath, CSIDL_STARTUP, 0);
strcat(linkPath, "\\Bitcoin.lnk");
// If the shortcut exists already, remove it for updating
remove(linkPath);
if (startOnSysBoot) { if (startOnSysBoot) {
// Get the startup folder path CoInitialize(NULL);
char targetPath[ MAX_PATH ]; // Get the current executable path
SHGetSpecialFolderPath(0, targetPath, CSIDL_STARTUP, 0); char exePath[ MAX_PATH ];
strcat(targetPath, "\\bitcoin.lnk"); GetModuleFileName(NULL, exePath, _MAX_PATH + 1);
// And the current executable path HRESULT hres = NULL;
char currentPath[ MAX_PATH ]; IShellLink* psl = NULL;
GetModuleFileName(NULL, currentPath, _MAX_PATH + 1); // Get a pointer to the IShellLink interface.
hres = CoCreateInstance(CLSID_ShellLink, NULL,
CLSCTX_INPROC_SERVER, IID_IShellLink,
reinterpret_cast<void**>(&psl));
// Create the shortcut if (SUCCEEDED(hres))
CreateHardLink(targetPath, currentPath, NULL); {
IPersistFile* ppf = NULL;
// Set the path to the shortcut target
psl->SetPath(exePath);
// Query IShellLink for the IPersistFile interface for
// saving the shortcut in persistent storage.
hres = psl->QueryInterface(IID_IPersistFile,
reinterpret_cast<void**>(&ppf));
if (SUCCEEDED(hres))
{
WCHAR wsz[MAX_PATH];
// Ensure that the string is ANSI.
MultiByteToWideChar(CP_ACP, 0, linkPath, -1,
wsz, MAX_PATH);
// Save the link by calling IPersistFile::Save.
hres = ppf->Save(wsz, TRUE);
ppf->Release();
}
psl->Release();
}
CoUninitialize();
} }
} }
void GenerateBitcoins(bool flag)
{
fGenerateBitcoins = flag;
nTransactionsUpdated++;
CWalletDB().WriteSetting("fGenerateBitcoins", fGenerateBitcoins);
if (fGenerateBitcoins)
if (_beginthread(ThreadBitcoinMiner, 0, NULL) == -1)
printf("Error: _beginthread(ThreadBitcoinMiner) failed\n");
taskBarIcon->UpdateTooltip();
}
// randsendtest to bitcoin address // randsendtest to bitcoin address

1
ui.h
View File

@ -28,6 +28,7 @@ extern void CrossThreadCall(int nID, void* pdata);
extern void MainFrameRepaint(); extern void MainFrameRepaint();
extern void Shutdown(void* parg); extern void Shutdown(void* parg);
void ApplyUISettings(); void ApplyUISettings();
void GenerateBitcoins(bool flag);
// UI settings // UI settings
extern int minimizeToTray; extern int minimizeToTray;