diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/GNUmakefile | 6 | ||||
-rw-r--r-- | src/common.cpp | 66 | ||||
-rw-r--r-- | src/debug.cpp | 2 | ||||
-rw-r--r-- | src/w32dlib/common.h | 27 |
4 files changed, 83 insertions, 18 deletions
diff --git a/src/GNUmakefile b/src/GNUmakefile index 88fc7a0..3d6115b 100644 --- a/src/GNUmakefile +++ b/src/GNUmakefile @@ -18,7 +18,7 @@ # # ------------------------------------------------------------------------- # -# $Id: GNUmakefile,v 1.11 2005-04-17 00:34:01 ianc Exp $ +# $Id: GNUmakefile,v 1.12 2005-04-18 00:52:51 ianc Exp $ # @@ -36,9 +36,9 @@ INSTALLDIR = /usr/local CREATECONF = 1 # Uncomment this if you want a debug build. Note that debug goes to a file -# called debug.out in the pwd. +# called c:\debug.out # -#DEBUG = -g -DW32D_DEBUG +# DEBUG = -g -DW32D_DEBUG # # **************************************** END OF CONFIGURATION diff --git a/src/common.cpp b/src/common.cpp index 59c7695..3cd84a7 100644 --- a/src/common.cpp +++ b/src/common.cpp @@ -217,19 +217,6 @@ bool Common::SelectDir(HWND parent, const char *title, std::string& path) // ------------------------------------------------------------ // -int CALLBACK Common::BrowseCallback(HWND w, UINT u, LPARAM p1, LPARAM p2) -{ - if (u==BFFM_INITIALIZED) - { - PostMessage(w,BFFM_SETSELECTION,TRUE,p2); - } - - return 0; -} - - -// ------------------------------------------------------------ -// std::string Common::GetOSError() { std::string res; @@ -262,6 +249,59 @@ HINSTANCE Common::GetInstance() } +// ------------------------------------------------------------ +// +HWND Common::GetAppWindow() +{ + EnumData data; + + data.handle=0; + data.procid=GetCurrentProcessId(); + + W32DEBUGOUT("Looking for window for process " << data.procid); + + EnumWindows(EnumCallback,reinterpret_cast<LPARAM>(&data)); + + W32DEBUGOUT("Got window handle " << data.handle << + " for process " << data.procid); + + return data.handle; +} + + +// ------------------------------------------------------------ +// +int CALLBACK Common::BrowseCallback(HWND w, UINT u, LPARAM p1, LPARAM p2) +{ + if (u==BFFM_INITIALIZED) + { + PostMessage(w,BFFM_SETSELECTION,TRUE,p2); + } + + return 0; +} + + +// ------------------------------------------------------------ +// +BOOL CALLBACK Common::EnumCallback(HWND w, LPARAM p) +{ + DWORD id; + EnumData *data=reinterpret_cast<EnumData*>(p); + + GetWindowThreadProcessId(w,&id); + + if (id==data->procid) + { + data->handle=w; + return FALSE; + } + + return TRUE; +} + + }; // namespace W32DLib + // END OF FILE diff --git a/src/debug.cpp b/src/debug.cpp index f234442..7885d77 100644 --- a/src/debug.cpp +++ b/src/debug.cpp @@ -232,7 +232,7 @@ void W32Debug(const char *func, const char *file, const char *msg) if (!fp) { - fp=fopen("debug.out","w"); + fp=fopen("c:/debug.out","w"); setbuf(fp,0); } diff --git a/src/w32dlib/common.h b/src/w32dlib/common.h index de5364f..67b7b47 100644 --- a/src/w32dlib/common.h +++ b/src/w32dlib/common.h @@ -172,15 +172,40 @@ namespace W32DLib /// \brief Get an HINSTANCE. /// + /// This should (though it hasn't been proved in all cases) get the + /// apropriate HINSTANCE for the application or DLL the library has + /// be linked into. + /// /// \return The HINSTANCE /// static HINSTANCE GetInstance(); + /// \brief Get an application's top-level window. + /// + /// This finds the top-level window for the application. This is + /// mainly a helper for when you're in a DLL, cannot access the + /// applications window handle any other way and wish to display a + /// modal Dialog. + /// + /// \return The window handle, or zero for error or the window couldn't + /// be found. + /// + static HWND GetAppWindow(); + + private: Common(); - static CALLBACK int BrowseCallback(HWND w,UINT u,LPARAM p1,LPARAM p2); + struct EnumData + { + HWND handle; + DWORD procid; + }; + + static int CALLBACK BrowseCallback(HWND w,UINT u,LPARAM p1,LPARAM p2); + + static BOOL CALLBACK EnumCallback(HWND w,LPARAM p); }; // class Common |