|
Here's some code to do it. Call "CenterChildren" with a HWND.
-------------------------------------------------------------
BOOL CALLBACK MeasureChildrenBoundsProc(HWND hwnd, LPARAM lParam)
{
RECT *pRectUnion = reinterpret_cast<RECT*>(lParam);
RECT RectControl;
GetWindowRect(hwnd, &RectControl);
HWND hParent = GetParent(hwnd);
MapWindowPoints(NULL, hParent, reinterpret_cast<LPPOINT>(&RectControl), 2);
UnionRect(pRectUnion, pRectUnion, &RectControl);
return TRUE;
}
BOOL CALLBACK OffsetChildrenProc(HWND hwnd, LPARAM lParam)
{
POINT *pPoint = reinterpret_cast<POINT*>(lParam);
RECT RectControl;
GetWindowRect(hwnd, &RectControl);
HWND hParent = GetParent(hwnd);
MapWindowPoints(NULL, hParent, reinterpret_cast<LPPOINT>(&RectControl), 2);
SetWindowPos(
hwnd,
NULL,
RectControl.left+pPoint->x,
RectControl.top+pPoint->y,
0,
0,
SWP_NOZORDER|SWP_NOSIZE
);
return TRUE;
}
void CenterChildren(HWND hWnd)
{
// Calculate the bounding box around our children.
RECT rc = {0};
EnumChildWindows(hWnd, &MeasureChildrenBoundsProc, reinterpret_cast<LPARAM>(&rc));
// Move the children.
RECT RectParent;
GetClientRect(hWnd, &RectParent);
int ParentWidth = RectParent.right-RectParent.left;
int ParentHeight = RectParent.bottom-RectParent.top;
int ChildrenWidth = rc.right-rc.left;
int ChildrenHeight = rc.bottom-rc.top;
POINT offset = {(ParentWidth-ChildrenWidth)/2-rc.left, (ParentHeight-ChildrenHeight)/2-rc.top};
EnumChildWindows(hWnd, &OffsetChildrenProc, reinterpret_cast<LPARAM>(&offset));
}
Steve
|
|
|
|
|
thanx steve , i 'll try these
|
|
|
|
|
Hi All,
im resposting my problem.
im not getting the current scroll position in an ownerdrawn listbox.
could u pls u help me to solve this?
-Sarath
|
|
|
|
|
of course i test this function you test in another function
<br />
void CAnswer::OnVScroll(UINT nSBCode, UINT nPos, CScrollBar* pScrollBar)<br />
{<br />
SCROLLINFO m_Scroll;<br />
GetScrollInfo(SB_VERT,&m_Scroll);<br />
CListBox::OnVScroll(nSBCode, nPos, pScrollBar);<br />
}<br />
<br />
whitesky
-- modified at 1:10 Thursday 18th May, 2006
|
|
|
|
|
What function are you using to get the scroll position, GetTopIndex()?
- S
50 cups of coffee and you know it's on!
|
|
|
|
|
Hi,
How to check whether a directory is write protected(not ready-only attribute) or not. I tried using _taccess_s but its not working for directories(MSDN confirms it). Is there any way to check it.
Thanks.
Adios,
Cool Ju
Dream Ur Destiny
|
|
|
|
|
Use GetFileAttributes function
-Sarath
|
|
|
|
|
Hi,
GetFileAttribute doesnot retrieve the write-protection setting. Thats why I specifically mentioned "not read-only attribute" in my post.
Thanks.
Adios,
Cool Ju
Dream Ur Destiny
|
|
|
|
|
See Access Control List
MSDN Security Glossary[^]
"What classes are you using ? You shouldn't call stuff if you have no idea what it does" Christian Graus in the C# forum
led mike
|
|
|
|
|
Thanks Mike,
I got it. Its a combination of APIs. Lot of code. But its working fine.
Adios,
Cool Ju
Dream Ur Destiny
|
|
|
|
|
I have a program with some ini profile files. For dynamicly changing profile files when the app is running, i change the m_pszProfileName value which is a attribute of the App Class. But some problems bother me, the values are loaded correctly for each ini file when the app first running, while it does'nt work after i changed the m_pszProfileName value when the app run.
Can anybody help me?
Thanks.
<br />
void update()<br />
{<br />
....<br />
<br />
free((void*)m_pszRegistryKey);<br />
m_pszRegistryKey = NULL;<br />
free((void*)m_pszProfileName); <br />
m_pszProfileName =_tcsdup(szPath); <br />
....}<br />
...<br />
{<br />
AfxGetApp()->GetProfileString(......);<br />
}<br />
...<br />
hi
|
|
|
|
|
You can check in sources what is wrong there (maybe it caches open file handle), but why don't you use GetPrivateProfilexxx functions directly?
Igor Green
http://www.grigsoft.com/ - files and folders comparison tools
|
|
|
|
|
|
zt9788 wrote: But some problems bother me, the values are loaded correctly for each ini file when the app first running, while it does'nt work after i changed the m_pszProfileName value when the app run.
try these INI file reading wrapper class:-
INI FILE reader![^]
"Opinions are neither right nor wrong. I cannot change your opinion. I can, however, change what influences your opinion." - David Crow
cheers,
Alok Gupta
VC Forum Q&A :- I/ IV
|
|
|
|
|
There is a statement in the description of the CArray in MSDN:
……
If you need a dump of individual elements in an array, you must set the depth of the CDumpContext object to 1 or greater.
………
What dose “the depth of the CDumpContext object” means? I can’t understand.
|
|
|
|
|
I see from msdn that the generic mapping of atof() is _tstof(), but I can't use it even after I include <stdlib.h> & <stdio.h>. So, which .h file should I include?
MSDN:
TCHAR.H routine _UNICODE & _MBCS not defined _MBCS defined _UNICODE defined
_tstof atof atof _wtof
-- modified at 21:20 Wednesday 17th May, 2006
|
|
|
|
|
|
It's very strange that I can use _tstof() in VS.net 2003 but not VC6, even I include the file tchar.h.
Maybe I need the latest Platform SDK?
|
|
|
|
|
Hi,
On Windows Xp, there is a functionality that allows to copy the archives of an user. This functionality is had access through My Computer ( click of the right button of mouse ) -> Settings -> Advanced -> User Profiles -> Configurations -> Copy to.
How can I do that by C++ programming? I was thinking in something like a method of a WMI Class or the ShellExecute command.
Can you help me?
Grateful!
Hélio
|
|
|
|
|
I don't know what you are trying to do.
SHGetSpecialFolderLocation[^]
"What classes are you using ? You shouldn't call stuff if you have no idea what it does" Christian Graus in the C# forum
led mike
|
|
|
|
|
I just want to copy the files of a user profile to another directory.
Here is a example:
There is user called João. In the directory c:\documents and settings\João\ are the João user's files. I just want to copy them to another directory. This functionality, as i said, is had access by My Computer -> Properties -> Advanced -> User Profiles -> Settings -> Copy To, but i want do that by C++ programming.
I still watting for help!!
gratiful!
Hélio
|
|
|
|
|
Hello all..
for the following program I got headache about the switch statment:
if I use switch(*hello) I got a compile error : switch quantity not an integer!
if I remove the stat I got a runtime error: segmentation fault!
I need help to fix this problem..
#include <stdio.h>
main()
{
int *hello;
printf("Hi, Enter any value > ");
scanf("%d",&hello);
switch (hello)
{
case 1: printf("your 1 luck number is > %d\n",hello);
case 2: printf("your 2 luck number is > %d\n",hello);
case 3: printf("your 3 luck number is > %d\n",hello);
default: printf("your 4 luck number is > %d\n",hello);
}
}
thanks
Ajmi
|
|
|
|
|
did you try changing the declaration of hello to be:
int hello;
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~<br />
Peter Weyzen<br />
Staff Engineer<br />
<A HREF="http://www.soonr.com">SoonR Inc.</A>
|
|
|
|
|
The segmentation fault is because the scanf statement is writing a new value to the POINTER hello , setting it to the value entered by the user. So if the user enters "4", hello is now a pointer to "address" 4. This will crash.
Do this instead:
<br />
int hello;<br />
printf("Hi, Enter any value > ");<br />
scanf("%d", &hello);<br />
switch(hello)<br />
{<br />
...<br />
...<br />
}<br />
Bob Ciora
|
|
|
|
|
moloza wrote: int *hello;
int hello is enough
nave
|
|
|
|