update
This commit is contained in:
@@ -2,7 +2,8 @@ project('scuffedcraft', 'c')
|
|||||||
|
|
||||||
cargs = [
|
cargs = [
|
||||||
'-std=c99',
|
'-std=c99',
|
||||||
'-Og'
|
'-Og',
|
||||||
|
'-g',
|
||||||
]
|
]
|
||||||
if host_machine.system() == 'windows'
|
if host_machine.system() == 'windows'
|
||||||
cargs += [
|
cargs += [
|
||||||
@@ -15,5 +16,5 @@ endif
|
|||||||
executable(
|
executable(
|
||||||
'scuffedcraft',
|
'scuffedcraft',
|
||||||
'./src/main.c',
|
'./src/main.c',
|
||||||
c_args: cargs
|
c_args: cargs,
|
||||||
)
|
)
|
||||||
|
|||||||
62
src/main.c
62
src/main.c
@@ -2,6 +2,7 @@
|
|||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <wchar.h>
|
#include <wchar.h>
|
||||||
#include <windows.h>
|
#include <windows.h>
|
||||||
|
#include <windowsx.h>
|
||||||
#include <winuser.h>
|
#include <winuser.h>
|
||||||
|
|
||||||
// int _main() {
|
// int _main() {
|
||||||
@@ -32,7 +33,23 @@ LRESULT CALLBACK WindowProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
|
|||||||
|
|
||||||
switch (uMsg) {
|
switch (uMsg) {
|
||||||
case WM_LBUTTONDOWN:
|
case WM_LBUTTONDOWN:
|
||||||
|
{
|
||||||
printf("State: msg: %s, num: %d\n", pState->msg, pState->num);
|
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;
|
return 0;
|
||||||
|
|
||||||
case WM_DESTROY:
|
case WM_DESTROY:
|
||||||
@@ -74,49 +91,6 @@ LRESULT CALLBACK WindowProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
|
|||||||
return DefWindowProc(hwnd, uMsg, wParam, 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) {
|
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR pCmdLine, int nCmdShow) {
|
||||||
// Register the window class
|
// Register the window class
|
||||||
const wchar_t* CLASS_NAME = L"Sample 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);
|
ShowWindow(hwnd, nCmdShow);
|
||||||
|
|
||||||
show_open_dialog(hwnd);
|
|
||||||
|
|
||||||
// Message loop
|
// Message loop
|
||||||
|
|
||||||
MSG msg = { };
|
MSG msg = { };
|
||||||
|
|||||||
Reference in New Issue
Block a user