Click here to Skip to main content
15,883,705 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Dear Friends,

I have created a new property page for a printer properties using "PROPSHEETPAGE".

In that new property page, I kept a static text label and edit text box.
After entering numeric values to that edit text box, the Apply Button in the property sheet gets enabled.
I clicked the APPLY Button; After closing the window and open again, applied changes is not reflected back. (Ie)., the entered values in the Edit text box is not present.

The Edit text box is empty.

What I need is: The previously done changes should get reflected back when I open the property sheet again.

I tried using SetPrinterData API.
It is not working.

Kindly help me out to solve this issue.

Thanks in advance.
Regards
Heera

*******************************************************
This below code is not working.. Pls help me...

#include "precomp.h"
#include "debug.h"
#include "resource.h"
#include "globals.h"
#include "devmode.h"
#include "oemui.h"
// This indicates to Prefast that this is a usermode driver file.
__user_driver;
////////////////////////////////////////////////////////
//      INTERNAL MACROS and DEFINES
////////////////////////////////////////////////////////
typedef struct _tagCBUserData
{
    HANDLE          hComPropSheet;
    HANDLE          hPropPage;
    POEMUIPSPARAM   pOEMUIParam;
    PFNCOMPROPSHEET pfnComPropSheet;
} CBUSERDATA, *PCBUSERDATA;

////////////////////////////////////////////////////////
//      INTERNAL PROTOTYPES
////////////////////////////////////////////////////////
LONG APIENTRY OEMPrinterUICallBack(PCPSUICBPARAM pCallbackParam, POEMCUIPPARAM pOEMUIParam);
LONG APIENTRY OEMDocUICallBack(PCPSUICBPARAM pCallbackParam, POEMCUIPPARAM pOEMUIParam);
LONG APIENTRY OEMDocUICallBack2(PCPSUICBPARAM pCallbackParam);
INT_PTR CALLBACK DevicePropPageProc(HWND hDlg, UINT uiMsg, WPARAM wParam, LPARAM lParam);


////////////////////////////////////////////////////////////////////////////////
//
// Initializes OptItems to display OEM device or document property UI.
//
//Added the below line for Warning Removal : warning C4100: 'pOEMUIParam' : unreferenced formal parameter
#pragma warning( disable : 4100 ) 
HRESULT hrOEMPropertyPage(DWORD dwMode, POEMCUIPPARAM pOEMUIParam)
{
    HRESULT hResult = S_OK;
    VERBOSE("hrOEMPropertyPage entry.\r\n");
    switch(dwMode)
    {
        case OEMCUIP_DOCPROP:
          //  hResult = hrDocumentPropertyPage(dwMode, pOEMUIParam);
            break;
        case OEMCUIP_PRNPROP:
          //  hResult = hrPrinterPropertyPage(dwMode, pOEMUIParam);
            break;
        default:
            // Should never reach this!
            ERR("hrOEMPropertyPage() Invalid dwMode");
            SetLastError(ERROR_INVALID_PARAMETER);
            hResult = E_FAIL;
            break;
    }
    return hResult;
}
////////////////////////////////////////////////////////////////////////////////
//
// Adds property page to printer property sheet.
//
HRESULT hrOEMDevicePropertySheets(PPROPSHEETUI_INFO pPSUIInfo, LPARAM lParam)
{
    LONG_PTR    lResult = 0;
    VERBOSE("hrOEMDevicePropertySheets entry\r\n");
    // Validate parameters.
    if( (NULL == pPSUIInfo)
        ||
        (PROPSHEETUI_INFO_VERSION != pPSUIInfo->Version)
      )
    {
        ERR("hrOEMDevicePropertySheets() ERROR_INVALID_PARAMETER.\r\n");
        // Return invalid parameter error.
        SetLastError(ERROR_INVALID_PARAMETER);
        return E_FAIL;
    }
    // Do action.
    switch(pPSUIInfo->Reason)
    {
        case PROPSHEETUI_REASON_INIT:
            {
                PROPSHEETPAGE   Page;
                // Init property page.
                memset(&Page, 0, sizeof(PROPSHEETPAGE));
                Page.dwSize = sizeof(PROPSHEETPAGE);
                Page.dwFlags = PSP_DEFAULT;
                Page.hInstance = ghInstance;
                Page.pszTemplate = MAKEINTRESOURCE(IDD_DEVICE_PROPPAGE);
                Page.pfnDlgProc = DevicePropPageProc;
                // Add property sheets.
                lResult = pPSUIInfo->pfnComPropSheet(pPSUIInfo->hComPropSheet, CPSFUNC_ADD_PROPSHEETPAGE, (LPARAM)&Page, 0);
            }
            break;
        case PROPSHEETUI_REASON_GET_INFO_HEADER:
            {
                PPROPSHEETUI_INFO_HEADER    pHeader = (PPROPSHEETUI_INFO_HEADER) lParam;
                pHeader->pTitle = (LPTSTR)PROP_TITLE;
                lResult = TRUE;
            }
            break;
        case PROPSHEETUI_REASON_GET_ICON:
            // No icon
            lResult = 0;
            break;
        case PROPSHEETUI_REASON_SET_RESULT:
            {
                PSETRESULT_INFO pInfo = (PSETRESULT_INFO) lParam;
                lResult = pInfo->Result;
            }
            break;
        case PROPSHEETUI_REASON_DESTROY:
            lResult = TRUE;
            break;
    }
    pPSUIInfo->Result = lResult;
    return S_OK;
}

INT_PTR CALLBACK DevicePropPageProc(HWND hDlg, UINT uiMsg, WPARAM wParam, LPARAM lParam)
{
	HWND hWndVal;
	hWndVal = GetDlgItem(hDlg, IDC_EDIT1);
	char strVal[20];
	int Val_len = 0;
	LPWSTR buffer = NULL;
	
	
    switch (uiMsg)
    {
	
		case WM_INITDIALOG:
	
			
			GetDlgItemText(hDlg,IDC_EDIT1, buffer,2);
			if (buffer != NULL)
			{
				SetWindowText(hWndVal, (LPCWSTR) buffer);
			}
			
			return TRUE;
        case WM_COMMAND:
            //if the textboxes are changed
			if (HIWORD(wParam) == EN_CHANGE)
			{
				SendMessage(GetParent(hDlg), PSM_CHANGED, (WPARAM)hDlg, 0);
			}
            return TRUE;
        case WM_NOTIFY:
            {
		NMHDR* pnmh = (NMHDR*)lParam;   
            if (pnmh->code == PSN_APPLY)   
            {   
				return TRUE;   
            }
		if (pnmh->code == PSN_KILLACTIVE)   
		{
		SetPrinterData(hDlg, OEMUI_VALUE, REG_DWORD, (PBYTE) (GetWindowText(hWndVal, (LPWSTR) strVal, 20)), sizeof(DWORD));
			
		GetWindowText(hWndVal, (LPWSTR) strVal, 20);
		Val_len = GetWindowTextLength(hWndVal);
			if (Val_len > 1)
			{
				//Error Enter value between 1 to 9
				MessageBox(hDlg, L"Enter value between 1 to 9", L"TESTING", MB_ICONWARNING | MB_OK);
			}
			else
			{
				SetWindowText(hWndVal, (LPCWSTR) strVal);
			}
			
			}
            break; 
            }
            break;
    }
    return FALSE;
}
#pragma warning(pop)
Posted
Updated 27-May-11 0:31am
v5
Comments
Dalek Dave 27-May-11 6:31am    
Edited for Grammar and Readability.

Well,

If you close the dialog and open it again, the changes made won't be reflected in the newly opened dialog unless you make it possible... you should edit the OnInitDialog function in order to update the contents of your controls at the beginning.

Notice that I think that after pressing Apply you are modifying some global variables, updating a file or any other persistent resource... On the OnInitDialog you should be able to recover the data from that resource.

Hope this helps... :thumbsup:
 
Share this answer
 
Comments
heera1686 27-May-11 2:23am    
Thanks for the idea. Let me try and come back.
Joan M 27-May-11 5:02am    
Please stop posting that in that way! (my bb is getting mad!) :-D you should improve your question and in that way you will be able to format your code without effort and moreover everyone here in the forum will see it... ;) Do it and we'll take a look at the code.
Joan M 27-May-11 5:04am    
In order to improve your question, you can click the green text that is down right the same question. Then you will be able to modify and update your question with the code you've just posted.
heera1686 27-May-11 5:08am    
Yes.. Done...
heera1686 27-May-11 5:21am    
Joan,
Help me pls..
I would say that it is normal that it don't work...

Keep in mind that once you've closed the dialog (property page) everything there gets destroyed.

So you must keep the property values stored in variables (or containers) that keep them. You should update the values of those containers each time you press apply/OK.

What I can see you are doing here in the OnInitDialog is to simply get the text of the same edit box... of course the editbox will not have any value so it has no sense to write the value inside the editbox again into the same editbox...

You should write the data you are interested to keep in a public variable, in a file, somewhere it would be stored at least meanwhile the app is running...

After that in the OnInitDialog you should recover the value of that variable and write it inside the editbox.

Hope this helps...

Good luck! :thumbsup:
 
Share this answer
 
Comments
heera1686 27-May-11 6:18am    
Am beginner to this project.
i understand what you are telling. But coding wise i dont know how to proceed. :(
heera1686 27-May-11 6:18am    
Anyways thanks for your response

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