|
@@ -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 = { };
|