Example #1
0
LRESULT WINAPI CustomItemOptionsDlgProc(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam)
{
    switch (message) {
		case WM_INITDIALOG:
			{
				SHINITDLGINFO shidi;

				shidi.dwMask = SHIDIM_FLAGS;
				shidi.dwFlags = SHIDIF_DONEBUTTON | SHIDIF_SIPDOWN | SHIDIF_SIZEDLGFULLSCREEN;
				shidi.hDlg = hDlg;
				SHInitDialog(&shidi);

				LoadSettings();
				
				SendMessage(GetDlgItem(hDlg, IDC_LEFT_FORMAT), WM_SETTEXT, NULL, (LPARAM) g_xsLeftFormat.GetBuffer());
				SendMessage(GetDlgItem(hDlg, IDC_RIGHT_FORMAT), WM_SETTEXT, NULL, (LPARAM) g_xsRightFormat.GetBuffer());

				HWND hWndTextSize = GetDlgItem(hDlg, IDC_TEXT_SIZE);

				InitializeComboBox(hWndTextSize);
				SendMessage(hWndTextSize, CB_ADDSTRING, NULL, (LPARAM) _T("System Default"));

				for (int i = MIN_FONT_SIZE; i <= MAX_FONT_SIZE; i++)
				{
					TCHAR szNumber[1];
					
					_itot(i, szNumber, 10);
					
					SendMessage(hWndTextSize, CB_ADDSTRING, NULL, (LPARAM) szNumber);
					//SendMessage(hWndTextSize, CB_ADDSTRING, NULL, (LPARAM) szNumber);
				}
				SendMessage(hWndTextSize, CB_SETCURSEL, (WPARAM) g_iTextSize, NULL);
			}
			return TRUE; 
	        
		case WM_COMMAND:
			if (LOWORD(wParam) == IDOK) {
				TCHAR szBuffer[MAX_LOADSTRING];

				SendMessage(GetDlgItem(hDlg, IDC_LEFT_FORMAT), WM_GETTEXT, (WPARAM) MAX_LOADSTRING, (LPARAM) szBuffer);
				g_xsLeftFormat = szBuffer;

				SendMessage(GetDlgItem(hDlg, IDC_RIGHT_FORMAT), WM_GETTEXT, (WPARAM) MAX_LOADSTRING, (LPARAM) szBuffer);
				g_xsRightFormat = szBuffer;

				g_iTextSize = SendMessage(GetDlgItem(hDlg, IDC_TEXT_SIZE), CB_GETCURSEL, NULL, NULL);

				SaveSettings();

				EndDialog(hDlg, LOWORD(wParam));

				return TRUE;
			}
			return FALSE;
	}

    return FALSE;
}
/* load a file */
BOOL MyAppWindow :: LoadFile ( char * p)
{
   // is there already a file loaded or has the user entered some text?
   if(loaded == FALSE && saved == TRUE)
      {
         //no, we load the file in the window of the current thread
         XFile loadfile;

         /* now open the file, fail if given filename is not existing */
         /* open the file for read-access, dont allow any other programm to use the file while it is open*/
         if( loadfile.Open( p, XFILE_FAIL_IF_NEW | XFILE_OPEN_EXISTING, XFILE_SHARE_DENYWRITE | XFILE_READONLY ) == 0)
           {
              XString s;

              loading = TRUE;

              //how large is the file?
              XFileInfo info;
              loadfile.GetFileInfo( &info );
              LONG size = info.GetFileSize();

              //read the complete file
              loadfile.Read ( (PVOID) s.GetBuffer(info.GetFileSize() + 1), size);
              s.ReleaseBuffer( info.GetFileSize() );

              //set the XString content to the mle
              mle->SetText( s );
              //dontïforget to close the file
              loadfile.Close();
              loaded = TRUE;
              path = p;
              mle->SetFocus();
              GetText( &s );
              s+= " - ";
              s+= p;
              SetText( s );

              loading = FALSE;

              return TRUE;
            }
         else
            {
               XMessageBox( p, "couldnït open File!", MB_OK|MB_ERROR);
               return FALSE;
            }
      }
   else
     {
         //there is a file loaded, or the user has entered some text, so
         // we create a new window and load the file
//         XResource res( IDM_MAIN, ((MyApp*) GetProcess())->GetResourceLibrary());
         MyAppWindow * win = new MyAppWindow( IDM_MAIN );
         win->LoadFile(p);
         return TRUE;
     }
}
Example #3
0
void SaveSettings() {
	HKEY hKey;
	TCHAR szRegistryKey[MAX_LOADSTRING], szTextSizeKey[MAX_LOADSTRING];
	TCHAR szLeftFormatKey[MAX_LOADSTRING], szRightFormatKey[MAX_LOADSTRING];

	LoadString(g_hInstance, IDS_REGISTRY, szRegistryKey, MAX_LOADSTRING);
	LoadString(g_hInstance, IDS_LEFTFORMAT, szLeftFormatKey, MAX_LOADSTRING);
	LoadString(g_hInstance, IDS_RIGHTFORMAT, szRightFormatKey, MAX_LOADSTRING);
	LoadString(g_hInstance, IDS_TEXTSIZE, szTextSizeKey, MAX_LOADSTRING);

	if (RegOpenKeyEx(HKEY_LOCAL_MACHINE, szRegistryKey, 0, 0, &hKey) == ERROR_SUCCESS) {
		RegSetValueEx(hKey, szLeftFormatKey, 0, REG_SZ, (BYTE *) g_xsLeftFormat.GetBuffer(), g_xsLeftFormat.Length() * sizeof(TCHAR));
		RegSetValueEx(hKey, szRightFormatKey, 0, REG_SZ, (BYTE *) g_xsRightFormat.GetBuffer(), g_xsRightFormat.Length() * sizeof(TCHAR));
		RegSetValueEx(hKey, szTextSizeKey, 0, REG_DWORD, (BYTE *) &g_iTextSize, sizeof(int));

		RegCloseKey (hKey);
	}
}
Example #4
0
void GetBuffer()
{
	XString str = L"Hello";
	wchar_t* p = str.GetBuffer(20);
	wcscpy_s(p, 20, L"Hello World");
	str.ReleseBuffer();
	str += L"!";

	wprintf(L"%s\n", str.GetString());
}
Example #5
0
void PaintMe(HWND hwnd)
{
	HDC hDC;
	PAINTSTRUCT ps;
	RECT rcWindow;
	HFONT hSysFont, hFont, hFontOld;
	LOGFONT lfFont;
	COLORREF crText;
	TCHAR szTextBuffer[50], szTextBuffer2[50], szInternetTime[5];
	XString xsTextBuffer;
	int iFontSizePixel;
	
	GetWindowRect(hwnd, &rcWindow);
	OffsetRect(&rcWindow, -rcWindow.left, -rcWindow.top);

	hDC = BeginPaint(hwnd, &ps);
	SetBkMode(hDC, TRANSPARENT);

	if (bSelected == TRUE) {
		HBRUSH hBrush = GetSysColorBrush(COLOR_HIGHLIGHT);

		FillRect(hDC, &rcWindow, hBrush);

		DeleteObject(hBrush);
	}

	if (g_iTextSize == 0)
	{
		SHGetUIMetrics(SHUIM_FONTSIZE_PIXEL, &iFontSizePixel, sizeof(iFontSizePixel), NULL);
	}
	else
	{
		iFontSizePixel = MulDiv(g_iTextSize + MIN_FONT_SIZE - 1, DRA::LogPixelsY(), 72);
	}

	hSysFont = (HFONT) GetStockObject(SYSTEM_FONT);
	GetObject(hSysFont, sizeof(LOGFONT), &lfFont);
	//memset(&lfFont, 0, sizeof(LOGFONT));
	lfFont.lfWeight = FW_SEMIBOLD;
	lfFont.lfHeight = -iFontSizePixel;
	hFont = CreateFontIndirect(&lfFont);
	hFontOld = (HFONT) SelectObject(hDC, hFont);

	crText = SendMessage(GetParent(hwnd), TODAYM_GETCOLOR, (WPARAM) TODAYCOLOR_TEXT, NULL);
	SetTextColor(hDC, crText);

	InflateRect(&rcWindow, -2, 0);

	_itot(g_iInternetTime, szInternetTime, 10);
	//_ttoi

	_tcscpy(szTextBuffer, _T("a\0"));
	GetTimeFormat(LOCALE_SYSTEM_DEFAULT, 0, &g_stLocalTime, g_xsLeftFormat.Replace(_T("'"), _T("'''")).GetBuffer(), szTextBuffer, sizeof szTextBuffer);
	GetDateFormat(LOCALE_SYSTEM_DEFAULT, 0, &g_stLocalTime, szTextBuffer, szTextBuffer2, sizeof szTextBuffer2);
	xsTextBuffer = XString(szTextBuffer2).Replace(_T("@"), XString(_T("@"), szInternetTime));
	DrawText(hDC, xsTextBuffer.GetBuffer(), -1, &rcWindow, DT_VCENTER | DT_LEFT);

	_tcscpy(szTextBuffer, _T("a\0"));
	GetTimeFormat(LOCALE_SYSTEM_DEFAULT, 0, &g_stLocalTime, g_xsRightFormat.Replace(_T("'"), _T("'''")).GetBuffer(), szTextBuffer, sizeof szTextBuffer);
	GetDateFormat(LOCALE_SYSTEM_DEFAULT, 0, &g_stLocalTime, szTextBuffer, szTextBuffer2, sizeof szTextBuffer2);
	xsTextBuffer = XString(szTextBuffer2).Replace(_T("@"), XString(_T("@"), szInternetTime));
	DrawText(hDC, xsTextBuffer.GetBuffer(), -1, &rcWindow, DT_VCENTER | DT_RIGHT);

	SelectObject(hDC, hFontOld);
	DeleteObject(hFont);

	EndPaint(hwnd, &ps);
}