so, i have a working interface, compiled in dll and which is called from a CAD system. the problem is after i click OK or CANCEL on the dialog box it just exit the CAD system.
here is the code
#include <stdio.h>
#include <uf.h>
#include <uf_defs.h>
#include <uf_exit.h>
#include <uf_ui.h>
#include <uf_styler.h>
#include <uf_mb.h>
#include <D:\litter\litter.h>
HWND hdialog;
HINSTANCE ghInstance;
HWND edit;
TCHAR FolderName[MAX_PATH];
TCHAR c[MAX_PATH];
BOOL t;
void SetFont(HWND hwnd,LPTSTR FontName,int FontSize)
{
HFONT hf;
LOGFONT lf={0};
HDC hdc=GetDC(hwnd);
GetObject(GetWindowFont(hwnd),sizeof(lf),&lf);
lf.lfWeight = FW_REGULAR;
lf.lfHeight = (LONG)FontSize;
lstrcpy( lf.lfFaceName, FontName );
hf=CreateFontIndirect(&lf);
SetBkMode(hdc,OPAQUE);
SendMessage(hwnd,WM_SETFONT,(WPARAM)hf,TRUE);
ReleaseDC(hwnd,hdc);
}
int __stdcall BrowseCallbackProc(HWND hwnd,UINT uMsg,LPARAM lParam,LPARAM lpData)
{
if(uMsg==BFFM_INITIALIZED)
{
RECT ListViewRect,Dialog;
edit=CreateWindowEx(0,"EDIT","",WS_CHILD|WS_VISIBLE|WS_BORDER|ES_AUTOHSCROLL,0,100,100,50,hwnd,0,ghInstance,NULL);
HWND caption=CreateWindowEx(0,"STATIC","You have selected the folder :",WS_CHILD|WS_VISIBLE|WS_CLIPCHILDREN,0,100,100,50,hwnd,0,ghInstance,NULL);
HWND ListView=FindWindowEx(hwnd,NULL,"SysTreeView32",NULL);
GetWindowRect(hwnd,&Dialog);
GetWindowRect(ListView,&ListViewRect);
SetWindowPos(ListView,0,(ListViewRect.left-Dialog.left) ,(ListViewRect.top-Dialog.top )-20,290,170,0);
SetWindowPos(edit,HWND_BOTTOM,(ListViewRect.left-Dialog.left),(ListViewRect.top-Dialog.top )+170,290,18,SWP_SHOWWINDOW);
SetWindowPos(caption,HWND_BOTTOM,(ListViewRect.left-Dialog.left),(ListViewRect.top-Dialog.top )+155,290,14,SWP_SHOWWINDOW);
SetFont(caption,"MS Sans Serif",12);
SetFont(edit,"MS Sans Serif",12);
}
if (uMsg==BFFM_SELCHANGED)
{
t = SHGetPathFromIDList((ITEMIDLIST*)lParam, c);
SetWindowText(edit,c);
}
return 0;
}
BOOL CALLBACK MainDlgProc(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam)
{
if(message==WM_QUIT||message==WM_CLOSE)
PostQuitMessage(0);
if(message==WM_INITDIALOG)
{
hdialog=hDlg;
RECT rc;
GetWindowRect(hDlg,&rc);
int w=rc.right-rc.left, h=rc.bottom-rc.top;
int cx=GetSystemMetrics(SM_CXSCREEN)/2, cy=GetSystemMetrics(SM_CYSCREEN)/2;
MoveWindow(hDlg,cx-w/2,cy-h/2,w,h,FALSE);
SendMessage(hDlg, WM_COMMAND, IDOK, 0);
}
if(message==WM_COMMAND)
{
if((LOWORD(wParam))==IDOK)
{
TCHAR dname[MAX_PATH];
IMalloc *imalloc; SHGetMalloc(&imalloc);
BROWSEINFO bi; ZeroMemory(&bi,sizeof(bi));
bi.hwndOwner=hDlg;
bi.pszDisplayName=dname;
bi.lpszTitle = TEXT("Choose Directory");
#define BIF_NONEWFOLDERBUTTON 0x0200
bi.ulFlags = BIF_NONEWFOLDERBUTTON|BIF_RETURNONLYFSDIRS;
bi.lpfn = BrowseCallbackProc;
ITEMIDLIST *pidl = SHBrowseForFolder(&bi);
if (pidl!=NULL)
MessageBox(hDlg,c,"Selected Folder",0);
SendMessage(hDlg, WM_COMMAND, IDCANCEL, 0);
imalloc->Free(pidl);
imalloc->Release();
}
if((LOWORD(wParam))==IDCANCEL)
{
PostQuitMessage(0);
EndDialog(hDlg,0);
}
}
return 0;
}