From 3b81ebab986d619742fffc052d4fca6a8c5080fd Mon Sep 17 00:00:00 2001 From: Pietro Gagliardi Date: Wed, 7 Jan 2015 16:24:17 -0500 Subject: [PATCH] Switched the test program to make the Table an actual child window now that I'm about to implement actually getting data in the real world. Implemented focus grabbing. More TODOs. --- wintable/main.h | 1 + wintable/select.h | 4 +++ wintable/test.c | 90 ++++++++++++++++++++++++++++++++++++----------- 3 files changed, 74 insertions(+), 21 deletions(-) diff --git a/wintable/main.h b/wintable/main.h index 7199676..3999d7b 100644 --- a/wintable/main.h +++ b/wintable/main.h @@ -148,6 +148,7 @@ static void deftablePanic(const char *msg, DWORD lastError) DebugBreak(); } +// TODO have hInstance passed in void initTable(void (*panicfunc)(const char *msg, DWORD lastError), BOOL (*WINAPI tme)(LPTRACKMOUSEEVENT)) { WNDCLASSW wc; diff --git a/wintable/select.h b/wintable/select.h index 0539e52..117dad5 100644 --- a/wintable/select.h +++ b/wintable/select.h @@ -109,6 +109,10 @@ HANDLER(mouseDownSelectHandler) { struct rowcol rc; + // TODO separate this from here + // TODO other mouse buttons? + // don't check SetFocus()'s error (http://stackoverflow.com/questions/24073695/winapi-can-setfocus-return-null-without-an-error-because-thats-what-im-see) + SetFocus(t->hwnd); rc = lParamToRowColumn(t, lParam); // don't check if lParamToRowColumn() returned row -1 or column -1; we want deselection behavior doselect(t, rc.row, rc.column); diff --git a/wintable/test.c b/wintable/test.c index 18fc1d1..59973e2 100644 --- a/wintable/test.c +++ b/wintable/test.c @@ -8,31 +8,23 @@ void mkbitmap(void); #include "main.h" -int main(int argc, char *argv[]) -{ - HWND mainwin; - MSG msg; - INITCOMMONCONTROLSEX icc; +HWND tablehwnd = NULL; +BOOL msgfont = FALSE; - mkbitmap(); - ZeroMemory(&icc, sizeof (INITCOMMONCONTROLSEX)); - icc.dwSize = sizeof (INITCOMMONCONTROLSEX); - icc.dwICC = ICC_LISTVIEW_CLASSES; - if (InitCommonControlsEx(&icc) == 0) - panic("(test program) error initializing comctl32.dll"); - initTable(NULL, _TrackMouseEvent); - mainwin = CreateWindowExW(0, +BOOL mainwinCreate(HWND hwnd, LPCREATESTRUCT lpcs) +{ + tablehwnd = CreateWindowExW(0, tableWindowClass, L"Main Window", - WS_OVERLAPPEDWINDOW | WS_HSCROLL | WS_VSCROLL, + WS_CHILD | WS_VISIBLE | WS_HSCROLL | WS_VSCROLL, CW_USEDEFAULT, CW_USEDEFAULT, 400, 400, - NULL, NULL, GetModuleHandle(NULL), NULL); - if (mainwin == NULL) + hwnd, NULL, lpcs->hInstance, NULL); + if (tablehwnd == NULL) panic("(test program) error creating Table"); - SendMessageW(mainwin, tableAddColumn, tableColumnText, (LPARAM) L"Column"); - SendMessageW(mainwin, tableAddColumn, tableColumnImage, (LPARAM) L"Column 2"); - SendMessageW(mainwin, tableAddColumn, tableColumnCheckbox, (LPARAM) L"Column 3"); - if (argc > 1) { + SendMessageW(tablehwnd, tableAddColumn, tableColumnText, (LPARAM) L"Column"); + SendMessageW(tablehwnd, tableAddColumn, tableColumnImage, (LPARAM) L"Column 2"); + SendMessageW(tablehwnd, tableAddColumn, tableColumnCheckbox, (LPARAM) L"Column 3"); + if (msgfont) { NONCLIENTMETRICSW ncm; HFONT font; @@ -43,8 +35,64 @@ int main(int argc, char *argv[]) font = CreateFontIndirectW(&ncm.lfMessageFont); if (font == NULL) panic("(test program) error creating lfMessageFont HFONT"); - SendMessageW(mainwin, WM_SETFONT, (WPARAM) font, TRUE); + SendMessageW(tablehwnd, WM_SETFONT, (WPARAM) font, TRUE); } + return TRUE; +} + +void mainwinDestroy(HWND hwnd) +{ + DestroyWindow(tablehwnd); + PostQuitMessage(0); +} + +void mainwinResize(HWND hwnd, UINT state, int cx, int cy) +{ + if (tablehwnd != NULL) + MoveWindow(tablehwnd, 0, 0, cx, cy, TRUE); +} + +LRESULT CALLBACK mainwndproc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam) +{ + switch (uMsg) { + HANDLE_MSG(hwnd, WM_CREATE, mainwinCreate); + HANDLE_MSG(hwnd, WM_SIZE, mainwinResize); + HANDLE_MSG(hwnd, WM_DESTROY, mainwinDestroy); + } + return DefWindowProcW(hwnd, uMsg, wParam, lParam); +} + +int main(int argc, char *argv[]) +{ + HWND mainwin; + MSG msg; + INITCOMMONCONTROLSEX icc; + WNDCLASSW wc; + + mkbitmap(); + ZeroMemory(&icc, sizeof (INITCOMMONCONTROLSEX)); + icc.dwSize = sizeof (INITCOMMONCONTROLSEX); + icc.dwICC = ICC_LISTVIEW_CLASSES; + if (InitCommonControlsEx(&icc) == 0) + panic("(test program) error initializing comctl32.dll"); + initTable(NULL, _TrackMouseEvent); + ZeroMemory(&wc, sizeof (WNDCLASSW)); + wc.lpszClassName = L"mainwin"; + wc.lpfnWndProc = mainwndproc; + wc.hIcon = LoadIcon(NULL, IDI_APPLICATION); + wc.hCursor = LoadCursor(NULL, IDC_ARROW); + wc.hbrBackground = (HBRUSH) (COLOR_BTNFACE + 1); + wc.hInstance = GetModuleHandle(NULL); + if (RegisterClassW(&wc) == 0) + panic("(test program) error registering main window class"); + mainwin = CreateWindowExW(0, + L"mainwin", L"Main Window", + WS_OVERLAPPEDWINDOW, + CW_USEDEFAULT, CW_USEDEFAULT, + 400, 400, + NULL, NULL, GetModuleHandle(NULL), NULL); + if (mainwin == NULL) + panic("(test program) error creating main window"); ShowWindow(mainwin, SW_SHOWDEFAULT); if (UpdateWindow(mainwin) == 0) panic("(test program) error updating window");