Hello

I have a static window control & I want to make the text inside that static window centre aligned.

Is is possible to do that with a static window?

Or should I use another function?

static window:

stBox = CreateWindowEx(
              0,
              "Static",
              s.c_str(),
              WS_BORDER | WS_CHILD | WS_VISIBLE, // maybe I can put TF_RIGHTALIGN ??
              x,y,
              w+totalW+5,h+10,
              hwnd, NULL,
              gInstance,NULL);

Another question, I have a dialog using OPENFILENAME that closes when I select a file. Is there a way to make the dialog close when I select a folder instead of a file?

void doFileOpen(HWND hwnd,UINT msg)
{
    OPENFILENAME ofn;
    char szFileName[MAX_PATH] = "";
    char folderPath[MAX_PATH] = "";

    ZeroMemory(&ofn, sizeof(ofn));

    ofn.lStructSize = sizeof(OPENFILENAME);
    ofn.hwndOwner = hwnd;
    ofn.lpstrFilter = "Text Files (*.txt)\0*.txt\0All Files (*.*)\0*.*\0";
    ofn.lpstrFile = szFileName;
    ofn.nMaxFile = MAX_PATH;
    ofn.Flags = OFN_EXPLORER | OFN_FILEMUSTEXIST | OFN_HIDEREADONLY;
    ofn.lpstrDefExt = "txt";

    
    if(GetOpenFileName(&ofn))
    {   
        //CommDlg_OpenSave_GetFolderPath(hwnd,sizeof(folderPath),(WPARAM)folderPath);  // This doesn't work
        SendMessage(hwnd,CDM_GETFOLDERPATH,sizeof(folderPath),(LPARAM)folderPath);
        SetDlgItemText(hwnd,msg,folderPath);
    }
    
}

Another question, I have a dialog using OPENFILENAME that closes when I select a file. Is there a way to make the dialog close when I select a folder instead of a file?

Try using a folder browsing dialog instead:

#define ID3LIB_LINKOPTION 1
#pragma comment(lib, "id3lib.lib")
#include <windows.h>
#include <shlobj.h>

bool BrowseFolder(char *lpPath, const char *caption, HWND hwndOwner = NULL) {
   BROWSEINFO bi;
   ZeroMemory( &bi, sizeof(bi) );

   bi.lpszTitle = caption;
   bi.hwndOwner = hwndOwner;
   LPITEMIDLIST pidl = SHBrowseForFolder ( &bi );

   if ( pidl ) {
      SHGetPathFromIDList( pidl, lpPath );
      return true;
   }

   return false;
}
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.