messed around with the creation to allow access to sync-data container

This commit is contained in:
Erik Faye-Lund 2007-12-13 19:58:13 +00:00
parent 983fb703f4
commit fbf9212544
3 changed files with 15 additions and 13 deletions

View File

@ -8,13 +8,15 @@
const TCHAR *mainWindowClassName = _T("MainWindow"); const TCHAR *mainWindowClassName = _T("MainWindow");
TrackView trackView;
HWND trackViewWin; HWND trackViewWin;
LRESULT CALLBACK mainWindowProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam) LRESULT CALLBACK mainWindowProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
{ {
switch(msg) switch(msg)
{ {
case WM_CREATE: case WM_CREATE:
trackViewWin = createTrackViewWindow(GetModuleHandle(NULL), hwnd); trackViewWin = trackView.create(GetModuleHandle(NULL), hwnd);
break; break;
case WM_SIZE: case WM_SIZE:

View File

@ -15,7 +15,7 @@ static const int trackWidth = fontWidth * 16;
static const int lines = 0x80; static const int lines = 0x80;
static const int tracks = 32; static const int tracks = 32;
TrackView::TrackView(HWND hwnd) TrackView::TrackView()
{ {
scrollPosX = 0; scrollPosX = 0;
scrollPosY = 0; scrollPosY = 0;
@ -25,7 +25,7 @@ TrackView::TrackView(HWND hwnd)
editLine = 0; editLine = 0;
editTrack = 0; editTrack = 0;
this->hwnd = hwnd; this->hwnd = NULL;
editBrush = CreateSolidBrush(RGB(255, 255, 0)); editBrush = CreateSolidBrush(RGB(255, 255, 0));
} }
@ -523,10 +523,9 @@ static LRESULT CALLBACK trackViewWindowProc(HWND hwnd, UINT msg, WPARAM wParam,
switch(msg) switch(msg)
{ {
case WM_NCCREATE: case WM_NCCREATE:
ASSERT(NULL == trackView); // Get TrackView from createstruct
trackView = (TrackView*)((CREATESTRUCT*)lParam)->lpCreateParams;
// allocate a TrackView instance trackView->hwnd = hwnd;
trackView = new TrackView(hwnd);
// Set the TrackView instance // Set the TrackView instance
#pragma warning(suppress:4244) /* remove a pointless warning */ #pragma warning(suppress:4244) /* remove a pointless warning */
@ -543,8 +542,7 @@ static LRESULT CALLBACK trackViewWindowProc(HWND hwnd, UINT msg, WPARAM wParam,
// call the window proc and store away the return code // call the window proc and store away the return code
LRESULT res = trackView->windowProc(hwnd, msg, wParam, lParam); LRESULT res = trackView->windowProc(hwnd, msg, wParam, lParam);
// free the TrackView instance // get rid of the TrackView instance
delete trackView;
trackView = NULL; trackView = NULL;
SetWindowLongPtr(hwnd, 0, (LONG_PTR)NULL); SetWindowLongPtr(hwnd, 0, (LONG_PTR)NULL);
@ -580,7 +578,7 @@ ATOM registerTrackViewWindowClass(HINSTANCE hInstance)
return RegisterClassEx(&wc); return RegisterClassEx(&wc);
} }
HWND createTrackViewWindow(HINSTANCE hInstance, HWND hwndParent) HWND TrackView::create(HINSTANCE hInstance, HWND hwndParent)
{ {
HWND hwnd = CreateWindowEx( HWND hwnd = CreateWindowEx(
WS_EX_CLIENTEDGE, WS_EX_CLIENTEDGE,
@ -588,7 +586,7 @@ HWND createTrackViewWindow(HINSTANCE hInstance, HWND hwndParent)
WS_VSCROLL | WS_HSCROLL | WS_CHILD | WS_VISIBLE, WS_VSCROLL | WS_HSCROLL | WS_CHILD | WS_VISIBLE,
CW_USEDEFAULT, CW_USEDEFAULT, // x, y CW_USEDEFAULT, CW_USEDEFAULT, // x, y
CW_USEDEFAULT, CW_USEDEFAULT, // width, height CW_USEDEFAULT, CW_USEDEFAULT, // width, height
hwndParent, NULL, GetModuleHandle(NULL), NULL hwndParent, NULL, GetModuleHandle(NULL), (void*)this
); );
return hwnd; return hwnd;
} }

View File

@ -5,9 +5,12 @@
class TrackView class TrackView
{ {
public: public:
TrackView(HWND hwnd); TrackView();
~TrackView(); ~TrackView();
HWND create(HINSTANCE hInstance, HWND hwndParent);
HWND getWin(){ return hwnd; }
private: private:
// some nasty hackery to forward the window messages // some nasty hackery to forward the window messages
friend static LRESULT CALLBACK trackViewWindowProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam); friend static LRESULT CALLBACK trackViewWindowProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam);
@ -48,4 +51,3 @@ private:
}; };
ATOM registerTrackViewWindowClass(HINSTANCE hInstance); ATOM registerTrackViewWindowClass(HINSTANCE hInstance);
HWND createTrackViewWindow(HINSTANCE hInstance, HWND hwndParent);