Difference between revisions of "CPlusPlus for Gideros Studio Help"
Line 116: | Line 116: | ||
}else if (strcmp(what, "openFileDialog") == 0) | }else if (strcmp(what, "openFileDialog") == 0) | ||
{ | { | ||
− | DWORD dwFlags; // | + | DWORD dwFlags; // XXX |
if (args.size()>0) | if (args.size()>0) | ||
{ | { | ||
− | std::wstring | + | std::wstring s=ws(args[0].s.c_str()); // "Title|C:/tmp/|Text (*.txt);; Image (*.png)" |
− | size_t index = | + | size_t index = s.find(L"|"); |
− | size_t index2 = | + | size_t index2 = s.find(L"|", index+1); |
− | std::wstring title = | + | std::wstring title = s.substr(0, index); |
− | std::wstring | + | std::wstring place = s.substr(index+1, index2-index-1); |
− | std::wstring | + | std::wstring extension = s.substr(index2+1); |
− | + | // printf("t p e:\n %ls\n %ls\n %ls\n", title.c_str(),place.c_str(),extension.c_str()); // TEST OK | |
HRESULT hr = CoInitializeEx(NULL, COINIT_APARTMENTTHREADED | COINIT_DISABLE_OLE1DDE); | HRESULT hr = CoInitializeEx(NULL, COINIT_APARTMENTTHREADED | COINIT_DISABLE_OLE1DDE); | ||
Line 136: | Line 136: | ||
{ L"Text Documents", L"*.txt" }, | { L"Text Documents", L"*.txt" }, | ||
{ L"All Files", L"*.*" }, | { L"All Files", L"*.*" }, | ||
− | }; // NEED TO PASS | + | }; // NEED TO PASS FROM ARGS wstring extension |
// Create the FileOpenDialog object. | // Create the FileOpenDialog object. | ||
Line 150: | Line 150: | ||
pFile->SetFileTypeIndex(1); // index starts at 1 XXX | pFile->SetFileTypeIndex(1); // index starts at 1 XXX | ||
// pFile->SetDefaultExtension(L"obj;fbx"); // XXX | // pFile->SetDefaultExtension(L"obj;fbx"); // XXX | ||
− | // pFile->SetFolder(shellItem); // | + | hr = pFile->SetTitle(title.c_str()); // need more check? |
+ | |||
+ | // ************* | ||
+ | // IShellItem *pItem = place //NULL; | ||
+ | // hr = SHCreateItemFromParsingName(wideString, NULL, IID_IShellItem, (LPVOID *)&pItem); | ||
+ | //// pFile->SetFolder(shellItem); | ||
+ | // hr = pFile->SetFolder(pItem); // trying to set start folder from ARGS wstring place | ||
+ | // ************* | ||
// Show the Open dialog box. | // Show the Open dialog box. |
Revision as of 17:31, 26 October 2022
Here you will find various resources to help learn C++ for people who wish to help with Gideros Studio development.
KNOWNFOLDERID
platform-win32.cpp
refs:
- KNOWNFOLDERID: https://learn.microsoft.com/en-us/windows/win32/shell/knownfolderid
- shlobj_core.h header: https://learn.microsoft.com/en-us/windows/win32/api/shlobj_core/
- SHGetKnownFolderPath function (shlobj_core.h): https://learn.microsoft.com/en-us/windows/win32/api/shlobj_core/nf-shlobj_core-shgetknownfolderpath
- SO (cc-by): https://stackoverflow.com/a/50660989/870125
C:\dev\gideros_hgy29\libgid\src\win32\platform-win32.cpp
Convert wstring <-> string
platform-win32.cpp
refs:
- SO (cc-by): https://stackoverflow.com/a/18374698/870125
C:\dev\gideros_hgy29\libgid\src\win32\platform-win32.cpp
#include <locale> // new 20221014 XXX
#include <codecvt> // new 20221014 XXX
...
std::wstring s2ws(const std::string& str)
{
using convert_typeX = std::codecvt_utf8<wchar_t>;
std::wstring_convert<convert_typeX, wchar_t> converterX;
return converterX.from_bytes(str);
}
std::string ws2s(const std::wstring& wstr)
{
using convert_typeX = std::codecvt_utf8<wchar_t>;
std::wstring_convert<convert_typeX, wchar_t> converterX;
return converterX.to_bytes(wstr);
}
win32 minimum, maximum screen size
platform-win32.cpp
refs:
- https://www.youtube.com/watch?v=-kg4TG7GoYI
- https://gamedev.net/forums/topic/569148-c-windows-api-minimum-resize-dimensions/4638297/
- SO (cc-by): https://stackoverflow.com/q/19035481/870125
- SO (cc-by): https://stackoverflow.com/a/22261818/870125
- https://learn.microsoft.com/en-gb/windows/win32/winmsg/wm-getminmaxinfo?redirectedfrom=MSDN
- https://learn.microsoft.com/en-us/windows/win32/api/winuser/nc-winuser-wndproc
C:\dev\gideros_hgy29\libgid\src\win32\platform-win32.cpp
win32 LFS problem with separator
Recent changes to path handling (most likely [0]) caused AssetCatalogTest.create_catalog_after_loading_file to fail on WIN32.
The test relied on the resulting path to be joined with "/" as a path separator. The resulting path used both forward and back-slashes. While these do work for some API's on WIN32, mixing both in a file path isn't expected behavior in most cases, so update the tests to use native slash direction for file-paths.
* \note If you want a trailing slash, add `SEP_STR` as the last path argument,
* duplicate slashes will be cleaned up.
*/
size_t BLI_path_join(char *__restrict dst, size_t dst_len, const char *path, ...)
# define SEP '\\'
# define ALTSEP '/'
# define SEP_STR "\\"
# define ALTSEP_STR "/"
#else
# define SEP '/'
#define SEP_CHR '#'
#define SEP_STR "#"
#define EPS 0.001
#define UN_SC_KM 1000.0f
#define UN_SC_HM 100.0f
str_tmp, TEMP_STR_SIZE, "*%.9g" SEP_STR, unit->scalar / scale_pref);
if (len_num > len_max) {
len_num = len_max;
}
if (found_ofs + len_num + len_move > len_max) {
openFileDialog
platform-win32.cpp
refs:
- https://learn.microsoft.com/en-us/windows/win32/learnwin32/learn-to-program-for-windows
- https://weblogs.asp.net/kennykerr/Windows-Vista-for-Developers-_1320_-Part-6-_1320_-The-New-File-Dialogs
- https://www.codeproject.com/Articles/16678/Vista-Goodies-in-C-Using-the-New-Vista-File-Dialog
- https://learn.microsoft.com/en-us/windows/win32/shell/common-file-dialog
#include <wchar.h> // new 20221026 XXX
...
}else if (strcmp(what, "openFileDialog") == 0)
{
DWORD dwFlags; // XXX
if (args.size()>0)
{
std::wstring s=ws(args[0].s.c_str()); // "Title|C:/tmp/|Text (*.txt);; Image (*.png)"
size_t index = s.find(L"|");
size_t index2 = s.find(L"|", index+1);
std::wstring title = s.substr(0, index);
std::wstring place = s.substr(index+1, index2-index-1);
std::wstring extension = s.substr(index2+1);
// printf("t p e:\n %ls\n %ls\n %ls\n", title.c_str(),place.c_str(),extension.c_str()); // TEST OK
HRESULT hr = CoInitializeEx(NULL, COINIT_APARTMENTTHREADED | COINIT_DISABLE_OLE1DDE);
if (SUCCEEDED(hr))
{
IFileOpenDialog *pFile;
COMDLG_FILTERSPEC fileTypes[] =
{
{ L"Text Documents", L"*.txt" },
{ L"All Files", L"*.*" },
}; // NEED TO PASS FROM ARGS wstring extension
// Create the FileOpenDialog object.
hr = CoCreateInstance(CLSID_FileOpenDialog, NULL, CLSCTX_ALL,
IID_IFileOpenDialog, reinterpret_cast<void**>(&pFile));
if (SUCCEEDED(hr))
{
// get/set options
pFile->GetOptions(&dwFlags);
pFile->SetOptions(dwFlags | FOS_FORCEFILESYSTEM);
pFile->SetFileTypes(ARRAYSIZE(fileTypes), fileTypes);
pFile->SetFileTypeIndex(1); // index starts at 1 XXX
// pFile->SetDefaultExtension(L"obj;fbx"); // XXX
hr = pFile->SetTitle(title.c_str()); // need more check?
// *************
// IShellItem *pItem = place //NULL;
// hr = SHCreateItemFromParsingName(wideString, NULL, IID_IShellItem, (LPVOID *)&pItem);
//// pFile->SetFolder(shellItem);
// hr = pFile->SetFolder(pItem); // trying to set start folder from ARGS wstring place
// *************
// Show the Open dialog box.
hr = pFile->Show(NULL);
// Get the file name from the dialog box.
if (SUCCEEDED(hr))
{
IShellItem *pItem;
hr = pFile->GetResult(&pItem);
if (SUCCEEDED(hr))
{
PWSTR pszFilePath;
hr = pItem->GetDisplayName(SIGDN_FILESYSPATH, &pszFilePath);
// Display the file name to the user.
if (SUCCEEDED(hr))
{
// MessageBoxW(NULL, pszFilePath, L"File Path", MB_OK);
r.type=gapplication_Variant::STRING;
r.s=us(pszFilePath);
rets.push_back(r);
CoTaskMemFree(pszFilePath);
}
pItem->Release();
}
}
pFile->Release();
}
CoUninitialize();
}
}
/*------------------------------------------------------------------*/
}else if (strcmp(what, "saveFileDialog") == 0)
Locate first occurrence of character in wide string
platform-win32.cpp
refs:
std::wstring gs=ws(args[0].s.c_str()); // "Title|C:/tmp/|Text (*.txt);; Image (*.png)"
size_t index = gs.find(L"|");
size_t index2 = gs.find(L"|", index+1);
printf("args0: %ls\n", gs.c_str()); // output: Title|C:/tmp/|Text (*.txt);; Image (*.png)
printf("indices: %d, %d\n", index,index2); // output 5, 13
std::wstring title = gs.substr(0, index);
std::wstring path = gs.substr(index+1, index2-index-1);
std::wstring exts = gs.substr(index2+1);
printf("t p e:\n %ls\n %ls\n %ls\n", title.c_str(),path.c_str(),exts.c_str()); // Title C:/tmp/ Text (*.txt);; Image (*.png)