aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJohn Ankarström <john@ankarstrom.se>2022-04-02 23:57:16 +0200
committerJohn Ankarström <john@ankarstrom.se>2022-04-02 23:57:16 +0200
commit279b0c7764c3e49db72606c25dd7151137d66b70 (patch)
tree9b79c76f2aaa156de7f03aa52635f123ac0ad305
parent7e52a92bac667723885f689a1310d93144bd6a11 (diff)
downloadEpisodeBrowser-279b0c7764c3e49db72606c25dd7151137d66b70.tar.gz
Move initialization to WM_CREATE.
WM_CREATE is sent as soon as the window is created. This means that it is not a good idea to set window-specific variables in the code following CreateWindow. Instead, they should be set in the window procedure's response to WM_CREATE.
-rw-r--r--c/common.c20
-rw-r--r--c/defs.h8
-rw-r--r--c/main.c33
3 files changed, 27 insertions, 34 deletions
diff --git a/c/common.c b/c/common.c
index 7ee27ff..a056993 100644
--- a/c/common.c
+++ b/c/common.c
@@ -4,26 +4,6 @@
#include "resource.h"
#include "defs.h"
-/* Scale integer according to DPI. */
-int Dpi(int i)
-{
- extern int IDPI;
-
- if (IDPI == -1) {
- HMODULE hModule;
- FARPROC GetDpiForWindow;
- extern HWND HWnd;
- IDPI = 96;
- hModule = LoadLibrary(TEXT("User32.dll"));
- if (hModule && (GetDpiForWindow = GetProcAddress(hModule, "GetDpiForWindow"))) {
- IDPI = GetDpiForWindow(HWnd);
- FreeLibrary(hModule);
- }
- }
-
- return MulDiv(i, IDPI, 96);
-}
-
/* Convert normal string to TSTR using given codepage. */
TCHAR *
TszFromSz(const char *sz, int iCp)
diff --git a/c/defs.h b/c/defs.h
index 536a121..6982578 100644
--- a/c/defs.h
+++ b/c/defs.h
@@ -5,7 +5,6 @@
#include <commctrl.h>
/* common.c */
-int Dpi(int);
TCHAR *TszFromSz(const char *, int);
/* main.c */
@@ -28,6 +27,13 @@ void ElvUpdateName(LPLVITEM);
HWND DlvCreate();
void DlvShowEpisode(int);
+inline int
+Dpi(int i)
+{
+ extern int IDPI;
+ return MulDiv(i, IDPI, 96);
+}
+
#define P(m,p,a,t) if (!PL_call_predicate(NULL, PL_Q_NORMAL, \
PL_predicate(p,a,m), t))
#define Q(m,p,a,t) PL_open_query(NULL, PL_Q_NORMAL, PL_predicate(p,a,m), t)
diff --git a/c/main.c b/c/main.c
index 2adb2f2..eaca8f3 100644
--- a/c/main.c
+++ b/c/main.c
@@ -61,7 +61,6 @@ WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance,
tszErr = TEXT("Could not register window class.");
if (!RegisterClassEx(&wc)) goto f;
-
/* Create window. */
hWnd = CreateWindowEx(
@@ -74,8 +73,6 @@ WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance,
);
tszErr = TEXT("Could not create main window.");
if (!hWnd) goto f;
- SetWindowPos(hWnd, NULL, -1, -1, Dpi(510), Dpi(400), SWP_NOMOVE);
- SetupFonts();
ShowWindow(hWnd, nCmdShow);
while (GetMessage(&msg, NULL, 0, 0) > 0) {
@@ -95,6 +92,26 @@ LRESULT CALLBACK
WndProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
{
switch (uMsg) {
+ case WM_CREATE:
+ {
+ HMODULE hModule;
+ FARPROC GetDpiForWindow;
+ extern HWND HWnd, HElv;
+ HWnd = hWnd;
+ IDPI = 96;
+ hModule = LoadLibrary(TEXT("User32.dll"));
+ if (hModule && (GetDpiForWindow = GetProcAddress(hModule, "GetDpiForWindow"))) {
+ IDPI = GetDpiForWindow(HWnd);
+ FreeLibrary(hModule);
+ }
+ SetWindowPos(hWnd, NULL, -1, -1, Dpi(510), Dpi(400), SWP_NOMOVE);
+ SetupFonts();
+ DlvCreate();
+ ElvCreate();
+ UpdateTheme();
+ SetFocus(HElv);
+ break;
+ }
case WM_CLOSE:
DestroyWindow(hWnd);
break;
@@ -111,16 +128,6 @@ WndProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
lpMMI->ptMinTrackSize.y = LvHeight(HDlv)+80;
break;
}
- case WM_CREATE:
- {
- extern HWND HElv;
- HWnd = hWnd;
- DlvCreate();
- ElvCreate();
- UpdateTheme();
- SetFocus(HElv);
- break;
- }
case WM_THEMECHANGED:
UpdateTheme();
break;