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.

This commit is contained in:
Pietro Gagliardi 2015-01-07 16:24:17 -05:00
parent 7c473a9fdc
commit 3b81ebab98
3 changed files with 74 additions and 21 deletions

View File

@ -148,6 +148,7 @@ static void deftablePanic(const char *msg, DWORD lastError)
DebugBreak(); DebugBreak();
} }
// TODO have hInstance passed in
void initTable(void (*panicfunc)(const char *msg, DWORD lastError), BOOL (*WINAPI tme)(LPTRACKMOUSEEVENT)) void initTable(void (*panicfunc)(const char *msg, DWORD lastError), BOOL (*WINAPI tme)(LPTRACKMOUSEEVENT))
{ {
WNDCLASSW wc; WNDCLASSW wc;

View File

@ -109,6 +109,10 @@ HANDLER(mouseDownSelectHandler)
{ {
struct rowcol rc; 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); rc = lParamToRowColumn(t, lParam);
// don't check if lParamToRowColumn() returned row -1 or column -1; we want deselection behavior // don't check if lParamToRowColumn() returned row -1 or column -1; we want deselection behavior
doselect(t, rc.row, rc.column); doselect(t, rc.row, rc.column);

View File

@ -8,31 +8,23 @@ void mkbitmap(void);
#include "main.h" #include "main.h"
int main(int argc, char *argv[]) HWND tablehwnd = NULL;
{ BOOL msgfont = FALSE;
HWND mainwin;
MSG msg;
INITCOMMONCONTROLSEX icc;
mkbitmap(); BOOL mainwinCreate(HWND hwnd, LPCREATESTRUCT lpcs)
ZeroMemory(&icc, sizeof (INITCOMMONCONTROLSEX)); {
icc.dwSize = sizeof (INITCOMMONCONTROLSEX); tablehwnd = CreateWindowExW(0,
icc.dwICC = ICC_LISTVIEW_CLASSES;
if (InitCommonControlsEx(&icc) == 0)
panic("(test program) error initializing comctl32.dll");
initTable(NULL, _TrackMouseEvent);
mainwin = CreateWindowExW(0,
tableWindowClass, L"Main Window", tableWindowClass, L"Main Window",
WS_OVERLAPPEDWINDOW | WS_HSCROLL | WS_VSCROLL, WS_CHILD | WS_VISIBLE | WS_HSCROLL | WS_VSCROLL,
CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT,
400, 400, 400, 400,
NULL, NULL, GetModuleHandle(NULL), NULL); hwnd, NULL, lpcs->hInstance, NULL);
if (mainwin == NULL) if (tablehwnd == NULL)
panic("(test program) error creating Table"); panic("(test program) error creating Table");
SendMessageW(mainwin, tableAddColumn, tableColumnText, (LPARAM) L"Column"); SendMessageW(tablehwnd, tableAddColumn, tableColumnText, (LPARAM) L"Column");
SendMessageW(mainwin, tableAddColumn, tableColumnImage, (LPARAM) L"Column 2"); SendMessageW(tablehwnd, tableAddColumn, tableColumnImage, (LPARAM) L"Column 2");
SendMessageW(mainwin, tableAddColumn, tableColumnCheckbox, (LPARAM) L"Column 3"); SendMessageW(tablehwnd, tableAddColumn, tableColumnCheckbox, (LPARAM) L"Column 3");
if (argc > 1) { if (msgfont) {
NONCLIENTMETRICSW ncm; NONCLIENTMETRICSW ncm;
HFONT font; HFONT font;
@ -43,8 +35,64 @@ int main(int argc, char *argv[])
font = CreateFontIndirectW(&ncm.lfMessageFont); font = CreateFontIndirectW(&ncm.lfMessageFont);
if (font == NULL) if (font == NULL)
panic("(test program) error creating lfMessageFont HFONT"); 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); ShowWindow(mainwin, SW_SHOWDEFAULT);
if (UpdateWindow(mainwin) == 0) if (UpdateWindow(mainwin) == 0)
panic("(test program) error updating window"); panic("(test program) error updating window");