|
On a side note, why use macros when enum s will work just as well? Better in fact. For example try doing this with macros:
void Function1()
{
enum { buffersize = 1024 };
char buffer[buffersize];
}
void Function2()
{
enum { buffersize = 2048 };
char buffer[buffersize];
}
The problem with macros in this context is that they don’t obey C/C++ scoping rules. Using macros to define constants is old fashioned and should be avoided.
Steve
|
|
|
|
|
I want to list all the directories in a folder including the hidden dir's.Which function to be used?
Thanks..
|
|
|
|
|
Use CFileFind .
CFileFind finder;
BOOL bWorking = finder.FindFile(L"*.*");
while (bWorking)
{
bWorking = finder.FindNextFile();
if (finder.IsHidden())
{
}
}
|
|
|
|
|
How about the FindFirstFile() /FindNextFile() pair?
"Approved Workmen Are Not Ashamed" - 2 Timothy 2:15
"Judge not by the eye but by the heart." - Native American Proverb
|
|
|
|
|
|
I need to display the file open dialog and browse directory dialog at the center of the screen. it's display right now at the top left corner ,can any body help me to display it at the center.
is there any realation with my main application window. Because the mainwindow is not display at center of screen now.
Amit
|
|
|
|
|
amitmistry_petlad wrote: I need to display the file open dialog and browse directory dialog at the center of the screen
Use CWnd::CenterWindow .
|
|
|
|
|
But Master, it's WIN32.
aMIT
|
|
|
|
|
Oh ! I guess, you had asked same question few days back[^]. And I'll answer same thing agains, Look, how CWnd::CenterWindow is implemented.
Code for above function I'm pasing,
void CWnd::CenterWindow(CWnd* pAlternateOwner)
{
ASSERT(::IsWindow(m_hWnd));
DWORD dwStyle = GetStyle();
HWND hWndCenter = pAlternateOwner->GetSafeHwnd();
if (pAlternateOwner == NULL)
{
if (dwStyle & WS_CHILD)
hWndCenter = ::GetParent(m_hWnd);
else
hWndCenter = ::GetWindow(m_hWnd, GW_OWNER);
if (hWndCenter != NULL)
{
HWND hWndTemp =
(HWND)::SendMessage(hWndCenter, WM_QUERYCENTERWND, 0, 0);
if (hWndTemp != NULL)
hWndCenter = hWndTemp;
}
}
CRect rcDlg;
GetWindowRect(&rcDlg);
CRect rcArea;
CRect rcCenter;
HWND hWndParent;
if (!(dwStyle & WS_CHILD))
{
if (hWndCenter != NULL)
{
DWORD dwAlternateStyle = ::GetWindowLong(hWndCenter, GWL_STYLE);
if (!(dwAlternateStyle & WS_VISIBLE) || (dwAlternateStyle & WS_MINIMIZE))
hWndCenter = NULL;
}
MONITORINFO mi;
mi.cbSize = sizeof(mi);
if (hWndCenter == NULL)
{
HWND hwDefault = AfxGetMainWnd()->GetSafeHwnd();
GetMonitorInfo(
MonitorFromWindow(hwDefault, MONITOR_DEFAULTTOPRIMARY), &mi);
rcCenter = mi.rcWork;
rcArea = mi.rcWork;
}
else
{
::GetWindowRect(hWndCenter, &rcCenter);
GetMonitorInfo(
MonitorFromWindow(hWndCenter, MONITOR_DEFAULTTONEAREST), &mi);
rcArea = mi.rcWork;
}
}
else
{
hWndParent = ::GetParent(m_hWnd);
ASSERT(::IsWindow(hWndParent));
::GetClientRect(hWndParent, &rcArea);
ASSERT(::IsWindow(hWndCenter));
::GetClientRect(hWndCenter, &rcCenter);
::MapWindowPoints(hWndCenter, hWndParent, (POINT*)&rcCenter, 2);
}
int xLeft = (rcCenter.left + rcCenter.right) / 2 - rcDlg.Width() / 2;
int yTop = (rcCenter.top + rcCenter.bottom) / 2 - rcDlg.Height() / 2;
if (xLeft < rcArea.left)
xLeft = rcArea.left;
else if (xLeft + rcDlg.Width() > rcArea.right)
xLeft = rcArea.right - rcDlg.Width();
if (yTop < rcArea.top)
yTop = rcArea.top;
else if (yTop + rcDlg.Height() > rcArea.bottom)
yTop = rcArea.bottom - rcDlg.Height();
SetWindowPos(NULL, xLeft, yTop, -1, -1,
SWP_NOSIZE | SWP_NOZORDER | SWP_NOACTIVATE);
}
|
|
|
|
|
ya i am in proccess of modifing that one . Is it real need to make the main screen in the center for display the system window in center?
|
|
|
|
|
amitmistry_petlad wrote: Is it real need to make the main screen in the center for display the system window in center?
Actually, If you had a look at CWnd::CenterWindow , it has flexiblity to decide the window, which should be considered for centering window in question. By default its desktop window.
John R. Shaw has shown you code snippet, having similar logic, which will center the window.
|
|
|
|
|
Interesting but the question had to do with centering to the screen and not some unknown window. Also they specifically said Win32 and not some function that depends on MFC.
INTP
"Program testing can be used to show the presence of bugs, but never to show their absence."Edsger Dijkstra
|
|
|
|
|
I think, you has not read my reply carefully. In my first reply, I suggested to use CWnd::CenterWindow . After that, OP indicated, he is using win32 api. So, I simply shown him how this function is implemented using win32 Api. And while implementation, its taken care of considering both possiblities.
John R. Shaw wrote: Also they specifically said Win32 and not some function that depends on MFC.
In original post, he has not mentioned No MFC this.
|
|
|
|
|
1) I did read your reply carefully and the function you showed him is not using the Win32 API directly. What you showed him was a function that depended on MFC and C++. The Win32 API does not depend on MFC and I believe it is written in C and not C++, as are all of the Windows operating systems before it. Your code starts off with a C++ name and contained lines with function calls like “Afx…”; no matter how you look at it those are not Win32 API call, they are MFC calls.
2) True he did not mention ‘No MFC’ in the original post, but the one you gave an answer to said “But Master, it's WIN32.”.
INTP
"Program testing can be used to show the presence of bugs, but never to show their absence."Edsger Dijkstra
|
|
|
|
|
John R. Shaw wrote: not using the Win32 API directly
Again, let me explain, what I tried to explain, I told him, see how CenterWindow is implemented, And I just pasted code , how it's defintion. So it was up to OP to extract solution from it(and there are win32 api's used there).
|
|
|
|
|
Yes I see your point.
You are applying the concept of working backwards; which I have used often. I was approaching it from the Win32 (C code) point of view. I did suggest that he create a small program using MFC and then work backwards to see how they did it, using the code browser. MFC hides a lot of things and unless you know what it is hiding then it is hard to determine what a piece of it is doing.
We where approaching the problem from opposite directions. I try to answer the questions (from memory) at the level from which they were asked. If you look further down in the posts (the one with no replies) you will see my center window solution. The only problem with it is that you need a handle to the window; which common dialog boxes do not give you unless you over ride (hook) the class (not a C++ class) and create them directly.
I do know where you are coming from and apologize if you thought otherwise.
INTP
"Program testing can be used to show the presence of bugs, but never to show their absence."Edsger Dijkstra
|
|
|
|
|
John R. Shaw wrote: If you look further down in the posts (the one with no replies) you will see my center window solution.
I saw that, and suggested OP to refer[^] it.
John R. Shaw wrote: The only problem with it is that you need a handle to the window;
I think, that very obvious, without window handle, its very difficult to operate on window.
John R. Shaw wrote: which common dialog boxes do not give you unless you over ride (hook) the class (not a C++ class) and create them directly.
I suggested him to handle it in HookProc[^].
John R. Shaw wrote: I do know where you are coming from and apologize if you thought otherwise.
Never mind, it bound to happen, due to communication mismatch.
Anyway, nice to have this communication.
|
|
|
|
|
You funny! LOL
INTP
"Program testing can be used to show the presence of bugs, but never to show their absence."Edsger Dijkstra
|
|
|
|
|
Thanks !
My main application window screen is now in center but the browse file and brwose
directory dialog is still display the dialog in the upper left corner.For that I have did the same thing but it is unable to handle.
becuse of this is a structure so for that how can I use this one for dispaying the fileopen dialog
in the center?
OPENFILENAME ofn;
I have passed the owner window but I think its not helpful me..????
Window_Center(ofn.hwndOwner);
GetOpenFileName(&ofn);//When this will open the dialog it must in the center. but its not working.
how can this works ?
Amit
|
|
|
|
|
amitmistry_petlad wrote: ofn.hwndOwner
It is handle to owner of dialog, not to the dialog.
You may need to use OFNHookProcOldStyle . Handle WM_INITIDIALOG message there. And center the window with given code.
|
|
|
|
|
Like I said, I was not sure if it would help. That code depends on having the handle to the window that you want to center on the screen. There are ways to override common windows behavior called hooking that will allow you to do what you want, so I suggest that you look that up. You will need to dig a little deep and remember that each window has its own class name (not a C++ class name), look up ‘CreateWindow’ in the MSDN and you will have a start on what I am referring too.
I would like to be of more help, but it is the middle of the night here and I should be asleep.
P.S. Next time post your reply to the post you are replying to or I might not notice it.
INTP
"Program testing can be used to show the presence of bugs, but never to show their absence."Edsger Dijkstra
|
|
|
|
|
amitmistry_petlad wrote: ...it's WIN32.
So how about stating all of your requirements in your initial post!?
Be sure and specicy the OFN_ENABLEHOOK flag. In response to the WM_INITDIALOG message in the hook procedure, simply call CenterWindow() .
"Approved Workmen Are Not Ashamed" - 2 Timothy 2:15
"Judge not by the eye but by the heart." - Native American Proverb
|
|
|
|
|
This is a very old function and I do not know if it will help.
void Window_Center(HWND hWnd) {
RECT rc;
int w,h;
GetWindowRect(hWnd,&rc);
w = 1+rc.right-rc.left;
h = 1+rc.bottom-rc.top;
rc.left =(GetSystemMetrics(SM_CXSCREEN)-w)>>1;
rc.top =(GetSystemMetrics(SM_CYSCREEN)-h)>>1;
MoveWindow(hWnd,rc.left,rc.top,w,h,TRUE);
}
If that does not help, start searching for the multitudes of FAQs on the NET because it is a common question.
INTP
"Program testing can be used to show the presence of bugs, but never to show their absence."Edsger Dijkstra
|
|
|
|
|
exploite environment:2003SP1 PlatformSDK + VC6
error information:
error LNK2001: unresolved external symbol _IID_IHTMLInputElement
error LNK1120: 1 unresolved externals
error code:
CComPtr<ihtmlinputelement> *pIInput;
hr=pDisp->QueryInterface(IID_IHTMLInputElement , (void**)&pIInput);
|
|
|
|
|
It doesnt have any problem on the VS2005
|
|
|
|