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 <stdio.h>
|
||||||
#include <tchar.h>
|
#include <tchar.h>
|
||||||
|
#include <assert.h>
|
||||||
|
#define ASSERT(x) assert(x)
|
||||||
|
|
||||||
|
|
||||||
// TODO: reference additional headers your program requires here
|
// TODO: reference additional headers your program requires here
|
||||||
|
|||||||
@ -6,65 +6,40 @@
|
|||||||
|
|
||||||
#include "trackview.h"
|
#include "trackview.h"
|
||||||
|
|
||||||
const char *windowClassName = "test";
|
const char *mainWindowClassName = "MainWindow";
|
||||||
TrackView trackView;
|
|
||||||
|
|
||||||
static int getScrollPos(HWND hwnd, int bar)
|
HWND trackViewWin;
|
||||||
{
|
LRESULT CALLBACK mainWindowProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
|
||||||
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)
|
|
||||||
{
|
{
|
||||||
switch(msg)
|
switch(msg)
|
||||||
{
|
{
|
||||||
case WM_CREATE:
|
case WM_CREATE:
|
||||||
trackView.onCreate(hwnd);
|
{
|
||||||
|
trackViewWin = createTrackViewWindow(GetModuleHandle(NULL), hwnd);
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case WM_SIZE:
|
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;
|
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:
|
default:
|
||||||
return DefWindowProc(hwnd, msg, wParam, lParam);
|
return DefWindowProc(hwnd, msg, wParam, lParam);
|
||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
ATOM registerWindowClass(HINSTANCE hInstance)
|
ATOM registerMainWindowClass(HINSTANCE hInstance)
|
||||||
{
|
{
|
||||||
WNDCLASSEX wc;
|
WNDCLASSEX wc;
|
||||||
|
|
||||||
wc.cbSize = sizeof(WNDCLASSEX);
|
wc.cbSize = sizeof(WNDCLASSEX);
|
||||||
wc.style = 0;
|
wc.style = 0;
|
||||||
wc.lpfnWndProc = windowProc;
|
wc.lpfnWndProc = mainWindowProc;
|
||||||
wc.cbClsExtra = 0;
|
wc.cbClsExtra = 0;
|
||||||
wc.cbWndExtra = 0;
|
wc.cbWndExtra = 0;
|
||||||
wc.hInstance = hInstance;
|
wc.hInstance = hInstance;
|
||||||
@ -72,7 +47,7 @@ ATOM registerWindowClass(HINSTANCE hInstance)
|
|||||||
wc.hCursor = LoadCursor(NULL, IDC_ARROW);
|
wc.hCursor = LoadCursor(NULL, IDC_ARROW);
|
||||||
wc.hbrBackground = (HBRUSH)(COLOR_WINDOW+1);
|
wc.hbrBackground = (HBRUSH)(COLOR_WINDOW+1);
|
||||||
wc.lpszMenuName = NULL;
|
wc.lpszMenuName = NULL;
|
||||||
wc.lpszClassName = windowClassName;
|
wc.lpszClassName = mainWindowClassName;
|
||||||
wc.hIconSm = LoadIcon(NULL, IDI_APPLICATION);
|
wc.hIconSm = LoadIcon(NULL, IDI_APPLICATION);
|
||||||
|
|
||||||
return RegisterClassEx(&wc);
|
return RegisterClassEx(&wc);
|
||||||
@ -84,8 +59,9 @@ int _tmain(int argc, _TCHAR* argv[])
|
|||||||
MSG Msg;
|
MSG Msg;
|
||||||
HINSTANCE hInstance = GetModuleHandle(NULL);
|
HINSTANCE hInstance = GetModuleHandle(NULL);
|
||||||
|
|
||||||
ATOM wc = registerWindowClass(hInstance);
|
ATOM mainClass = registerMainWindowClass(hInstance);
|
||||||
if(!wc)
|
ATOM trackViewClass = registerTrackViewWindowClass(hInstance);
|
||||||
|
if(!mainClass || ! trackViewClass)
|
||||||
{
|
{
|
||||||
MessageBox(NULL, _T("Window Registration Failed!"), _T("Error!"), MB_ICONEXCLAMATION | MB_OK);
|
MessageBox(NULL, _T("Window Registration Failed!"), _T("Error!"), MB_ICONEXCLAMATION | MB_OK);
|
||||||
return 0;
|
return 0;
|
||||||
@ -93,10 +69,10 @@ int _tmain(int argc, _TCHAR* argv[])
|
|||||||
|
|
||||||
// Step 2: Creating the Window
|
// Step 2: Creating the Window
|
||||||
hwnd = CreateWindowEx(
|
hwnd = CreateWindowEx(
|
||||||
WS_EX_CLIENTEDGE,
|
0,
|
||||||
windowClassName,
|
mainWindowClassName,
|
||||||
_T("SyncTracker 3000"),
|
_T("SyncTracker 3000"),
|
||||||
WS_VSCROLL | WS_HSCROLL | WS_OVERLAPPEDWINDOW,
|
WS_OVERLAPPEDWINDOW | WS_CLIPCHILDREN,
|
||||||
CW_USEDEFAULT, CW_USEDEFAULT, // x, y
|
CW_USEDEFAULT, CW_USEDEFAULT, // x, y
|
||||||
CW_USEDEFAULT, CW_USEDEFAULT, // width, height
|
CW_USEDEFAULT, CW_USEDEFAULT, // width, height
|
||||||
NULL, NULL, hInstance, NULL
|
NULL, NULL, hInstance, NULL
|
||||||
@ -118,6 +94,6 @@ int _tmain(int argc, _TCHAR* argv[])
|
|||||||
DispatchMessage(&Msg);
|
DispatchMessage(&Msg);
|
||||||
}
|
}
|
||||||
|
|
||||||
UnregisterClass(windowClassName, hInstance);
|
UnregisterClass(mainWindowClassName, hInstance);
|
||||||
return int(Msg.wParam);
|
return int(Msg.wParam);
|
||||||
}
|
}
|
||||||
111
trackview.cpp
111
trackview.cpp
@ -2,6 +2,8 @@
|
|||||||
|
|
||||||
#include "trackview.h"
|
#include "trackview.h"
|
||||||
|
|
||||||
|
const char *trackViewWindowClassName = "TrackView";
|
||||||
|
|
||||||
static const int topMarginHeight = 20;
|
static const int topMarginHeight = 20;
|
||||||
static const int leftMarginWidth = 70;
|
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;
|
int lastLine = scrollPosY + ((rcTracks.bottom - topMarginHeight) + (fontHeight - 1)) / fontHeight;
|
||||||
|
|
||||||
lastLine = min(lastLine, lines);
|
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);
|
SetBkMode(hdc, TRANSPARENT);
|
||||||
|
|
||||||
for (int y = firstLine; y < lastLine; ++y)
|
for (int y = firstLine; y < lastLine; ++y)
|
||||||
@ -308,3 +317,103 @@ void TrackView::onSize(HWND hwnd, int width, int height)
|
|||||||
setupScrollBars(hwnd);
|
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 windowWidth, windowHeight;
|
||||||
int windowLines;
|
int windowLines;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
ATOM registerTrackViewWindowClass(HINSTANCE hInstance);
|
||||||
|
HWND createTrackViewWindow(HINSTANCE hInstance, HWND hwndParent);
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user