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 /wintable/test.c | |
| 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.
Diffstat (limited to 'wintable/test.c')
| -rw-r--r-- | wintable/test.c | 86 |
1 files changed, 67 insertions, 19 deletions
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"); |
