Skip to content

Commit

Permalink
Implemented File Selection for text
Browse files Browse the repository at this point in the history
  • Loading branch information
koosemose committed Oct 22, 2015
1 parent a162916 commit 1227797
Show file tree
Hide file tree
Showing 12 changed files with 86 additions and 16 deletions.
99 changes: 84 additions & 15 deletions Marquee Text/overlayMarqueeText.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
#include "resource.h"
#include<iostream>
#include<fstream>
#include <sys/stat.h>

#include <shobjidl.h>
// add your own path for PlayClaw5.lib
#ifdef _DEBUG
#pragma comment(lib, "../playclaw5.lib")
Expand All @@ -29,12 +29,14 @@ Gdiplus::Pen* pAxisPen = 0;
Gdiplus::Font* pFont = 0;

BOOL bShowBackground = true;
wchar_t wcTextContents[256];
wchar_t wcTextContents[256];

const WCHAR *pFileName = L"";

int cycleCount = 0;
int scroll = 0;
int textLength = 0;
time_t oldModifyTime;
FILETIME oldModifyTime;

//
// Init plugin
Expand Down Expand Up @@ -77,6 +79,8 @@ PLUGIN_EXPORT void PluginSetDefaultVars()
PC_SetPluginVar(m_dwPluginID, VAR_TEXT_FONT_SIZE, 24);
PC_SetPluginVar(m_dwPluginID, VAR_TEXT_FONT_STYLE, (int)0); // flags: 1 - bold, 2 - italic
PC_SetPluginVar(m_dwPluginID, VAR_SHOW_BACKGROUND, 1);
PC_SetPluginVar(m_dwPluginID, VAR_TEXT_FILE, L"");

}

//
Expand All @@ -103,15 +107,17 @@ PLUGIN_EXPORT void PluginUpdateVars()
(float)PC_GetPluginVarInt(m_dwPluginID, VAR_TEXT_FONT_SIZE),
PC_GetPluginVarInt(m_dwPluginID, VAR_TEXT_FONT_STYLE));

//SAFE_DELETE(pFileName);
pFileName = PC_GetPluginVarStr(m_dwPluginID, VAR_TEXT_FILE);

struct stat attrib;
stat("C:/Users/Koosemose/Desktop/Snip/Snip.txt", &attrib);
time_t modifyTime = attrib.st_mtime;

WIN32_FILE_ATTRIBUTE_DATA attribs;
GetFileAttributesExW(pFileName, GetFileExInfoStandard, &attribs);

FILETIME modifyTime = attribs.ftLastWriteTime;
oldModifyTime = modifyTime;
string line;
ifstream myfile;
myfile.open("C:/Users/Koosemose/Desktop/Snip/Snip.txt");
myfile.open(pFileName);
string textContents = "";
if (myfile.is_open())
{
Expand Down Expand Up @@ -178,14 +184,16 @@ PLUGIN_EXPORT void PluginUpdateOverlay()

WCHAR s[128];
_itow_s(PC_GetConfirmedProcessID(), s, 10);
struct stat attrib;
stat("C:/Users/Koosemose/Desktop/Snip/Snip.txt", &attrib);
time_t modifyTime = attrib.st_mtime;
if (modifyTime > oldModifyTime) {

WIN32_FILE_ATTRIBUTE_DATA attribs;
GetFileAttributesExW(pFileName, GetFileExInfoStandard, &attribs);

FILETIME modifyTime = attribs.ftLastWriteTime;
if (CompareFileTime(&modifyTime, &oldModifyTime) >0) {
oldModifyTime = modifyTime;
string line;
ifstream myfile;
myfile.open("C:/Users/Koosemose/Desktop/Snip/Snip.txt");
myfile.open(pFileName);
string textContents = "";
if (myfile.is_open())
{
Expand Down Expand Up @@ -237,6 +245,7 @@ DWORD dwTextColor, dwBackgroundColor;
BOOL bItalic, bBold;
wstring szFontFamily;
DWORD dwFontSize;
wstring szFileName;

static void SetFontButtonText(HWND dlg)
{
Expand All @@ -250,6 +259,14 @@ static void SetFontButtonText(HWND dlg)
SetWindowText(GetDlgItem(dlg, IDC_TEXT_FONT), fontstr);
}

static void SetFileNameButtonText(HWND dlg)
{
WCHAR filestr[128];
wsprintf(filestr, L"%s",
szFileName.c_str());
SetWindowText(GetDlgItem(dlg, IDC_TEXT_FILE), filestr);
}

static void InitSettingsDialog(HWND hwnd)
{
// HWND ctrl;
Expand All @@ -262,9 +279,10 @@ static void InitSettingsDialog(HWND hwnd)
bBold = (PC_GetPluginVarInt(m_dwPluginID, VAR_TEXT_FONT_STYLE) & 1) != 0;
szFontFamily = PC_GetPluginVarStr(m_dwPluginID, VAR_TEXT_FONT_FAMILY);
dwFontSize = PC_GetPluginVarInt(m_dwPluginID, VAR_TEXT_FONT_SIZE);

szFileName = PC_GetPluginVarStr(m_dwPluginID, VAR_TEXT_FILE);
Button_SetCheck(GetDlgItem(hwnd, IDC_SHOW_BACKGROUND), PC_GetPluginVarInt(m_dwPluginID, VAR_SHOW_BACKGROUND) != 0 ? BST_CHECKED : BST_UNCHECKED);
SetFontButtonText(hwnd);
SetFileNameButtonText(hwnd);
}

static void DrawColorButton(LPDRAWITEMSTRUCT lpDIS, COLORREF clr)
Expand Down Expand Up @@ -297,8 +315,9 @@ static INT_PTR CALLBACK DlgProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lPar
{
PC_SetPluginVar(m_dwPluginID, VAR_TEXT_COLOR, dwTextColor);
PC_SetPluginVar(m_dwPluginID, VAR_BACKGROUND_COLOR, dwBackgroundColor);

PC_SetPluginVar(m_dwPluginID, VAR_TEXT_FILE, szFileName.c_str());
PC_SetPluginVar(m_dwPluginID, VAR_TEXT_FONT_FAMILY, szFontFamily.c_str());
PC_SetPluginVar(m_dwPluginID, VAR_TEXT_FILE, szFileName.c_str());
PC_SetPluginVar(m_dwPluginID, VAR_TEXT_FONT_SIZE, dwFontSize);
PC_SetPluginVar(m_dwPluginID, VAR_SHOW_BACKGROUND, Button_GetCheck(GetDlgItem(hwnd, IDC_SHOW_BACKGROUND)) == BST_CHECKED);
int style = (bBold ? 1 : 0) | (bItalic ? 2 : 0);
Expand Down Expand Up @@ -350,6 +369,56 @@ static INT_PTR CALLBACK DlgProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lPar
}
ReleaseDC(hwnd, dc);

}
if (id == IDC_TEXT_FILE) {
HRESULT hr = CoInitializeEx(NULL, COINIT_APARTMENTTHREADED |
COINIT_DISABLE_OLE1DDE);
if (SUCCEEDED(hr))
{
IFileOpenDialog *pFileOpen;
COMDLG_FILTERSPEC rgSpec[] =
{
{ L"Text Files", L"*.txt" },
{ L"All Files", L"*.*" },
};
// Create the FileOpenDialog object.
hr = CoCreateInstance(CLSID_FileOpenDialog, NULL, CLSCTX_ALL,
IID_IFileOpenDialog, reinterpret_cast<void**>(&pFileOpen));

if (SUCCEEDED(hr))
{
// Show the Open dialog box.
pFileOpen->SetFileTypes(2,rgSpec);

hr = pFileOpen->Show(NULL);

// Get the file name from the dialog box.
if (SUCCEEDED(hr))
{
IShellItem *pItem;
hr = pFileOpen->GetResult(&pItem);
if (SUCCEEDED(hr))
{
PWSTR pszFilePath;
hr = pItem->GetDisplayName(SIGDN_FILESYSPATH, &pszFilePath);

// Display the file name to the user.
if (SUCCEEDED(hr))
{
//MessageBox(NULL, pszFilePath, L"File Path", MB_OK);
//szFileName = L"CATS";
szFileName = pszFilePath;
SetFileNameButtonText(hwnd);
CoTaskMemFree(pszFilePath);
}
pItem->Release();
}
}
pFileOpen->Release();
}
CoUninitialize();
}

}

break;
Expand Down
3 changes: 2 additions & 1 deletion Marquee Text/overlayMarqueeText.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,5 @@
#define VAR_TEXT_FONT_FAMILY "text_font.family"
#define VAR_TEXT_FONT_SIZE "text_font.size"
#define VAR_TEXT_FONT_STYLE "text_font.style"
#define VAR_SHOW_BACKGROUND "show_background"
#define VAR_SHOW_BACKGROUND "show_background"
#define VAR_TEXT_FILE "text_file"
Binary file modified Marquee Text/overlayMarqueeText.rc
Binary file not shown.
Binary file modified Marquee Text/resource.h
Binary file not shown.
Binary file modified lang/English.txt
Binary file not shown.
Binary file modified lang/Français.txt
Binary file not shown.
Binary file modified lang/Magyar.txt
Binary file not shown.
Binary file modified lang/Polski.txt
Binary file not shown.
Binary file modified lang/Português (Brasil).txt
Binary file not shown.
Binary file modified lang/Suomi.txt
Binary file not shown.
Binary file modified lang/Русский.txt
Binary file not shown.
Binary file modified lang/日本語.txt
Binary file not shown.

0 comments on commit 1227797

Please sign in to comment.