These examples come from the dp.SyntaxHighlighter package.
Save this page completely if you want the recipes and stylesheets used here. (They don't come bundled with the zip)
package us.prokhorenko.jx;
import us.prokhorenko.jx.Person;
import org.exolab.castor.xml.*;
import java.io.*;
import java.util.*;
public class Test {
public static void main(String args[]) {
try {
/***********************************
** Multiline block comments
**********************************/
string stringWithUrl1 = "http://blog.dreamprojections.com";
// Marshalling class to XML
// Create the Person class
Person person = new Person("Mr. White", "mr@white", "626-555-1234");
// Marshal and save to XML file
FileWriter file = new FileWriter("person.xml");
Marshaller m = new Marshaller(file);
m.marshal(person);
file.close();
// Unmarshalling XML to class
// Read from XML and unmarshal
FileReader uFile = new FileReader("person.xml");
Unmarshaller u = new Unmarshaller();
Person uPerson = (Person)u.unmarshal(Person.class, uFile);
// Show name and email
System.out.println("name: " + uPerson.getName());
System.out.println("email: " + uPerson.getEmail());
} catch (Exception e) {
e.printStackTrace();
}
}
}
#include <windows.h>
#include "winevent.hpp"
#include <time.h>
#include <stdio.h>
int nInt = 0;
int nStart = 0;
int nEnd = 0;
char buf[255];
//////////////////////////////////////////////////////////////
// Event handlers
template<>
LRESULT OnMsg<WM_CREATE>(HWND hWnd, WPARAM wParam, LPARAM lParam)
{
strcpy(buf, "Press any key to start test");
return DefWindowProc(hWnd, WM_CREATE, wParam, lParam);
}
template<>
LRESULT OnMsg<WM_KEYDOWN>(HWND hWnd, WPARAM wParam, LPARAM lParam)
{
nInt = 0;
strcpy(buf, "running test, please wait ...");
InvalidateRect(hWnd, NULL, true);
SendMessage(hWnd, WM_PAINT, 0, 0);
nStart = GetTickCount();
PostMessage(hWnd, WM_TIMER, 0, 0);
return DefWindowProc(hWnd, WM_KEYDOWN, wParam, lParam);
}
template<>
LRESULT OnMsg<WM_TIMER>(HWND hWnd, WPARAM wParam, LPARAM lParam)
{
if (nInt++ < 100000) {
PostMessage(hWnd, WM_TIMER, 0, 0);
} else {
nEnd = GetTickCount();
sprintf(buf, "Time elapsed = %d msec",
((nEnd - nStart) * 1000) / CLOCKS_PER_SEC);
InvalidateRect(hWnd, NULL, true);
}
return 0;
}
template<>
LRESULT OnMsg<WM_DESTROY>(HWND hWnd, WPARAM wParam, LPARAM lParam)
{
PostQuitMessage(0);
return 0;
}
template<>
LRESULT OnMsg<WM_PAINT>(HWND hWnd, WPARAM wParam, LPARAM lParam)
{
PAINTSTRUCT ps;
HDC hdc;
hdc = BeginPaint(hWnd, &ps);
TextOut(hdc, 100, 100, buf, static_cast<int>(strlen(buf)));
EndPaint(hWnd, &ps);
return DefWindowProc(hWnd, WM_PAINT, wParam, lParam);
}
/****************************************************
// Entry point for the application.
****************************************************/
int WINAPI WinMain(HINSTANCE hInstance,
HINSTANCE hPrevInstance, LPSTR szCmdLine, int nCmdShow)
{
InitMsgHandlers<NULL>();
static char szAppName[] = "demo";
HWND hwnd;
MSG msg;
WNDCLASSEX wndclass;
wndclass.cbSize = sizeof(wndclass);
wndclass.style = CS_HREDRAW | CS_VREDRAW;
wndclass.lpfnWndProc = WndProc;
wndclass.cbClsExtra = 0;
wndclass.cbWndExtra = 0;
wndclass.hInstance = hInstance;
wndclass.hIcon = LoadIcon(NULL, IDI_APPLICATION);
wndclass.hIconSm = LoadIcon(NULL, IDI_APPLICATION);
wndclass.hCursor = LoadCursor(NULL, IDC_ARROW);
wndclass.hbrBackground = (HBRUSH) GetStockObject(WHITE_BRUSH);
wndclass.lpszClassName = szAppName;
wndclass.lpszMenuName = NULL;
RegisterClassEx(&wndclass);
hwnd = CreateWindow(szAppName, "Static Dispatch Demo",
WS_OVERLAPPEDWINDOW,
CW_USEDEFAULT, CW_USEDEFAULT,
CW_USEDEFAULT, CW_USEDEFAULT,
NULL, NULL, hInstance, NULL);
ShowWindow(hwnd, nCmdShow);
UpdateWindow(hwnd);
while ( GetMessage(&msg, NULL, 0, 0) ) {
TranslateMessage(&msg);
DispatchMessage(&msg);
}
return static_cast<int>(msg.wParam);
}
string url = "<a href=\"" + someObj.getUrl() + "\" target=\"_blank\">";
// single line comments
// second single line
override protected void OnLoad(EventArgs e)
{
if(Attributes["class"] != null)
{
//_year.CssClass = _month.CssClass = _day.CssClass = Attributes["class"];
}
// base.OnLoad(e);
}
/***********************************
** Multiline block comments
**********************************/
/// <summary>
/// Gets or sets currently selected date of birth or <see cref="DateTime.MinValue"/> if selection is incomplete or invalid.
/// </summary>
public DateTime Date
{
String stringWithUrl = "http://blog.dreamprojections.com";
get
{
#region Hello world
try
{
/*
DateTime result = new DateTime(
int.Parse(_year.SelectedItem.Value),
int.Parse(_month.SelectedItem.Value),
int.Parse(_day.SelectedItem.Value)
);
i *= 2;
*/
return result;
}
catch
{
/* return _minDate; */
}
#endregion
}
set
{
Day = value.Day;
Month = value.Month;
Year = value.Year;
}
}
/* Main style for the table */
.dp-highlighter
{
font-family: "Courier New", Courier, mono;
font-size: 12px;
text-align: left;
border: 1px solid #2B91AF;
background-color: #fff;
width: 99%;
overflow: auto;
line-height: 100% !important;
margin: 18px 0px 18px 0px;
}
.dp-highlighter ol
{
margin: 0px 0px 0px 45px;
padding: 0px;
color: #2B91AF;
}
.dp-highlighter ol li
{
border-left: 3px solid #6CE26C;
border-bottom: 1px solid #eee;
background-color: #fff;
padding-left: 10px;
}
.dp-highlighter ol li.alt
{
background-color: #f8f8f8;
}
{$IFDEF VER140}
(***********************************
** Multiline block comments
**********************************)
procedure TForm1.Button1Click(Sender: TObject);
var
Number, I, X: Integer;
Y: Integer;
begin
str := 'http://blog.dreamprojections.com';
Number := 12356;
Caption := 'The Number is ' + IntToStr(Number);
for I := 0 to Number do
begin
Inc(X);
{
Dec(X);
X := X * 1.0;
}
Y := $F5D3;
ListBox1.Items.Add(IntToStr(X));
(*
ShowMessage('Hello'); *)
end;
asm
MOV AX,1234H
// MOV Number,AX
end;
end;