The Origin Forum
File Exchange
Try Origin for Free
The Origin Forum
Home | Profile | Register | Active Topics | Members | Search | FAQ | Send File to Tech support
Username:
Password:
Save Password
Forgot your Password? | Admin Options

 All Forums
 Origin Forum for Programming
 Forum for Origin C
 Prevent Dialog Size Storage
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic Lock Topic Edit Topic Delete Topic New Topic Reply to Topic

cdrozdowski111

USA
247 Posts

Posted - 02/28/2014 :  06:30:50 AM  Show Profile  Edit Topic  Reply with Quote  View user's IP address  Delete Topic
OriginPro 9.1 SR1 64-bit/32-bit, Win7 Pro 64-bit, running in VMware Fusion 5.0.4

I am developing a resource DLL-based dialog that inherits from the Dialog class.

How can I prevent the automatic storage of the dialog size and screen position in Origin?

As I am developing, I'm changing the size of the dialog in VC++ but the size of the dialog remains at the "old" size from last time I ran it in Origin.

cdrozdowski111

USA
247 Posts

Posted - 03/01/2014 :  09:19:41 AM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
I thought I'd share this in case anyone else has the need to "ignore" Origin's automatic dialog resizing/repositioning feature in their Resource DLL/Origin C dialog implementation. It works for dialogs derived from the Dialog class. It does NOT prevent Origin from storing the size/position information in the Registry- it simply ignores it. This has been tested in 9.1 only so far.

If anyone can improve on it, please post.

Put the following in your OC dialog class code.

In your message map section:

EVENTS_BEGIN
ON_INIT(OnInitDialog)
ON_READY(OnReady) // Add this map if you don't have it already
EVENTS_END


Relevant dialog methods:

BOOL OnInitDialog()
{
 	// Must go first!!!
	// Get the dialog size and position before the DDK-stored
	// sizing/positioning gets a hold of it. We can't show dialog yet because if this!
	GetWindowRect(&m_rectDialog); // m_rectDialog is a private member var of type RECT
	ShowWindow(SW_HIDE);

	// Other code
}

BOOL OnReady()
{
	// Other code

	// Put the dialog back where it was before the DDK-stored sizing/positioning moved it
	MoveWindow(&m_rectDialog);
	ShowWindow(SW_NORMAL);

	return true;
}


Define member variable:

private:
	RECT m_rectDialog;



Edited by - cdrozdowski111 on 03/02/2014 6:58:29 PM
Go to Top of Page

cpyang

USA
1406 Posts

Posted - 03/03/2014 :  7:15:50 PM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
Why not just delete the registry entry before you get into the dialog code? That way will for sure no resizing?

CP
Go to Top of Page

cdrozdowski111

USA
247 Posts

Posted - 03/03/2014 :  8:02:41 PM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
You can't delete the registry entry because you can't get the registry key name that Dialog class uses. At least according to OC Help, there is no way. I cou;d be wrong though.
Go to Top of Page

Iris_Bai

China
Posts

Posted - 03/03/2014 :  9:14:31 PM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
Hi,

We can use the following way to set the dialog name (see ""MyDlg" below) in Registry entry.

BOOL OnInitDialog()
{
    ResizeDialog::OnInitDialog(0, "MyDlg");
    // Other code
}


Iris
Go to Top of Page

cdrozdowski111

USA
247 Posts

Posted - 03/03/2014 :  10:19:14 PM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
Ah, but this particular dialog is derived from Dialog, not ResizeDialog.

It's just a little "settings" dialog with a bunch of checkboxes that is instantiated when the user clicks a button in another, much more sophisticated dialog.

My goal was simply to get around the Dialog class' automatic sizing and repositioning.

The code I presented achieves my goal. It simply undoes what Dialog does without worrying about the Registry.
Go to Top of Page

ZanHUNG

20 Posts

Posted - 03/03/2014 :  10:21:34 PM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
quote:
Originally posted by cdrozdowski111

OriginPro 9.1 SR1 64-bit/32-bit, Win7 Pro 64-bit, running in VMware Fusion 5.0.4

I am developing a resource DLL-based dialog that inherits from the Dialog class.

How can I prevent the automatic storage of the dialog size and screen position in Origin?

As I am developing, I'm changing the size of the dialog in VC++ but the size of the dialog remains at the "old" size from last time I ran it in Origin.




Here's an example of prevent the automatic storage of the dialog size and screen position: delete the value in OnDestroy(). To do so, you should know the Dialog Name, which can be set in OnInitDialog(), and OnRestoreSize().

#include <Origin.h>
#include <dialog.h>
#include <..\originlab\ResizeDialog.h>
#include "resource.h"        // .h


#define STR_DLG_NAME "DialogName"

class MyDlg : public ResizeDialog
{
public:
    MyDlg() : ResizeDialog(IDD_DIALOG1, "dlgsizepos")        // .dll
    {
    }
    int DoModal(HWND hParent = NULL)
    {
        InitMsgMap();
        return ResizeDialog::DoModal(hParent);
    }
    
protected:
    EVENTS_BEGIN
        ON_INIT( OnInitDialog )
        ON_DESTROY( OnDestroy )
        ON_RESTORESIZE( OnRestoreSize )
    EVENTS_END
    
    BOOL OnInitDialog()
    {
        ResizeDialog::OnInitDialog(0, STR_DLG_NAME);
        return TRUE;
    }
    BOOL OnDestroy()
    {
        /* value delete */
        Registry reg(HKEY_CURRENT_USER);
        string strKey = GetRegKey() + "\\Dialogs\\" + STR_DLG_NAME;
        reg.DelValue(strKey, "Position");
        
        return ResizeDialog::OnDestroy();
    }
    BOOL OnRestoreSize(ODWP dwSizeInfo)
    {
        void * p = (void*)dwSizeInfo;
        DLGSIZEINFO *pSz = (DLGSIZEINFO*)p;
        lstrcpyn(pSz->szDialogName, STR_DLG_NAME, MAXLINE);
        
        /* here, you specify the size and position */
        pSz->top = 100;
        pSz->left = 150;
        pSz->width = -1;
        pSz->height = -1;
        
        return TRUE;
    }
};

int dlgDelReg()
{
    MyDlg dlg;
    dlg.DoModal( GetWindow() );
    
    return 0;
}


Edit: Be the Border Resizing or not, you can use ResizeDialog here.

Edited by - ZanHUNG on 03/03/2014 10:29:49 PM
Go to Top of Page

cdrozdowski111

USA
247 Posts

Posted - 03/04/2014 :  07:58:52 AM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
Thanks, Ya'll.

Zan's hint that ResizeDialog will work for just as well for non-resizeable dialogs made it all fall into place and I was able to use the ResizeDialog code to get what I needed without having to resort to the hack I had suggested.

Only one thing-


pSz->width = -1;
pSz->height = -1;


Wasn't right. But I caught it and changed the values to the dimensions I needed.
Go to Top of Page
  Previous Topic Topic Next Topic Lock Topic Edit Topic Delete Topic New Topic Reply to Topic
 New Topic  Reply to Topic
 Printer Friendly
Jump To:
The Origin Forum © 2020 Originlab Corporation Go To Top Of Page
Snitz Forums 2000