dummy message
This commit is contained in:
parent
084c0805c0
commit
e4d1206e35
3
stdafx.h
3
stdafx.h
@ -11,7 +11,8 @@
|
||||
|
||||
#include <stdio.h>
|
||||
#include <tchar.h>
|
||||
|
||||
#include <assert.h>
|
||||
#define ASSERT(x) assert(x)
|
||||
|
||||
|
||||
// TODO: reference additional headers your program requires here
|
||||
|
||||
@ -6,65 +6,40 @@
|
||||
|
||||
#include "trackview.h"
|
||||
|
||||
const char *windowClassName = "test";
|
||||
TrackView trackView;
|
||||
const char *mainWindowClassName = "MainWindow";
|
||||
|
||||
static int getScrollPos(HWND hwnd, int bar)
|
||||
{
|
||||
SCROLLINFO si = { sizeof(si), SIF_TRACKPOS };
|
||||
GetScrollInfo(hwnd, bar, &si);
|
||||
return int(si.nTrackPos);
|
||||
}
|
||||
|
||||
LRESULT CALLBACK windowProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
|
||||
HWND trackViewWin;
|
||||
LRESULT CALLBACK mainWindowProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
|
||||
{
|
||||
switch(msg)
|
||||
{
|
||||
case WM_CREATE:
|
||||
trackView.onCreate(hwnd);
|
||||
{
|
||||
trackViewWin = createTrackViewWindow(GetModuleHandle(NULL), hwnd);
|
||||
}
|
||||
break;
|
||||
|
||||
case WM_SIZE:
|
||||
trackView.onSize(hwnd, LOWORD(lParam), HIWORD(lParam));
|
||||
{
|
||||
int width = (short)LOWORD(lParam);
|
||||
int height = (short)HIWORD(lParam);
|
||||
MoveWindow(trackViewWin, 0, 0, width, height, TRUE);
|
||||
}
|
||||
break;
|
||||
|
||||
case WM_GETMINMAXINFO:
|
||||
trackView.onGetMinMaxInfo((MINMAXINFO*)lParam);
|
||||
break;
|
||||
|
||||
case WM_CLOSE:
|
||||
DestroyWindow(hwnd);
|
||||
break;
|
||||
|
||||
case WM_DESTROY:
|
||||
PostQuitMessage(0);
|
||||
break;
|
||||
|
||||
case WM_VSCROLL:
|
||||
trackView.onVScroll(hwnd, LOWORD(wParam), getScrollPos(hwnd, SB_VERT));
|
||||
break;
|
||||
|
||||
case WM_HSCROLL:
|
||||
trackView.onHScroll(hwnd, LOWORD(wParam), getScrollPos(hwnd, SB_HORZ));
|
||||
break;
|
||||
|
||||
case WM_PAINT:
|
||||
trackView.onPaint(hwnd);
|
||||
break;
|
||||
|
||||
default:
|
||||
return DefWindowProc(hwnd, msg, wParam, lParam);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
ATOM registerWindowClass(HINSTANCE hInstance)
|
||||
ATOM registerMainWindowClass(HINSTANCE hInstance)
|
||||
{
|
||||
WNDCLASSEX wc;
|
||||
|
||||
wc.cbSize = sizeof(WNDCLASSEX);
|
||||
wc.style = 0;
|
||||
wc.lpfnWndProc = windowProc;
|
||||
wc.lpfnWndProc = mainWindowProc;
|
||||
wc.cbClsExtra = 0;
|
||||
wc.cbWndExtra = 0;
|
||||
wc.hInstance = hInstance;
|
||||
@ -72,7 +47,7 @@ ATOM registerWindowClass(HINSTANCE hInstance)
|
||||
wc.hCursor = LoadCursor(NULL, IDC_ARROW);
|
||||
wc.hbrBackground = (HBRUSH)(COLOR_WINDOW+1);
|
||||
wc.lpszMenuName = NULL;
|
||||
wc.lpszClassName = windowClassName;
|
||||
wc.lpszClassName = mainWindowClassName;
|
||||
wc.hIconSm = LoadIcon(NULL, IDI_APPLICATION);
|
||||
|
||||
return RegisterClassEx(&wc);
|
||||
@ -84,8 +59,9 @@ int _tmain(int argc, _TCHAR* argv[])
|
||||
MSG Msg;
|
||||
HINSTANCE hInstance = GetModuleHandle(NULL);
|
||||
|
||||
ATOM wc = registerWindowClass(hInstance);
|
||||
if(!wc)
|
||||
ATOM mainClass = registerMainWindowClass(hInstance);
|
||||
ATOM trackViewClass = registerTrackViewWindowClass(hInstance);
|
||||
if(!mainClass || ! trackViewClass)
|
||||
{
|
||||
MessageBox(NULL, _T("Window Registration Failed!"), _T("Error!"), MB_ICONEXCLAMATION | MB_OK);
|
||||
return 0;
|
||||
@ -93,10 +69,10 @@ int _tmain(int argc, _TCHAR* argv[])
|
||||
|
||||
// Step 2: Creating the Window
|
||||
hwnd = CreateWindowEx(
|
||||
WS_EX_CLIENTEDGE,
|
||||
windowClassName,
|
||||
0,
|
||||
mainWindowClassName,
|
||||
_T("SyncTracker 3000"),
|
||||
WS_VSCROLL | WS_HSCROLL | WS_OVERLAPPEDWINDOW,
|
||||
WS_OVERLAPPEDWINDOW | WS_CLIPCHILDREN,
|
||||
CW_USEDEFAULT, CW_USEDEFAULT, // x, y
|
||||
CW_USEDEFAULT, CW_USEDEFAULT, // width, height
|
||||
NULL, NULL, hInstance, NULL
|
||||
@ -118,6 +94,6 @@ int _tmain(int argc, _TCHAR* argv[])
|
||||
DispatchMessage(&Msg);
|
||||
}
|
||||
|
||||
UnregisterClass(windowClassName, hInstance);
|
||||
UnregisterClass(mainWindowClassName, hInstance);
|
||||
return int(Msg.wParam);
|
||||
}
|
||||
111
trackview.cpp
111
trackview.cpp
@ -2,6 +2,8 @@
|
||||
|
||||
#include "trackview.h"
|
||||
|
||||
const char *trackViewWindowClassName = "TrackView";
|
||||
|
||||
static const int topMarginHeight = 20;
|
||||
static const int leftMarginWidth = 70;
|
||||
|
||||
@ -51,7 +53,14 @@ void TrackView::paintTracks(HDC hdc, RECT rcTracks)
|
||||
int lastLine = scrollPosY + ((rcTracks.bottom - topMarginHeight) + (fontHeight - 1)) / fontHeight;
|
||||
|
||||
lastLine = min(lastLine, lines);
|
||||
|
||||
|
||||
RECT topLeftCorner;
|
||||
topLeftCorner.top = 0;
|
||||
topLeftCorner.bottom = topMarginHeight;
|
||||
topLeftCorner.left = 0;
|
||||
topLeftCorner.right = leftMarginWidth;
|
||||
FillRect( hdc, &topLeftCorner, (HBRUSH)GetStockObject(LTGRAY_BRUSH));
|
||||
|
||||
SetBkMode(hdc, TRANSPARENT);
|
||||
|
||||
for (int y = firstLine; y < lastLine; ++y)
|
||||
@ -308,3 +317,103 @@ void TrackView::onSize(HWND hwnd, int width, int height)
|
||||
setupScrollBars(hwnd);
|
||||
}
|
||||
|
||||
LRESULT CALLBACK trackViewWindowProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
|
||||
{
|
||||
// Get the TrackView instance (if any)
|
||||
#pragma warning(suppress:4312) /* remove a pointless warning */
|
||||
TrackView *trackView = (TrackView*)GetWindowLongPtr(hwnd, 0);
|
||||
|
||||
switch(msg)
|
||||
{
|
||||
case WM_CREATE:
|
||||
ASSERT(NULL == trackView);
|
||||
|
||||
// allocate a TrackView instance
|
||||
trackView = new TrackView();
|
||||
|
||||
// Set the TrackView instance
|
||||
#pragma warning(suppress:4244) /* remove a pointless warning */
|
||||
SetWindowLongPtr(hwnd, 0, (LONG_PTR)trackView);
|
||||
|
||||
trackView->onCreate(hwnd);
|
||||
break;
|
||||
|
||||
case WM_CLOSE:
|
||||
// free the TrackView instance
|
||||
ASSERT(NULL != trackView);
|
||||
delete trackView;
|
||||
SetWindowLongPtr(hwnd, 0, (LONG_PTR)NULL);
|
||||
|
||||
DestroyWindow(hwnd);
|
||||
break;
|
||||
|
||||
case WM_DESTROY:
|
||||
PostQuitMessage(0);
|
||||
break;
|
||||
|
||||
case WM_SIZE:
|
||||
ASSERT(NULL != trackView);
|
||||
trackView->onSize(hwnd, LOWORD(lParam), HIWORD(lParam));
|
||||
break;
|
||||
|
||||
case WM_GETMINMAXINFO:
|
||||
ASSERT(NULL != trackView);
|
||||
trackView->onGetMinMaxInfo((MINMAXINFO*)lParam);
|
||||
break;
|
||||
|
||||
case WM_VSCROLL:
|
||||
ASSERT(NULL != trackView);
|
||||
trackView->onVScroll(hwnd, LOWORD(wParam), getScrollPos(hwnd, SB_VERT));
|
||||
break;
|
||||
|
||||
case WM_HSCROLL:
|
||||
ASSERT(NULL != trackView);
|
||||
trackView->onHScroll(hwnd, LOWORD(wParam), getScrollPos(hwnd, SB_HORZ));
|
||||
break;
|
||||
|
||||
case WM_PAINT:
|
||||
ASSERT(NULL != trackView);
|
||||
trackView->onPaint(hwnd);
|
||||
break;
|
||||
|
||||
default:
|
||||
return DefWindowProc(hwnd, msg, wParam, lParam);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
ATOM registerTrackViewWindowClass(HINSTANCE hInstance)
|
||||
{
|
||||
WNDCLASSEX wc;
|
||||
|
||||
wc.cbSize = sizeof(WNDCLASSEX);
|
||||
wc.style = 0;
|
||||
wc.lpfnWndProc = trackViewWindowProc;
|
||||
wc.cbClsExtra = 0;
|
||||
wc.cbWndExtra = sizeof(TrackView*);
|
||||
wc.hInstance = hInstance;
|
||||
wc.hIcon = 0;
|
||||
wc.hCursor = LoadCursor(NULL, IDC_IBEAM);
|
||||
wc.hbrBackground = (HBRUSH)0;
|
||||
wc.lpszMenuName = NULL;
|
||||
wc.lpszClassName = trackViewWindowClassName;
|
||||
wc.hIconSm = LoadIcon(NULL, IDI_APPLICATION);
|
||||
|
||||
return RegisterClassEx(&wc);
|
||||
}
|
||||
|
||||
HWND createTrackViewWindow(HINSTANCE hInstance, HWND hwndParent)
|
||||
{
|
||||
HWND hwnd = CreateWindowEx(
|
||||
WS_EX_CLIENTEDGE,
|
||||
trackViewWindowClassName, _T(""),
|
||||
WS_VSCROLL | WS_HSCROLL | WS_CHILD | WS_VISIBLE,
|
||||
CW_USEDEFAULT, CW_USEDEFAULT, // x, y
|
||||
CW_USEDEFAULT, CW_USEDEFAULT, // width, height
|
||||
hwndParent, NULL, GetModuleHandle(NULL), NULL
|
||||
);
|
||||
// SetWindowLong(hwnd, 0, (LONG)0xdeadbeef);
|
||||
// SetWindowLongPtr(hwnd, DWLP_USER, 0xdeadbeef);
|
||||
return hwnd;
|
||||
}
|
||||
|
||||
|
||||
@ -20,3 +20,6 @@ public:
|
||||
int windowWidth, windowHeight;
|
||||
int windowLines;
|
||||
};
|
||||
|
||||
ATOM registerTrackViewWindowClass(HINSTANCE hInstance);
|
||||
HWND createTrackViewWindow(HINSTANCE hInstance, HWND hwndParent);
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user