wxDisplayFactoryMSW::wxDisplayFactoryMSW() { if ( gs_MonitorFromPoint==NULL || gs_MonitorFromWindow==NULL || gs_GetMonitorInfo==NULL || gs_EnumDisplayMonitors==NULL ) { // First initialization, or last initialization failed. wxDynamicLibrary dllDisplay(displayDllName, wxDL_VERBATIM | wxDL_QUIET); wxDL_INIT_FUNC(gs_, MonitorFromPoint, dllDisplay); wxDL_INIT_FUNC(gs_, MonitorFromWindow, dllDisplay); wxDL_INIT_FUNC_AW(gs_, GetMonitorInfo, dllDisplay); wxDL_INIT_FUNC(gs_, EnumDisplayMonitors, dllDisplay); // we can safely let dllDisplay go out of scope, the DLL itself will // still remain loaded as all programs link to it statically anyhow } if ( gs_MonitorFromPoint==NULL || gs_MonitorFromWindow==NULL || gs_GetMonitorInfo==NULL || gs_EnumDisplayMonitors==NULL ) return; // enumerate all displays if ( !gs_EnumDisplayMonitors(NULL, NULL, MultimonEnumProc, (LPARAM)this) ) { wxLogLastError(wxT("EnumDisplayMonitors")); } }
bool wxSocketMSWManager::OnInit() { static LPCTSTR pclassname = NULL; int i; /* Create internal window for event notifications */ hWin = wxCreateHiddenWindow(&pclassname, CLASSNAME, wxSocket_Internal_WinProc); if (!hWin) return false; /* Initialize socket list */ for (i = 0; i < MAXSOCKETS; i++) { socketList[i] = NULL; } firstAvailable = 0; // we don't link with wsock32.dll (or ws2 in CE case) statically to avoid // dependencies on it for all the application using wx even if they don't use // sockets #ifdef __WXWINCE__ #define WINSOCK_DLL_NAME wxT("ws2.dll") #else #define WINSOCK_DLL_NAME wxT("wsock32.dll") #endif gs_wsock32dll.Load(WINSOCK_DLL_NAME, wxDL_VERBATIM | wxDL_QUIET); if ( !gs_wsock32dll.IsLoaded() ) return false; #ifndef __WXWINCE__ wxDL_INIT_FUNC(gs_, WSAAsyncSelect, gs_wsock32dll); if ( !gs_WSAAsyncSelect ) return false; #else wxDL_INIT_FUNC(gs_, WSAEventSelect, gs_wsock32dll); if ( !gs_WSAEventSelect ) return false; wxDL_INIT_FUNC(gs_, WSACreateEvent, gs_wsock32dll); if ( !gs_WSACreateEvent ) return false; wxDL_INIT_FUNC(gs_, WSAWaitForMultipleEvents, gs_wsock32dll); if ( !gs_WSAWaitForMultipleEvents ) return false; wxDL_INIT_FUNC(gs_, WSAEnumNetworkEvents, gs_wsock32dll); if ( !gs_WSAEnumNetworkEvents ) return false; currSocket = 0; #endif // !__WXWINCE__/__WXWINCE__ // finally initialize WinSock WSADATA wsaData; return WSAStartup((1 << 8) | 1, &wsaData) == 0; }
wxDisplayFactoryDirectDraw::wxDisplayFactoryDirectDraw() { if ( !ms_supportsMultimon ) return; m_dllDDraw.Load(wxT("ddraw.dll"), wxDL_VERBATIM | wxDL_QUIET); if ( !m_dllDDraw.IsLoaded() ) return; DirectDrawEnumerateEx_t wxDL_INIT_FUNC_AW(pfn, DirectDrawEnumerateEx, m_dllDDraw); if ( !pfnDirectDrawEnumerateEx ) return; // we can't continue without DirectDrawCreate() later, so resolve it right // now and fail the initialization if it's not available if ( !wxDL_INIT_FUNC(m_pfn, DirectDrawCreate, m_dllDDraw) ) return; if ( (*pfnDirectDrawEnumerateEx)(DDEnumExCallback, this, DDENUM_ATTACHEDSECONDARYDEVICES) != DD_OK ) { wxLogLastError(wxT("DirectDrawEnumerateEx")); } }
bool wxSocketMSWManager::OnInit() { LPCTSTR pclassname = NULL; int i; /* Create internal window for event notifications */ hWin = wxCreateHiddenWindow(&pclassname, CLASSNAME, wxSocket_Internal_WinProc); if (!hWin) return false; /* Initialize socket list */ for (i = 0; i < MAXSOCKETS; i++) { socketList[i] = NULL; } firstAvailable = 0; // we don't link with wsock32.dll statically to avoid // dependencies on it for all the application using wx even if they don't use // sockets #define WINSOCK_DLL_NAME wxT("wsock32.dll") gs_wsock32dll.Load(WINSOCK_DLL_NAME, wxDL_VERBATIM | wxDL_QUIET); if ( !gs_wsock32dll.IsLoaded() ) return false; wxDL_INIT_FUNC(gs_, WSAAsyncSelect, gs_wsock32dll); if ( !gs_WSAAsyncSelect ) return false; // finally initialize WinSock WSADATA wsaData; return WSAStartup((1 << 8) | 1, &wsaData) == 0; }
bool wxTextEntry::AutoCompleteFileNames() { #ifdef HAS_AUTOCOMPLETE typedef HRESULT (WINAPI *SHAutoComplete_t)(HWND, DWORD); static SHAutoComplete_t s_pfnSHAutoComplete = (SHAutoComplete_t)-1; static wxDynamicLibrary s_dllShlwapi; if ( s_pfnSHAutoComplete == (SHAutoComplete_t)-1 ) { if ( !s_dllShlwapi.Load(wxT("shlwapi.dll"), wxDL_VERBATIM | wxDL_QUIET) ) { s_pfnSHAutoComplete = NULL; } else { wxDL_INIT_FUNC(s_pfn, SHAutoComplete, s_dllShlwapi); } } if ( !s_pfnSHAutoComplete ) return false; HRESULT hr = (*s_pfnSHAutoComplete)(GetEditHwnd(), SHACF_FILESYS_ONLY); if ( FAILED(hr) ) { wxLogApiError(wxT("SHAutoComplete()"), hr); return false; } return true; #else // !HAS_AUTOCOMPLETE return false; #endif // HAS_AUTOCOMPLETE/!HAS_AUTOCOMPLETE }
wxDisplayFactoryWin32Base::wxDisplayFactoryWin32Base() { if ( ms_supportsMultimon == -1 ) { ms_supportsMultimon = 0; wxDynamicLibrary dllDisplay(displayDllName, wxDL_VERBATIM | wxDL_QUIET); if ( (wxDL_INIT_FUNC(gs_, MonitorFromPoint, dllDisplay)) == NULL || (wxDL_INIT_FUNC(gs_, MonitorFromWindow, dllDisplay)) == NULL || (wxDL_INIT_FUNC_AW(gs_, GetMonitorInfo, dllDisplay)) == NULL ) return; ms_supportsMultimon = 1; // we can safely let dllDisplay go out of scope, the DLL itself will // still remain loaded as all programs link to it statically anyhow } }
wxDisplayFactoryMSW::wxDisplayFactoryMSW() { // This is not supposed to happen with the current code, the factory is // implicitly a singleton. wxASSERT_MSG( !ms_factory, wxS("Using more than one factory?") ); ms_factory = this; m_hiddenHwnd = NULL; m_hiddenClass = NULL; if ( gs_MonitorFromPoint==NULL || gs_MonitorFromWindow==NULL || gs_GetMonitorInfo==NULL || gs_EnumDisplayMonitors==NULL ) { // First initialization, or last initialization failed. wxDynamicLibrary dllDisplay(displayDllName, wxDL_VERBATIM | wxDL_QUIET); wxDL_INIT_FUNC(gs_, MonitorFromPoint, dllDisplay); wxDL_INIT_FUNC(gs_, MonitorFromWindow, dllDisplay); wxDL_INIT_FUNC_AW(gs_, GetMonitorInfo, dllDisplay); wxDL_INIT_FUNC(gs_, EnumDisplayMonitors, dllDisplay); // we can safely let dllDisplay go out of scope, the DLL itself will // still remain loaded as all programs link to it statically anyhow } if ( gs_MonitorFromPoint==NULL || gs_MonitorFromWindow==NULL || gs_GetMonitorInfo==NULL || gs_EnumDisplayMonitors==NULL ) return; DoRefreshMonitors(); // Also create a hidden window to listen for WM_SETTINGCHANGE that we // receive when a monitor is added to or removed from the system as we must // refresh our monitor handles information then. m_hiddenHwnd = wxCreateHiddenWindow ( &m_hiddenClass, wxT("wxDisplayHiddenWindow"), wxDisplayWndProc ); }
bool wxFrame::Create(wxWindow *parent, wxWindowID id, const wxString& title, const wxPoint& pos, const wxSize& size, long style, const wxString& name) { if ( !wxTopLevelWindow::Create(parent, id, title, pos, size, style, name) ) return false; SetOwnBackgroundColour(wxSystemSettings::GetColour(wxSYS_COLOUR_APPWORKSPACE)); #if wxUSE_TASKBARBUTTON static bool s_taskbarButtonCreatedMsgRegistered = false; if ( !s_taskbarButtonCreatedMsgRegistered ) { s_taskbarButtonCreatedMsgRegistered = true; wxMsgTaskbarButtonCreated = ::RegisterWindowMessage(wxT("TaskbarButtonCreated")); // In case the application is run elevated, allow the // TaskbarButtonCreated and WM_COMMAND messages through. #if wxUSE_DYNLIB_CLASS typedef BOOL (WINAPI *ChangeWindowMessageFilter_t)(UINT message, DWORD dwFlag); wxDynamicLibrary dllUser32(wxT("user32.dll")); ChangeWindowMessageFilter_t pfnChangeWindowMessageFilter = NULL; wxDL_INIT_FUNC(pfn, ChangeWindowMessageFilter, dllUser32); if ( pfnChangeWindowMessageFilter ) { pfnChangeWindowMessageFilter(wxMsgTaskbarButtonCreated, wxMSGFLT_ADD); pfnChangeWindowMessageFilter(WM_COMMAND, wxMSGFLT_ADD); } #else ChangeWindowMessageFilter(wxMsgTaskbarButtonCreated, wxMSGFLT_ADD); ChangeWindowMessageFilter(WM_COMMAND, wxMSGFLT_ADD); #endif // wxUSE_DYNLIB_CLASS } #endif // wxUSE_TASKBARBUTTON return true; }
wxDisplayFactoryMultimon::wxDisplayFactoryMultimon() { if ( !ms_supportsMultimon ) return; // look up EnumDisplayMonitors() which we don't need with DirectDraw // implementation EnumDisplayMonitors_t pfnEnumDisplayMonitors; { wxDynamicLibrary dllDisplay(displayDllName, wxDL_VERBATIM | wxDL_QUIET); if ( (wxDL_INIT_FUNC(pfn, EnumDisplayMonitors, dllDisplay)) == NULL ) return; } // enumerate all displays if ( !pfnEnumDisplayMonitors(NULL, NULL, MultimonEnumProc, (LPARAM)this) ) { wxLogLastError(wxT("EnumDisplayMonitors")); } }
bool wxChoice::MSWGetComboBoxInfo(tagCOMBOBOXINFO* info) const { // TODO-Win9x: Get rid of this once we officially drop support for Win9x // and just call the function directly. #if wxUSE_DYNLIB_CLASS typedef BOOL (WINAPI *GetComboBoxInfo_t)(HWND, tagCOMBOBOXINFO*); static GetComboBoxInfo_t s_pfnGetComboBoxInfo = NULL; static bool s_triedToLoad = false; if ( !s_triedToLoad ) { s_triedToLoad = true; wxLoadedDLL dllUser32("user32.dll"); wxDL_INIT_FUNC(s_pfn, GetComboBoxInfo, dllUser32); } if ( s_pfnGetComboBoxInfo ) return (*s_pfnGetComboBoxInfo)(GetHwnd(), info) != 0; #endif // wxUSE_DYNLIB_CLASS return false; }
WXHWND wxComboBox::GetEditHWNDIfAvailable() const { #if wxUSE_DYNLIB_CLASS #if defined(WINVER) && WINVER >= 0x0500 typedef BOOL (WINAPI *GetComboBoxInfo_t)(HWND, COMBOBOXINFO*); static GetComboBoxInfo_t s_pfnGetComboBoxInfo = NULL; static bool s_triedToLoad = false; if ( !s_triedToLoad ) { s_triedToLoad = true; wxLoadedDLL dllUser32("user32.dll"); wxDL_INIT_FUNC(s_pfn, GetComboBoxInfo, dllUser32); } if ( s_pfnGetComboBoxInfo ) { WinStruct<COMBOBOXINFO> info; (*s_pfnGetComboBoxInfo)(GetHwnd(), &info); return info.hwndItem; } #endif // WINVER >= 0x0500 #endif // wxUSE_DYNLIB_CLASS if (HasFlag(wxCB_SIMPLE)) { POINT pt; pt.x = pt.y = 4; return (WXHWND) ::ChildWindowFromPoint(GetHwnd(), pt); } // notice that a slightly safer alternative could be to use FindWindowEx() // but it's not available under WinCE so just take the first child for now // to keep one version of the code for all platforms and fix it later if // problems are discovered // we assume that the only child of the combobox is the edit window return (WXHWND)::GetWindow(GetHwnd(), GW_CHILD); }
int wxDirDialog::ShowIFileDialog(WXHWND owner) { HRESULT hr; wxCOMPtr<IFileDialog> fileDialog; hr = ::CoCreateInstance(CLSID_FileOpenDialog, NULL, CLSCTX_INPROC_SERVER, wxIID_PPV_ARGS(IFileDialog, &fileDialog)); if ( FAILED(hr) ) { wxLogApiError(wxS("CoCreateInstance(CLSID_FileOpenDialog)"), hr); return wxID_NONE; } // allow user to select only a file system folder hr = fileDialog->SetOptions(FOS_PICKFOLDERS | FOS_FORCEFILESYSTEM); if ( FAILED(hr) ) { wxLogApiError(wxS("IFileDialog::SetOptions"), hr); return wxID_NONE; } hr = fileDialog->SetTitle(m_message.wc_str()); if ( FAILED(hr) ) { // This error is not serious, let's just log it and continue even // without the title set. wxLogApiError(wxS("IFileDialog::SetTitle"), hr); } // set the initial path if ( !m_path.empty() ) { // We need to link SHCreateItemFromParsingName() dynamically as it's // not available on pre-Vista systems. typedef HRESULT (WINAPI *SHCreateItemFromParsingName_t)(PCWSTR, IBindCtx*, REFIID, void**); SHCreateItemFromParsingName_t pfnSHCreateItemFromParsingName = NULL; wxDynamicLibrary dllShell32; if ( dllShell32.Load(wxS("shell32.dll"), wxDL_VERBATIM | wxDL_QUIET) ) { wxDL_INIT_FUNC(pfn, SHCreateItemFromParsingName, dllShell32); } if ( !pfnSHCreateItemFromParsingName ) { wxLogLastError(wxS("SHCreateItemFromParsingName() not found")); return wxID_NONE; } wxCOMPtr<IShellItem> folder; hr = pfnSHCreateItemFromParsingName(m_path.wc_str(), NULL, wxIID_PPV_ARGS(IShellItem, &folder)); // Failing to parse the folder name is not really an error, we'll just // ignore the initial directory in this case, but we should still show // the dialog. if ( FAILED(hr) ) { if ( hr != HRESULT_FROM_WIN32(ERROR_FILE_NOT_FOUND) ) { wxLogApiError(wxS("SHCreateItemFromParsingName"), hr); return wxID_NONE; } } else // The folder was parsed correctly. { hr = fileDialog->SetFolder(folder); if ( FAILED(hr) ) { wxLogApiError(wxS("IFileDialog::SetFolder"), hr); return wxID_NONE; } } } wxString path; hr = fileDialog->Show(owner); if ( SUCCEEDED(hr) ) { wxCOMPtr<IShellItem> folder; hr = fileDialog->GetResult(&folder); if ( SUCCEEDED(hr) ) { LPOLESTR pathOLE = NULL; hr = folder->GetDisplayName(SIGDN_FILESYSPATH, &pathOLE); if ( SUCCEEDED(hr) ) { path = pathOLE; CoTaskMemFree(pathOLE); } else { wxLogApiError(wxS("IShellItem::GetDisplayName"), hr); } } else { wxLogApiError(wxS("IFileDialog::GetResult"), hr); } } else if ( hr == HRESULT_FROM_WIN32(ERROR_CANCELLED) ) { return wxID_CANCEL; // the user cancelled the dialog } else { wxLogApiError(wxS("IFileDialog::Show"), hr); } if ( path.empty() ) { // the user didn't cancel the dialog and yet the path is empty // it means there was an error, already logged by wxLogApiError() // now report the error to the user and return wxLogSysError(_("Couldn't obtain folder name"), hr); return wxID_CANCEL; } m_path = path; return wxID_OK; }
// Code from http://dslweb.nwnexus.com/~ast/dload/guicon.htm // Andrew Tucker, no license, assumed to be public domain. void wxlua_RedirectIOToDosConsole(bool alloc_new_if_needed, short max_console_lines) { int hConHandle = 0; long lStdHandle = 0; CONSOLE_SCREEN_BUFFER_INFO coninfo; memset(&coninfo, 0, sizeof(CONSOLE_SCREEN_BUFFER_INFO)); FILE *fp = 0; // we don't close this, let the OS close it when the app exits wxDynamicLibrary kernel; // Dynamically load kernel32 because AttachConsole() is not supported pre-XP BOOL attached_ok = kernel.Load(wxT("kernel32.dll")); if (attached_ok) { // Try to attach to the parent process if it's a console, i.e. we're run from a DOS prompt. // The code below is equivalent to calling this code: // BOOL attached_ok = AttachConsole( ATTACH_PARENT_PROCESS ); typedef BOOL (WINAPI *AttachConsole_t)(DWORD dwProcessId); AttachConsole_t wxDL_INIT_FUNC(pfn, AttachConsole, kernel); if (pfnAttachConsole) attached_ok = pfnAttachConsole( ATTACH_PARENT_PROCESS ); else attached_ok = 0; } if (attached_ok == 0) // failed attaching { // we tried to attach, but failed don't alloc a new one if (!alloc_new_if_needed) return; // Unable to attach, allocate a console for this app AllocConsole(); } // set the screen buffer to be big enough to let us scroll text GetConsoleScreenBufferInfo(GetStdHandle(STD_OUTPUT_HANDLE), &coninfo); coninfo.dwSize.Y = (WORD)max_console_lines; SetConsoleScreenBufferSize(GetStdHandle(STD_OUTPUT_HANDLE), coninfo.dwSize); // redirect unbuffered STDOUT to the console lStdHandle = (long)GetStdHandle(STD_OUTPUT_HANDLE); hConHandle = _open_osfhandle(lStdHandle, _O_TEXT); fp = _fdopen( hConHandle, "w" ); *stdout = *fp; setvbuf( stdout, NULL, _IONBF, 0 ); // redirect unbuffered STDIN to the console lStdHandle = (long)GetStdHandle(STD_INPUT_HANDLE); hConHandle = _open_osfhandle(lStdHandle, _O_TEXT); fp = _fdopen( hConHandle, "r" ); *stdin = *fp; setvbuf( stdin, NULL, _IONBF, 0 ); // redirect unbuffered STDERR to the console lStdHandle = (long)GetStdHandle(STD_ERROR_HANDLE); hConHandle = _open_osfhandle(lStdHandle, _O_TEXT); fp = _fdopen( hConHandle, "w" ); *stderr = *fp; setvbuf( stderr, NULL, _IONBF, 0 ); // make cout, wcout, cin, wcin, wcerr, cerr, wclog and clog // point to console as well std::ios::sync_with_stdio(); }