Aaro Saila 4 maanden geleden
bovenliggende
commit
ef978f60f6
2 gewijzigde bestanden met toevoegingen van 20 en 47 verwijderingen
  1. 3 2
      meson.build
  2. 17 45
      src/main.c

+ 3 - 2
meson.build

@@ -2,7 +2,8 @@ project('scuffedcraft', 'c')
 
 cargs = [
   '-std=c99',
-  '-Og'
+  '-Og',
+  '-g',
   ]
 if host_machine.system() == 'windows'
   cargs += [
@@ -15,5 +16,5 @@ endif
 executable(
   'scuffedcraft',
   './src/main.c',
-  c_args: cargs
+  c_args: cargs,
   )

+ 17 - 45
src/main.c

@@ -2,6 +2,7 @@
 #include <stdio.h>
 #include <wchar.h>
 #include <windows.h>
+#include <windowsx.h>
 #include <winuser.h>
 
 // int _main() {
@@ -32,7 +33,23 @@ LRESULT CALLBACK WindowProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
 
     switch (uMsg) {
     case WM_LBUTTONDOWN:
+    {
         printf("State: msg: %s, num: %d\n", pState->msg, pState->num);
+
+        printf("lParam: %llx\n", lParam);
+        int mouse_x = GET_X_LPARAM(lParam);
+        printf("mouse_x: %x\n", mouse_x);
+        int mouse_y = GET_Y_LPARAM(lParam);
+        printf("mouse_y: %x\n", mouse_y);
+        printf("x: %d y: %d\n", mouse_x, mouse_y);
+
+        return 0;
+    }
+
+    case WM_KEYDOWN:
+        if (wParam == VK_ESCAPE) {
+            PostQuitMessage(0);
+        }
         return 0;
 
     case WM_DESTROY:
@@ -74,49 +91,6 @@ LRESULT CALLBACK WindowProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
     return DefWindowProc(hwnd, uMsg, wParam, lParam);
 }
 
-void show_open_dialog(HWND hwnd) {
-    HRESULT hr = CoInitializeEx(NULL, COINIT_APARTMENTTHREADED | COINIT_DISABLE_OLE1DDE);
-    if (FAILED(hr)) {
-        printf("COM init failed\n");
-        exit(1);
-    }
-
-#define OPEN_DIALOG_CHECK_ERR(msg) \
-    if (FAILED((hr))) { \
-        printf("%s:%d: %s", __FILE__, __LINE__, (msg)); \
-        exit(1); \
-    }
-
-    IFileOpenDialog* pFileOpen;
-    hr = CoCreateInstance(
-        &CLSID_FileOpenDialog,
-        NULL,
-        CLSCTX_ALL,
-        &IID_IFileOpenDialog,
-        (void**) &pFileOpen
-    );
-    OPEN_DIALOG_CHECK_ERR("ERROR: Failed to create FileOpenDialog\n");
-
-    hr = pFileOpen->lpVtbl->Show(pFileOpen, hwnd);
-    OPEN_DIALOG_CHECK_ERR("ERROR: Failed to show FileOpenDialog\n");
-
-    IShellItem* pItem;
-    hr = pFileOpen->lpVtbl->GetResult(pFileOpen, &pItem);
-    OPEN_DIALOG_CHECK_ERR("ERROR: Failed to get open file dialog result.\n")
-
-    PWSTR pszFilePath;
-    hr = pItem->lpVtbl->GetDisplayName(pItem, SIGDN_FILESYSPATH, &pszFilePath);
-    OPEN_DIALOG_CHECK_ERR("ERROR: Failed to get path\n");
-
-    MessageBox(NULL, pszFilePath, L"File Path", MB_OK);
-
-    CoTaskMemFree(pszFilePath);
-    pItem->lpVtbl->Release(pItem);
-    pFileOpen->lpVtbl->Release(pFileOpen);
-
-    CoUninitialize();
-}
-
 int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR pCmdLine, int nCmdShow) {
     // Register the window class
     const wchar_t* CLASS_NAME = L"Sample Window Class";
@@ -156,8 +130,6 @@ int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR pCmdLine,
 
     ShowWindow(hwnd, nCmdShow);
 
-    show_open_dialog(hwnd);
-
     // Message loop
 
     MSG msg = { };