initial commit

This commit is contained in:
Erik Faye-Lund 2008-02-17 12:56:01 +00:00
commit 1b91475b6c
5 changed files with 496 additions and 0 deletions

8
stdafx.cpp Normal file
View File

@ -0,0 +1,8 @@
// stdafx.cpp : source file that includes just the standard includes
// synctracker2.pch will be the pre-compiled header
// stdafx.obj will contain the pre-compiled type information
#include "stdafx.h"
// TODO: reference any additional headers you need in STDAFX.H
// and not in this file

15
stdafx.h Normal file
View File

@ -0,0 +1,15 @@
// stdafx.h : include file for standard system include files,
// or project specific include files that are used frequently, but
// are changed infrequently
//
#pragma once
#define WIN32_LEAN_AND_MEAN // Exclude rarely-used stuff from Windows headers
#include <stdio.h>
#include <tchar.h>
// TODO: reference additional headers your program requires here

248
synctracker2.cpp Normal file
View File

@ -0,0 +1,248 @@
// synctracker2.cpp : Defines the entry point for the console application.
//
#include "stdafx.h"
#include <windows.h>
const _TCHAR g_szClassName[] = _T("myWindowClass");
const int fontHeight = 16;
const int fontWidth = 12;
int scrollPosX;
int scrollPosY;
int windowWidth;
int windowHeight;
int windowLines;
void setupScrollBars(HWND hwnd)
{
SCROLLINFO si = { sizeof(si) };
si.fMask = SIF_POS | SIF_PAGE | SIF_RANGE | SIF_DISABLENOSCROLL;
si.nPos = scrollPosY;
si.nPage = windowLines;
si.nMin = 0;
si.nMax = 0x80;
SetScrollInfo(hwnd, SB_VERT, &si, TRUE);
}
void scroll(HWND hwnd, int dx, int dy)
{
const int oldScrollPosX = scrollPosX;
const int oldScrollPosY = scrollPosY;
// update scrollPos
scrollPosX += dx;
scrollPosY += dy;
// clamp scrollPos
scrollPosX = max(scrollPosX, 0);
scrollPosY = max(scrollPosY, 0);
if (oldScrollPosX != scrollPosX || oldScrollPosY != scrollPosY)
{
ScrollWindowEx(
hwnd,
oldScrollPosX - scrollPosX,
(oldScrollPosY - scrollPosY) * fontHeight,
NULL,
NULL,
NULL,
NULL,
SW_INVALIDATE
);
setupScrollBars(hwnd);
}
}
void paintWindow(HWND hwnd)
{
PAINTSTRUCT ps;
HDC hdc = BeginPaint(hwnd, &ps);
SetBkMode(hdc, OPAQUE);
// SetBkColor(hdc, RGB(255, 0, 0));
int firstLine = scrollPosY + ps.rcPaint.top / fontHeight;
int lastLine = scrollPosY + (ps.rcPaint.bottom + fontHeight - 1) / fontHeight;
for (int x = 0; x < 10; ++x)
{
for (int y = firstLine; y < lastLine; ++y)
{
int val = y | (x << 8);
/* format the text */
char temp[256];
_snprintf_s(temp, 256, "%04X ", val);
TextOut(hdc, x * fontWidth * 5 - scrollPosX, (y - scrollPosY) * fontHeight, temp, int(strlen(temp)));
}
}
EndPaint(hwnd, &ps);
}
void onCreate(HWND hwnd)
{
scrollPosX = 0;
scrollPosY = 0;
windowWidth = -1;
windowHeight = -1;
setupScrollBars(hwnd);
}
void onScroll(HWND hwnd, UINT sbCode, int newPos)
{
switch (sbCode)
{
case SB_LINEUP:
scroll(hwnd, 0, -1);
break;
case SB_LINEDOWN:
scroll(hwnd, 0, 1);
break;
case SB_PAGEUP:
scroll(hwnd, 0, -windowLines);
break;
case SB_PAGEDOWN:
scroll(hwnd, 0, windowLines);
break;
}
}
void onSize(HWND hwnd, int width, int height)
{
const int oldWindowWidth = windowWidth;
const int oldWindowHeight = windowHeight;
windowWidth = width;
windowHeight = height;
windowLines = height / fontHeight;
setupScrollBars(hwnd);
/*
if (oldWindowWidth < windowWidth)
{
RECT rightRect;
rightRect.left = oldWindowWidth;
rightRect.right = windowWidth;
InvalidateRect(hwnd, &rightRect, FALSE);
}
*/
/*
if (oldWindowHeight < windowHeight)
{
RECT bottomRect;
bottomRect.left = 0;
bottomRect.right = width;
bottomRect.top = oldWindowHeight;
bottomRect.bottom = windowHeight;
printf("extending downwards! %d %d\n", bottomRect.top, bottomRect.bottom);
InvalidateRect(hwnd, &bottomRect, FALSE);
}
*/
}
void onPaint(HWND hwnd)
{
paintWindow(hwnd);
}
int getScrollPos(HWND hwnd, int bar)
{
SCROLLINFO si = { sizeof(si), SIF_TRACKPOS };
GetScrollInfo(hwnd, bar, &si);
return int(si.nTrackPos);
}
LRESULT CALLBACK WndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
{
switch(msg)
{
case WM_CREATE:
onCreate(hwnd);
break;
case WM_SIZE:
onSize(hwnd, LOWORD(lParam), HIWORD(lParam));
break;
case WM_CLOSE:
DestroyWindow(hwnd);
break;
case WM_DESTROY:
PostQuitMessage(0);
break;
case WM_VSCROLL:
onScroll(hwnd, LOWORD(wParam), getScrollPos(hwnd, SB_VERT));
break;
case WM_PAINT:
onPaint(hwnd);
break;
default:
return DefWindowProc(hwnd, msg, wParam, lParam);
}
return 0;
}
int _tmain(int argc, _TCHAR* argv[])
{
WNDCLASSEX wc;
HWND hwnd;
MSG Msg;
HINSTANCE hInstance = GetModuleHandle(NULL);
//Step 1: Registering the Window Class
wc.cbSize = sizeof(WNDCLASSEX);
wc.style = 0;
wc.lpfnWndProc = WndProc;
wc.cbClsExtra = 0;
wc.cbWndExtra = 0;
wc.hInstance = hInstance;
wc.hIcon = LoadIcon(NULL, IDI_APPLICATION);
wc.hCursor = LoadCursor(NULL, IDC_ARROW);
wc.hbrBackground = (HBRUSH)(COLOR_WINDOW+1);
wc.lpszMenuName = NULL;
wc.lpszClassName = g_szClassName;
wc.hIconSm = LoadIcon(NULL, IDI_APPLICATION);
if(!RegisterClassEx(&wc))
{
MessageBox(NULL, _T("Window Registration Failed!"), _T("Error!"), MB_ICONEXCLAMATION | MB_OK);
return 0;
}
// Step 2: Creating the Window
hwnd = CreateWindowEx(
WS_EX_CLIENTEDGE,
g_szClassName,
_T("The title of my window"),
WS_VSCROLL | WS_HSCROLL | WS_OVERLAPPEDWINDOW,
CW_USEDEFAULT, CW_USEDEFAULT, 240, 120,
NULL, NULL, hInstance, NULL
);
if(hwnd == NULL)
{
MessageBox(NULL, _T("Window Creation Failed!"), _T("Error!"), MB_ICONEXCLAMATION | MB_OK);
return 0;
}
ShowWindow(hwnd, TRUE);
UpdateWindow(hwnd);
// Step 3: The Message Loop
while(GetMessage(&Msg, NULL, 0, 0) > 0)
{
TranslateMessage(&Msg);
DispatchMessage(&Msg);
}
return int(Msg.wParam);
}

20
synctracker2.sln Normal file
View File

@ -0,0 +1,20 @@

Microsoft Visual Studio Solution File, Format Version 9.00
# Visual Studio 2005
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "synctracker2", "synctracker2.vcproj", "{76B44BC8-8BB4-4B6E-B2FA-7738C9E7F80B}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Win32 = Debug|Win32
Release|Win32 = Release|Win32
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{76B44BC8-8BB4-4B6E-B2FA-7738C9E7F80B}.Debug|Win32.ActiveCfg = Debug|Win32
{76B44BC8-8BB4-4B6E-B2FA-7738C9E7F80B}.Debug|Win32.Build.0 = Debug|Win32
{76B44BC8-8BB4-4B6E-B2FA-7738C9E7F80B}.Release|Win32.ActiveCfg = Release|Win32
{76B44BC8-8BB4-4B6E-B2FA-7738C9E7F80B}.Release|Win32.Build.0 = Release|Win32
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
EndGlobal

205
synctracker2.vcproj Normal file
View File

@ -0,0 +1,205 @@
<?xml version="1.0" encoding="Windows-1252"?>
<VisualStudioProject
ProjectType="Visual C++"
Version="8,00"
Name="synctracker2"
ProjectGUID="{76B44BC8-8BB4-4B6E-B2FA-7738C9E7F80B}"
RootNamespace="synctracker2"
Keyword="Win32Proj"
>
<Platforms>
<Platform
Name="Win32"
/>
</Platforms>
<ToolFiles>
</ToolFiles>
<Configurations>
<Configuration
Name="Debug|Win32"
OutputDirectory="$(SolutionDir)$(ConfigurationName)"
IntermediateDirectory="$(ConfigurationName)"
ConfigurationType="1"
CharacterSet="2"
>
<Tool
Name="VCPreBuildEventTool"
/>
<Tool
Name="VCCustomBuildTool"
/>
<Tool
Name="VCXMLDataGeneratorTool"
/>
<Tool
Name="VCWebServiceProxyGeneratorTool"
/>
<Tool
Name="VCMIDLTool"
/>
<Tool
Name="VCCLCompilerTool"
Optimization="0"
PreprocessorDefinitions="WIN32;_DEBUG;_CONSOLE"
MinimalRebuild="true"
BasicRuntimeChecks="3"
RuntimeLibrary="3"
UsePrecompiledHeader="0"
WarningLevel="3"
Detect64BitPortabilityProblems="true"
DebugInformationFormat="4"
/>
<Tool
Name="VCManagedResourceCompilerTool"
/>
<Tool
Name="VCResourceCompilerTool"
/>
<Tool
Name="VCPreLinkEventTool"
/>
<Tool
Name="VCLinkerTool"
LinkIncremental="2"
GenerateDebugInformation="true"
SubSystem="1"
TargetMachine="1"
/>
<Tool
Name="VCALinkTool"
/>
<Tool
Name="VCManifestTool"
/>
<Tool
Name="VCXDCMakeTool"
/>
<Tool
Name="VCBscMakeTool"
/>
<Tool
Name="VCFxCopTool"
/>
<Tool
Name="VCAppVerifierTool"
/>
<Tool
Name="VCWebDeploymentTool"
/>
<Tool
Name="VCPostBuildEventTool"
/>
</Configuration>
<Configuration
Name="Release|Win32"
OutputDirectory="$(SolutionDir)$(ConfigurationName)"
IntermediateDirectory="$(ConfigurationName)"
ConfigurationType="1"
CharacterSet="1"
WholeProgramOptimization="1"
>
<Tool
Name="VCPreBuildEventTool"
/>
<Tool
Name="VCCustomBuildTool"
/>
<Tool
Name="VCXMLDataGeneratorTool"
/>
<Tool
Name="VCWebServiceProxyGeneratorTool"
/>
<Tool
Name="VCMIDLTool"
/>
<Tool
Name="VCCLCompilerTool"
PreprocessorDefinitions="WIN32;NDEBUG;_CONSOLE"
RuntimeLibrary="2"
UsePrecompiledHeader="0"
WarningLevel="3"
Detect64BitPortabilityProblems="true"
DebugInformationFormat="3"
/>
<Tool
Name="VCManagedResourceCompilerTool"
/>
<Tool
Name="VCResourceCompilerTool"
/>
<Tool
Name="VCPreLinkEventTool"
/>
<Tool
Name="VCLinkerTool"
LinkIncremental="1"
GenerateDebugInformation="true"
SubSystem="1"
OptimizeReferences="2"
EnableCOMDATFolding="2"
TargetMachine="1"
/>
<Tool
Name="VCALinkTool"
/>
<Tool
Name="VCManifestTool"
/>
<Tool
Name="VCXDCMakeTool"
/>
<Tool
Name="VCBscMakeTool"
/>
<Tool
Name="VCFxCopTool"
/>
<Tool
Name="VCAppVerifierTool"
/>
<Tool
Name="VCWebDeploymentTool"
/>
<Tool
Name="VCPostBuildEventTool"
/>
</Configuration>
</Configurations>
<References>
</References>
<Files>
<Filter
Name="Source Files"
Filter="cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx"
UniqueIdentifier="{4FC737F1-C7A5-4376-A066-2A32D752A2FF}"
>
<File
RelativePath=".\stdafx.cpp"
>
</File>
<File
RelativePath=".\synctracker2.cpp"
>
</File>
</Filter>
<Filter
Name="Header Files"
Filter="h;hpp;hxx;hm;inl;inc;xsd"
UniqueIdentifier="{93995380-89BD-4b04-88EB-625FBE52EBFB}"
>
<File
RelativePath=".\stdafx.h"
>
</File>
</Filter>
<Filter
Name="Resource Files"
Filter="rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav"
UniqueIdentifier="{67DA6AB6-F800-4c08-8B7A-83BB121AAD01}"
>
</Filter>
</Files>
<Globals>
</Globals>
</VisualStudioProject>