int main(void) { WNDCLASSW wc; HWND mainwin; MSG msg; CoInitialize(NULL); initDraw(); hInstance = GetModuleHandle(NULL); h.ah.Draw = handlerDraw; h.ah.HScrollMax = handlerHScrollMax; h.ah.VScrollMax = handlerVScrollMax; h.ah.RedrawOnResize = handlerRedrawOnResize; h.ah.MouseEvent = handlerMouseEvent; h.ah.DragBroken = handlerDragBroken; h.ah.KeyEvent = handlerKeyEvent; registerAreaClass(); ZeroMemory(&wc, sizeof (WNDCLASSW)); wc.lpszClassName = L"mainwin"; wc.lpfnWndProc = wndproc; wc.hInstance = hInstance; wc.hbrBackground = (HBRUSH) (COLOR_BTNFACE + 1); RegisterClassW(&wc); mainwin = CreateWindowExW(0, L"mainwin", L"mainwin", WS_OVERLAPPEDWINDOW, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, NULL, NULL, hInstance, NULL); area = makeArea(0, WS_CHILD | WS_VISIBLE, 0, 0, 0, 0, mainwin, (uiAreaHandler *) (&h)); nhspinb = CreateWindowExW(WS_EX_CLIENTEDGE, L"edit", L"0", ES_NUMBER | WS_CHILD | WS_VISIBLE, 0, 0, 100, 100, mainwin, NULL, hInstance, NULL); nvspinb = CreateWindowExW(WS_EX_CLIENTEDGE, L"edit", L"0", ES_NUMBER | WS_CHILD | WS_VISIBLE, 0, 0, 100, 100, mainwin, NULL, hInstance, NULL); // initial state repos(mainwin); areaUpdateScroll(area); ShowWindow(mainwin, SW_SHOWDEFAULT); UpdateWindow(mainwin); extern BOOL processAreaMessage(MSG *); while (GetMessage(&msg, NULL, 0, 0)) { if (processAreaMessage(&msg)) continue; TranslateMessage(&msg); DispatchMessage(&msg); } uninitDraw(); CoUninitialize(); return 0; }
const char *uiInit(uiInitOptions *o) { STARTUPINFOW si; const char *ce; HICON hDefaultIcon; HCURSOR hDefaultCursor; NONCLIENTMETRICSW ncm; INITCOMMONCONTROLSEX icc; HRESULT hr; options = *o; initAlloc(); nCmdShow = SW_SHOWDEFAULT; GetStartupInfoW(&si); if ((si.dwFlags & STARTF_USESHOWWINDOW) != 0) nCmdShow = si.wShowWindow; hDefaultIcon = LoadIconW(NULL, IDI_APPLICATION); if (hDefaultIcon == NULL) return ieLastErr("loading default icon for window classes"); hDefaultCursor = LoadCursorW(NULL, IDC_ARROW); if (hDefaultCursor == NULL) return ieLastErr("loading default cursor for window classes"); ce = initUtilWindow(hDefaultIcon, hDefaultCursor); if (ce != NULL) return ieLastErr("TODO use ce here"); if (registerWindowClass(hDefaultIcon, hDefaultCursor) == 0) return ieLastErr("registering uiWindow window class"); ZeroMemory(&ncm, sizeof (NONCLIENTMETRICSW)); ncm.cbSize = sizeof (NONCLIENTMETRICSW); if (SystemParametersInfoW(SPI_GETNONCLIENTMETRICS, sizeof (NONCLIENTMETRICSW), &ncm, sizeof (NONCLIENTMETRICSW)) == 0) return ieLastErr("getting default fonts"); hMessageFont = CreateFontIndirectW(&(ncm.lfMessageFont)); if (hMessageFont == NULL) return ieLastErr("loading default messagebox font; this is the default UI font"); // TODO rewrite this error message if (initContainer(hDefaultIcon, hDefaultCursor) == 0) return ieLastErr("initializing uiMakeContainer() window class"); hollowBrush = (HBRUSH) GetStockObject(HOLLOW_BRUSH); if (hollowBrush == NULL) return ieLastErr("getting hollow brush"); ZeroMemory(&icc, sizeof (INITCOMMONCONTROLSEX)); icc.dwSize = sizeof (INITCOMMONCONTROLSEX); icc.dwICC = wantedICCClasses; if (InitCommonControlsEx(&icc) == 0) return ieLastErr("initializing Common Controls"); hr = CoInitialize(NULL); if (hr != S_OK && hr != S_FALSE) return ieHRESULT("initializing COM", hr); // TODO initialize COM security // TODO (windows vista) turn off COM exception handling hr = initDraw(); if (hr != S_OK) return ieHRESULT("initializing Direct2D", hr); hr = initDrawText(); if (hr != S_OK) return ieHRESULT("initializing DirectWrite", hr); if (registerAreaClass(hDefaultIcon, hDefaultCursor) == 0) return ieLastErr("registering uiArea window class"); if (registerMessageFilter() == 0) return ieLastErr("registering libui message filter"); if (registerD2DScratchClass(hDefaultIcon, hDefaultCursor) == 0) return ieLastErr("initializing D2D scratch window class"); return NULL; }