Click here to Skip to main content
15,893,594 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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

C++
/* These include files are needed for the following template 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;

}
Posted

Probably, it's a problem with how one of your methods is being called - if the parameters don't match, you can easily get a stack corruption problem and the whole thing falls over.

Check teh way you call the DLL and compare that with your actual methods - but we can't help much with just that code. Have you tried calling it from a different application to see if it works in isolation?
 
Share this answer
 
i've worked it out by removing this command PostQuitMessage(0);
 
Share this answer
 
its working fine by itself ,

here how it works : first apears dialog box with 1 button - "ShowDialog", after u click button u get the dialog box(SHBrowseForFolder) wich allows you to select the folder root, then when u click OK or CANCEL u will get the window with button "ShowDialog" again.


i want only the BrowseForFolder dialog box on screen, without that little menu, so i putted in
this code :

SendMessage(hDlg, WM_COMMAND, IDOK, 0);
SendMessage(hDlg, WM_COMMAND, IDCANCEL, 0);


so the little menu vanished, i thought the problem is over, but when i compiled it in dll
and called it i recieve the problem i described above

so if u delete that code it's all working but i dont like that menu, want to drop it

here is that project [^]
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900