aboutsummaryrefslogtreecommitdiff
path: root/win.c
diff options
context:
space:
mode:
Diffstat (limited to 'win.c')
-rw-r--r--win.c259
1 files changed, 159 insertions, 100 deletions
diff --git a/win.c b/win.c
index 8764092..b45a012 100644
--- a/win.c
+++ b/win.c
@@ -1,6 +1,7 @@
#include <windows.h>
#include <TCHAR.H>
#include <commctrl.h>
+#include <uxtheme.h>
#include <stdio.h>
#include <string.h>
#include <SWI-Prolog.h>
@@ -10,14 +11,18 @@
HFONT g_GUIFont;
-static int Attach(void);
+static LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM);
static INT_PTR CALLBACK AboutDlgProc(HWND, UINT, WPARAM, LPARAM);
+static void CreateListView(HWND);
+static LRESULT HandleListViewNotify(HWND, NMLISTVIEW *);
+
static HFONT GetGUIFont();
+static TCHAR *TSZFromSZ(char *, int);
+
+static int Attach(void);
static void UpdateName(HWND, int);
static void UpdateList(HWND);
static void ShowEpisode(HWND, int);
-static TCHAR *TSZFromSZ(int, char *);
-static LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM);
/*
int main(int argc, char *argv[])
@@ -43,7 +48,7 @@ WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance,
LPSTR lpCmdLine, INT nCmdShow)
{
char *rgArgs[2];
- HWND hwnd;
+ HWND hWnd;
MSG msg;
INITCOMMONCONTROLSEX icc;
WNDCLASSEX wc;
@@ -81,7 +86,7 @@ WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance,
RegisterClassEx(&wc);
- hwnd = CreateWindowEx(
+ hWnd = CreateWindowEx(
0,
CLASSNAME,
TEXT("Episode Browser"),
@@ -94,10 +99,10 @@ WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance,
NULL
);
- if (!hwnd)
+ if (!hWnd)
return 0;
- ShowWindow(hwnd, nCmdShow);
+ ShowWindow(hWnd, nCmdShow);
while (GetMessage(&msg, NULL, 0, 0) > 0) {
TranslateMessage(&msg);
@@ -108,11 +113,11 @@ WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance,
}
LRESULT CALLBACK
-WndProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
+WndProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
{
switch (uMsg) {
case WM_CLOSE:
- DestroyWindow(hwnd);
+ DestroyWindow(hWnd);
break;
case WM_DESTROY:
PostQuitMessage(0);
@@ -120,88 +125,59 @@ WndProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
case WM_COMMAND:
switch (LOWORD(wParam)) {
case ID_FILE_EXIT:
- PostMessage(hwnd, WM_CLOSE, 0, 0);
+ PostMessage(hWnd, WM_CLOSE, 0, 0);
break;
case ID_FILE_ABOUT:
DialogBox(
GetModuleHandle(NULL),
MAKEINTRESOURCE(IDD_ABOUT),
- hwnd,
+ hWnd,
AboutDlgProc
);
break;
}
break;
case WM_CREATE:
- {
- HWND hListView;
- LVCOLUMN lvc;
-
- hListView = CreateWindowEx(
- 0,
- WC_LISTVIEW,
- TEXT(""),
- WS_CHILD|WS_VISIBLE|WS_VSCROLL|LVS_REPORT,
- 0, 0, 100, 100,
- hwnd,
- (HMENU)IDC_LISTVIEW,
- GetModuleHandle(NULL),
- NULL
- );
-
- SendMessage(hListView,LVM_SETEXTENDEDLISTVIEWSTYLE,
- 0, LVS_EX_FULLROWSELECT);
-
- SendMessage(hListView, WM_SETFONT,
- (WPARAM)g_GUIFont, MAKELPARAM(FALSE, 0));
-
- lvc.mask = LVCF_WIDTH|LVCF_TEXT|LVCF_SUBITEM;
-
- lvc.iSubItem = 0;
- lvc.pszText = TEXT("#");
- lvc.cx = 40;
- ListView_InsertColumn(hListView, 0, &lvc);
-
- lvc.iSubItem = 1;
- lvc.pszText = TEXT("Title");
- lvc.cx = 500;
- ListView_InsertColumn(hListView, 1, &lvc);
-
- UpdateList(hListView);
- }
+ CreateListView(hWnd);
break;
case WM_SIZE:
{
HWND hListView;
RECT rc;
- GetClientRect(hwnd, &rc);
- hListView = GetDlgItem(hwnd, IDC_LISTVIEW);
+ GetClientRect(hWnd, &rc);
+ hListView = GetDlgItem(hWnd, IDC_LISTVIEW);
MoveWindow(hListView, 0, 0,
rc.right, rc.bottom,
TRUE);
}
break;
+ case WM_NOTIFY:
+ switch (((NMHDR *)lParam)->idFrom) {
+ case IDC_LISTVIEW:
+ return HandleListViewNotify(hWnd, (NMLISTVIEW *)lParam);
+ }
+ break;
default:
- return DefWindowProc(hwnd, uMsg, wParam, lParam);
+ return DefWindowProc(hWnd, uMsg, wParam, lParam);
}
return 0;
}
INT_PTR CALLBACK
-AboutDlgProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
+AboutDlgProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
{
switch (uMsg) {
case WM_INITDIALOG:
return TRUE;
case WM_CLOSE:
- EndDialog(hwnd, IDOK);
+ EndDialog(hWnd, IDOK);
break;
case WM_COMMAND:
switch (LOWORD(wParam)) {
case IDOK:
- EndDialog(hwnd, IDOK);
+ EndDialog(hWnd, IDOK);
break;
}
break;
@@ -212,6 +188,125 @@ AboutDlgProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
return TRUE;
}
+void
+CreateListView(HWND hWnd)
+{
+ HMODULE hModule;
+ HWND hListView;
+ LVCOLUMN lvc;
+
+ hListView = CreateWindowEx(
+ 0,
+ WC_LISTVIEW,
+ TEXT(""),
+ WS_CHILD|WS_VISIBLE|WS_VSCROLL|LVS_REPORT,
+ 0, 0, 0, 0,
+ hWnd,
+ (HMENU)IDC_LISTVIEW,
+ GetModuleHandle(NULL),
+ NULL
+ );
+
+ SendMessage(hListView,LVM_SETEXTENDEDLISTVIEWSTYLE,
+ 0, LVS_EX_FULLROWSELECT);
+
+ SendMessage(hListView, WM_SETFONT,
+ (WPARAM)g_GUIFont, MAKELPARAM(FALSE, 0));
+
+ hModule = LoadLibrary(TEXT("uxtheme.dll"));
+ if (hModule && GetProcAddress(hModule, "SetWindowTheme")) {
+ SendMessage(hListView, WM_CHANGEUISTATE,
+ MAKEWPARAM(UIS_SET, UISF_HIDEFOCUS), 0);
+ SetWindowTheme(hListView, TEXT("Explorer"), NULL);
+ }
+
+ lvc.mask = LVCF_WIDTH|LVCF_TEXT|LVCF_SUBITEM;
+
+ lvc.iSubItem = 0;
+ lvc.pszText = TEXT("#");
+ lvc.cx = 40;
+ ListView_InsertColumn(hListView, 0, &lvc);
+
+ lvc.iSubItem = 1;
+ lvc.pszText = TEXT("Title");
+ lvc.cx = 500;
+ ListView_InsertColumn(hListView, 1, &lvc);
+
+ UpdateList(hWnd);
+}
+
+LRESULT
+HandleListViewNotify(HWND hWnd, NMLISTVIEW *pNmListView)
+{
+ switch (pNmListView->hdr.code) {
+ case NM_CUSTOMDRAW:
+ {
+ NMLVCUSTOMDRAW *pLvCd;
+ pLvCd = (NMLVCUSTOMDRAW *)pNmListView;
+ switch (pLvCd->nmcd.dwDrawStage) {
+ case CDDS_PREPAINT:
+ //return CDRF_NOTIFYITEMDRAW;
+ break;
+ case CDDS_ITEMPREPAINT:
+
+ break;
+ }
+ }
+ break;
+ }
+
+ return 0;
+}
+
+/***/
+
+HFONT
+GetGUIFont()
+{
+ HMODULE hModule;
+
+ hModule = LoadLibrary(TEXT("User32.dll"));
+ if (hModule && GetProcAddress(hModule, "SystemParametersInfoW")) {
+ NONCLIENTMETRICS m;
+
+ m.cbSize = sizeof(NONCLIENTMETRICS);
+ SystemParametersInfo(SPI_GETNONCLIENTMETRICS,
+ sizeof(NONCLIENTMETRICS), &m, 0);
+ return CreateFontIndirect(&m.lfMessageFont);
+ } else {
+ return GetStockObject(DEFAULT_GUI_FONT);
+ }
+}
+
+/* Convert zero-terminated non-wide (multi-byte) string to
+ * zero-terminated wide/non-wide string depending on UNICODE. */
+TCHAR *
+TSZFromSZ(char *sz, int iCp)
+{
+ TCHAR *tsz;
+
+#ifdef UNICODE
+ int cbMultiByte, cchWideChar;
+
+ cbMultiByte = strlen(sz)+1;
+ cchWideChar = MultiByteToWideChar(iCp, 0, sz, cbMultiByte, NULL, 0);
+ tsz = malloc(cchWideChar*sizeof(WCHAR));
+ if (!tsz)
+ return NULL;
+ if (!MultiByteToWideChar(iCp, 0, sz, cbMultiByte, tsz, cchWideChar))
+ return NULL;
+#else
+ tsz = malloc(strlen(sz)+1);
+ if (!tsz)
+ return NULL;
+ strcpy(tsz, sz);
+#endif
+
+ return tsz;
+}
+
+/***/
+
/* Attach persistent databases. */
int
Attach()
@@ -233,24 +328,9 @@ Attach()
return 1;
}
-HFONT
-GetGUIFont()
-{
-#ifndef WIN9X
- NONCLIENTMETRICS m;
-
- m.cbSize = sizeof(NONCLIENTMETRICS);
- SystemParametersInfo(SPI_GETNONCLIENTMETRICS, sizeof(NONCLIENTMETRICS),
- &m, 0);
- return CreateFontIndirect(&m.lfMessageFont);
-#else
- return GetStockObject(DEFAULT_GUI_FONT);
-#endif
-}
-
/* Show episode data. */
void
-ShowEpisode(HWND hwnd, int iEpisode)
+ShowEpisode(HWND hWnd, int iEpisode)
{
int r;
term_t t;
@@ -295,33 +375,9 @@ ShowEpisode(HWND hwnd, int iEpisode)
}
}
-TCHAR *
-TSZFromSZ(int iCp, char *sz)
-{
- TCHAR *tsz;
-
-#ifdef UNICODE
- int cb;
-
- cb = MultiByteToWideChar(iCp, 0, sz, -1, NULL, 0);
- tsz = malloc(cb*sizeof(wchar_t));
- if (!tsz)
- return NULL;
- if (!MultiByteToWideChar(iCp, 0, sz, -1, tsz, cb))
- return NULL;
-#else
- tsz = malloc(strlen(sz)+1);
- if (!tsz)
- return NULL;
- strcpy(tsz, sz);
-#endif
-
- return tsz;
-}
-
/* Update episode name. */
void
-UpdateName(HWND hwnd, int iEpisode)
+UpdateName(HWND hWnd, int iEpisode)
{
char *szName;
term_t t;
@@ -342,16 +398,16 @@ UpdateName(HWND hwnd, int iEpisode)
/* Update episode list. */
void
-UpdateList(HWND hListView)
+UpdateList(HWND hWnd)
{
+ HWND hListView;
LVITEM lviEpisode, lviName;
qid_t q;
term_t t;
- lviEpisode.mask = LVIF_TEXT | LVIF_STATE | LVIF_PARAM;
- lviEpisode.state = 0;
- lviEpisode.stateMask = 0;
+ hListView = GetDlgItem(hWnd, IDC_LISTVIEW);
+ lviEpisode.mask = LVIF_TEXT|LVIF_PARAM;
lviName.mask = LVIF_TEXT;
t = PL_new_term_refs(2);
@@ -386,7 +442,7 @@ UpdateList(HWND hListView)
tszName = NULL;
if (r && PL_get_atom_chars(t2+1, &szName)) {
- tszName = TSZFromSZ(CP_UTF8, szName);
+ tszName = TSZFromSZ(szName, CP_UTF8);
if (!tszName)
continue;
}
@@ -400,7 +456,7 @@ UpdateList(HWND hListView)
/* Insert item. */
- lviEpisode.mask = LVIF_TEXT | LVIF_STATE | LVIF_PARAM;
+ lviEpisode.mask = LVIF_TEXT|LVIF_STATE|LVIF_PARAM;
lviEpisode.iItem = i;
lviEpisode.iSubItem = 0;
lviEpisode.pszText = tszEpisode;
@@ -413,6 +469,9 @@ UpdateList(HWND hListView)
lviName.pszText = tszName;
ListView_SetItem(hListView, &lviName);
}
+
+ free(tszName);
+ free(tszEpisode);
}
close: