diff options
| author | Pietro Gagliardi <[email protected]> | 2015-01-07 16:24:17 -0500 |
|---|---|---|
| committer | Pietro Gagliardi <[email protected]> | 2015-01-07 16:24:17 -0500 |
| commit | 3b81ebab986d619742fffc052d4fca6a8c5080fd (patch) | |
| tree | 1ef2eb935d51ed0dabbd61bcf8ce7bcb7a944dde | |
| parent | 7c473a9fdcfd9c0efa09839b1f8da19a74ae2bdc (diff) | |
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.
| -rw-r--r-- | wintable/main.h | 1 | ||||
| -rw-r--r-- | wintable/select.h | 4 | ||||
| -rw-r--r-- | wintable/test.c | 86 |
3 files changed, 72 insertions, 19 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,11 +8,66 @@ void mkbitmap(void); #include "main.h" +HWND tablehwnd = NULL; +BOOL msgfont = FALSE; + +BOOL mainwinCreate(HWND hwnd, LPCREATESTRUCT lpcs) +{ + tablehwnd = CreateWindowExW(0, + tableWindowClass, L"Main Window", + WS_CHILD | WS_VISIBLE | WS_HSCROLL | WS_VSCROLL, + CW_USEDEFAULT, CW_USEDEFAULT, + 400, 400, + hwnd, NULL, lpcs->hInstance, NULL); + if (tablehwnd == NULL) + panic("(test program) error creating Table"); + 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; + + ZeroMemory(&ncm, sizeof (NONCLIENTMETRICSW)); + ncm.cbSize = sizeof (NONCLIENTMETRICSW); + if (SystemParametersInfoW(SPI_GETNONCLIENTMETRICS, sizeof (NONCLIENTMETRICSW), &ncm, sizeof (NONCLIENTMETRICSW)) == 0) + panic("(test program) error getting non-client metrics"); + font = CreateFontIndirectW(&ncm.lfMessageFont); + if (font == NULL) + panic("(test program) error creating lfMessageFont HFONT"); + 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)); @@ -21,30 +76,23 @@ int main(int argc, char *argv[]) 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, - tableWindowClass, L"Main Window", - WS_OVERLAPPEDWINDOW | WS_HSCROLL | WS_VSCROLL, + 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 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) { - NONCLIENTMETRICSW ncm; - HFONT font; - - ZeroMemory(&ncm, sizeof (NONCLIENTMETRICSW)); - ncm.cbSize = sizeof (NONCLIENTMETRICSW); - if (SystemParametersInfoW(SPI_GETNONCLIENTMETRICS, sizeof (NONCLIENTMETRICSW), &ncm, sizeof (NONCLIENTMETRICSW)) == 0) - panic("(test program) error getting non-client metrics"); - font = CreateFontIndirectW(&ncm.lfMessageFont); - if (font == NULL) - panic("(test program) error creating lfMessageFont HFONT"); - SendMessageW(mainwin, WM_SETFONT, (WPARAM) font, TRUE); - } + panic("(test program) error creating main window"); ShowWindow(mainwin, SW_SHOWDEFAULT); if (UpdateWindow(mainwin) == 0) panic("(test program) error updating window"); |
