Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations wOOdy-Soft on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Why Windows NT misplaces my controls?

Status
Not open for further replies.

rbarella

Technical User
Dec 26, 2002
11
IT
Some lines of program written in Visual C++ for covering the active cell of a MSFlexGrid with a CEdit run properly in Windows '98, once solved the problem of translating twips into pixels.
But when the same program is tried in Windows NT or XP, the CEdit is misplaced, a few pixels over and at the left of where it should be.
Incidentally, in these OS the CEdit doesn't accept the instructions to change its font.
My questions are:
1) how can the program be informed of which is the environment Operating System?
2) how do Windows NT or XP map points and sizes on the screen?
3) for changing the font in NT, do I have to use an instruction different from SetFont?

Many thanks for any help.
 
It sounds like you are guessing at what is causing the discrepancy. I would suspect your code that calculates the position before I would suspect some difference between the Systems.

-pete
 
Whatever the problems with the code calculating position and size of the CEdit, there must be a difference between the Systems, because the same code runs perfectly in Window '98.
 
Ok... let me say that a different way. The code must be fixed to use system independent techniques to calculate the position. For instance, if the calculation uses a hard coded number for the Caption Bar height of a window, or a windows border width, rather than using an API call to obtain it. How’s that?

-pete
 
OK, this is the code:
quote
CRect CRbDLLApp::GetCellRect(CMSFlexGrid *pGrid)
{
// this function returns, in pixels, the inside (client) dimensions
// of the Grid's active cell
// The parent window of the control to be put over the active cell is the same Grid

AFX_MANAGE_STATE(AfxGetStaticModuleState());

HWND hDesktop = GetDesktopWindow();
HDC hdc = GetDC(hDesktop);
long ScreenHeightInTwips = GetDeviceCaps(hdc, VERTSIZE) *567 /10;
long ScreenHeightInPixels = GetDeviceCaps(hdc, VERTRES);
long ScreenWidthInTwips = GetDeviceCaps(hdc,HORZSIZE) *567 /10 ;
long ScreenWidthInPixels = GetDeviceCaps(hdc, HORZRES);

::ReleaseDC(hDesktop, hdc); // NEVER forget this ! ! !

CRect ControlRect;
ControlRect.left = (long) ( pGrid->GetColPos(pGrid->GetCol())* ScreenWidthInPixels
/ ScreenWidthInTwips);
ControlRect.top = (long) (pGrid->GetRowPos(pGrid->GetRow()) * ScreenHeightInPixels
/ ScreenHeightInTwips);
ControlRect.right = ControlRect.left + (long) ( pGrid->GetCellWidth() * ScreenWidthInPixels
/ ScreenWidthInTwips);
ControlRect.bottom = ControlRect.top + (long)( pGrid->GetCellHeight() * ScreenHeightInPixels
/ ScreenHeightInTwips);

return ControlRect;
}
unquote

I do appreciate your patience. And kindness.
 
Yeah, i don't believe you work in twips in C/C++ Win32 APIs. I think that is a VB ( read: BAD ) thing.

If i am wrong about that and there is some use of twips that i am unaware of in Win32 functions, or maybe it is the ActiveX control your using that returns twips rather than pixels. Then consider that you may need some way to obtain the twips per pixel dynamically rather than hard coding numbers. Perhaps because the number of twips per pixel could be different based on ?? (i don't know)

-pete
 
CMSFlexGrid in fact was built by VB programmers. For I don't know what reason and for my despair, it treats all sizes in twips, even if Win32 APIs and the human eye have no use for them but only for pixels. But this same ActiveX makes a wonderful job, when you have to expose long and complex lists of data.
What do you mean by «dinamically» obtaining twip per pixel?
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top