Click here to Skip to main content
15,867,488 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi,

This problem has me pulling my hair out?? I have an application that doesn't display text for some users. I cannot replicate the problem as it works fine for me. I did discover that if I run the application as an administrator the problem happens?

When running the application as an administrator the SetWindowText function does not work. When running the application as normal the SetWindowText works fine.

If I try to debug the application in Visual Studio 2017 running the application in admin mode it works fine so I cannot see what the problem is. I have displayed a message box just before it calls SetWindowText and the messabe box displays the text correctly but the SetWindowText is blank?

Here's an example of the test code.


// Declared in the Header file
WCHAR m_UserPrompt[128];



// CPP implementation file
void CUserPromptDlg::GetDisplayPrompt(WCHAR *pUserPrompt)
{
	wcscpy(pUserPrompt, L"Test message");
}


void CUserPromptDlg::TestFunc1()
{
	GetDisplayPrompt(m_UserPrompt);
	AfxMessageBox(m_UserPrompt);
	SetDlgItemTextW(IDS_USER_PROMPT, m_UserPrompt);
}


What I have tried:

I have tried everything I can think of but I cannot figure out why it works for 85% of users and not for the other 15%??
Posted
Updated 14-Apr-20 5:39am
Comments
KarstenK 14-Apr-20 9:51am    
you missed to add the code for your SetWindowText bug!
MickFarrell 14-Apr-20 10:33am    
Hi, it is included above, not sure why you can't see it but here it is

// Declared in the Header file
WCHAR m_UserPrompt[128];



// CPP implementation file
void CUserPromptDlg::GetDisplayPrompt(WCHAR *pUserPrompt)
{
wcscpy(pUserPrompt, L"Test message");
}


void CUserPromptDlg::TestFunc1()
{
GetDisplayPrompt(m_UserPrompt);
AfxMessageBox(m_UserPrompt);
SetDlgItemTextW(IDS_USER_PROMPT, m_UserPrompt);
}

I have had a similar problem with simple Messagebox calls, when the WM_PAINT handler does not call the BeginPaint / EndPaint sequence. You may like to check if that is a possibility.

[edit]
C++
// CPP implementation file
void CUserPromptDlg::GetDisplayPrompt(WCHAR *pUserPrompt)
{
	wcscpy(pUserPrompt, L"Test message");
}


void CUserPromptDlg::TestFunc1()
{
	GetDisplayPrompt(m_UserPrompt);
	AfxMessageBox(m_UserPrompt);
	SetDlgItemTextW(IDS_USER_PROMPT, m_UserPrompt);
}


You appear to be using different variables for the text.

[/edit]
 
Share this answer
 
v3
Comments
MickFarrell 14-Apr-20 11:51am    
Hi Richard,

I have simplified the code as much as possible to test and I only use the basic CDialog with no WM_PAINT message handling. The same code works fine but does not display text when run in Admin mode?
MickFarrell 14-Apr-20 11:51am    
Hi Richard,

I have simplified the code as much as possible to test and I only use the basic CDialog with no WM_PAINT message handling. The same code works fine but does not display text when run in Admin mode?
Richard MacCutchan 14-Apr-20 11:57am    
See my updated solution.
MickFarrell 14-Apr-20 12:16pm    
Hi Richard, One is a pointer to the WCHAR array. m_UserPrompt is declared in the header file.

Solution 1: If I moved m_UserPrompt from the Header file and declare it in the class function TestFunc1() as a local variable it works fine.

Solution 2: If I copy the contents of m_UserPrompt to a CString it works fine.

This has me completely puzzled?? I'm convinced the problem is UNICODE related but I can't figure it out?
Richard MacCutchan 14-Apr-20 12:29pm    
Sorry but there is far too much detail that we cannot see. If you need to move something from the header to the implementation file to make it work then your class definition must be incorrect. You need to go through all your code line by line to ensure that it is complete, and that you have not misdirected something.
Do your other 15% users use computer language configuration set to EN(US)?
 
Share this answer
 
Comments
MickFarrell 14-Apr-20 10:35am    
Hi,

I will check with a couple of the users to see if they have different language setups on their PC's.

If it is a problem with language setups why would it happen to me when I run in Admin mode but not when I don't?
MickFarrell 14-Apr-20 11:49am    
I checked with 4 users and they all have their language and regional settings set to EN(US). One of those users has the display issue
steveb 14-Apr-20 11:52am    
Usually it would just display garbage characters if you place en(us) codes onto cyrillic or japanese langs. Also since you put the string, by what it looks like, the static text control, make sure it is wide enough. As far as I remember when static text does not fit the box it will remain blank. Unlike edit text box.

And most important: call UpdateData(FALSE) after if your m_UserPrompt bound to DDX_ routines updates
MickFarrell 14-Apr-20 12:23pm    
Hi Steve, m_UserPrompt isn't bound to any DDX, it is just a WCHAR array with plenty of room. The text box in the dialog has plenty of room and displays the text prefectly when not run as an Administrator.
steveb 14-Apr-20 13:36pm    
Ok. I am not an Admin on my machine. I just created dialog based app and used exactly your code (I called TestFunc1() from OnInitDialog). And it works fine whether I ran is as Admin or a regular user. There something else is missing in your code. I cannot tell what.

BTW since you using MFC you can use CString instead of WCHAR[128] and DDX_ bind it to the control. Call UpdateData(FALSE) after you change CString value. If you build UNICODE CString becomes CStringW.

Also I noticed this: Your control ID is IDS_USER_PROMPT. This maybe nothing. But MSVC app wizard uses prefix IDS_ for resource strings and prefix IDC_ for controls. Double check that your IDS_USER_PROMPT is not a "String Table Resource" but an actual control ID

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

  Print Answers RSS
Top Experts
Last 24hrsThis month


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