2 Replies - 710 Views - Last Post: 22 April 2012 - 01:04 PM Rate Topic: -----

#1 Shtock  Icon User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 28
  • Joined: 14-November 11

Can't open the DialogBox just using a button handler. (Win32 C\C++

Posted 08 April 2012 - 07:17 AM

Hi everyone.I got stuck with the Openbox in win32.
I've read this article

(http://www.codeproject.com/Articles/3984/Customizing-the-quot-Browse-for-folder-quot-dialog).

That dude used a dialog box to call Folder Browser-box as you can see on the main picture.
But I can't call it just pushing the VIEW button without using intermediate OpenBox.

If I trying to send the ID_BUTTON in case VIEW_BUTTON:{ DialogBox(ghInstance,MAKEINTRESOURCE(IDD_DIALOG1),hWnd,MainDlgProc);break;}
it gives nothing.

HELP PLEASE.

As you see on my picture:
1) I push View button
2) Than I get this unnecessary DialogBox (I must dispose of it) with your help
3) I get the BrowserFolder....
Attached Image

Is This A Good Question/Topic? 0
  • +

Replies To: Can't open the DialogBox just using a button handler. (Win32 C\C++

#2 GunnerInc  Icon User is offline

  • "Hurry up and wait"
  • member icon




Reputation: 858
  • View blog
  • Posts: 2,277
  • Joined: 28-March 11

Re: Can't open the DialogBox just using a button handler. (Win32 C\C++

Posted 08 April 2012 - 10:01 AM

So, you push button 1 and dialog 2 opens then you have to push the show dialog for dialog 3 to show up?.

What you want to do is push button 1 and manke dialog 3 open up?

How do you think you can fix it? Hint... the code in your "Show Dialog" button handler of your "Browse for Folder DEMO" dialog has to go someplace else.
Was This Post Helpful? 1
  • +
  • -

#3 Shtock  Icon User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 28
  • Joined: 14-November 11

Re: Can't open the DialogBox just using a button handler. (Win32 C\C++

Posted 22 April 2012 - 01:04 PM

I got it:
......
case VIEW_BUTTON:{ MainDlgProc(hWnd);break;}
.......
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);   
   }
//Browse dialog callback procedure
  int __stdcall BrowseCallbackProc(HWND  hwnd,UINT  uMsg,LPARAM  lParam,LPARAM  lpData)
  {
   
   	//Initialization callback message
   	if(uMsg==BFFM_INITIALIZED)
   	{
   		//Rectangles for getting the positions
   		RECT ListViewRect,Dialog;
   		//Create the edit and static control on the dialog box
   		edit=CreateWindowEx(0,L"EDIT",L"",WS_CHILD|WS_VISIBLE|WS_BORDER|ES_AUTOHSCROLL,0,100,100,50,hwnd,0,hInst,NULL);
   		HWND caption=CreateWindowEx(0,L"STATIC",L"You have selected the folder :",WS_CHILD|WS_VISIBLE|WS_CLIPCHILDREN,0,100,100,50,hwnd,0,hInst,NULL);
  		HWND ListView=FindWindowEx(hwnd,NULL,L"SysTreeView32",NULL);
   
   		//Gets the dimentions of the windows
   		GetWindowRect(hwnd,&Dialog);
   		GetWindowRect(ListView,&ListViewRect);
  
  		//Sets the listview controls dimentions
  		SetWindowPos(ListView,0,(ListViewRect.left-Dialog.left) ,(ListViewRect.top-Dialog.top )-20,290,170,0);
  		//Sets the window positions of edit and dialog controls
   		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);
   
   		//Sets the fonts of edit and static controls
   		SetFont(caption,L"MS Sans Serif",12);
   		SetFont(edit,L"MS Sans Serif",12);
   		
   	}
	//Selection change message
   	if(uMsg==BFFM_SELCHANGED)
   	{
   		t = SHGetPathFromIDList((ITEMIDLIST*)lParam, c);
   
   		//Sets the text of the edit control to the current folder
   		SetWindowText(edit,c);
       }
   	return 0;
  }
  //Callback of the main window
  BOOL CALLBACK MainDlgProc(HWND 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);
  	 
  			TCHAR dname[MAX_PATH];
  			IMalloc *imalloc; SHGetMalloc(&imalloc);
  			BROWSEINFO bi; ZeroMemory(&bi,sizeof(bi));
  			bi.hwndOwner=hDlg;
  			bi.pszDisplayName=dname;
  			bi.lpszTitle = TEXT("Select the directory:");	

  			//#define BIF_NONEWFOLDERBUTTON  0x0200 		

  			bi.ulFlags = 0x0200 |BIF_RETURNONLYFSDIRS;
  			bi.lpfn = BrowseCallbackProc;
  			ITEMIDLIST *pidl = SHBrowseForFolder(&bi);  
  			//Displays the selected folder
 			if (pidl!=NULL)
  				//MessageBox(hDlg,c,L"You have selected the folder",0); 			
  			imalloc->Free(pidl);
  			imalloc->Release(); 
			SetWindowText(tBox,c);//Set the value into Main path_textbox(a folder where we'd search the files)
		while( (hRet = GetMessage( &Msg, NULL, 0, 0 )) != 0)
        { 
            if (hRet == -1)
            {
            // handle the error and possibly exit
            }
            else
            {
				PostQuitMessage(0);
				EndDialog(hDlg,0);
            }
        } 			
	return 0;  
  }


:code:

This post has been edited by jimblumberg: 22 April 2012 - 01:08 PM
Reason for edit:: Added missing Code Tags, Please learn to use them.

Was This Post Helpful? 0
  • +
  • -

Page 1 of 1