|
Hi,
I want to find all title of windows. But the code is giving 2 errors:
code is:
<br />
void CMainFrame::TrackWindow()<br />
{<br />
HWND hwnd;<br />
LPARAM lParam = 0; <br />
<br />
while(EnumWindows((WNDENUMPROC)EnumWindowsProc,lParam))<br />
{<br />
EnumWindowsProc(hwnd,lParam);<br />
}<br />
}<br />
<br />
static BOOL CALLBACK EnumWindowsProc(HWND hwnd, LPARAM lParam)<br />
{<br />
char text[200];<br />
GetWindowText(hwnd,text,200);<br />
AfxMessageBox(text);<br />
return TRUE;<br />
};<br />
<br />
Erros are:
1.'type cast' : cannot convert from 'overloaded-function' to 'WNDENUMPROC'
2. unable to recover from previous error(s); stopping compilation
|
|
|
|
|
1) Do you have a prototype for your callback function before the call to EnumWindows ?
2) <pet peeve> Change the name of the callback function to something other than the default. </pet peeve>
Judy
|
|
|
|
|
Thank you, Its working but I want to know the WindowPlacement using GetWindowPlacement() . The below code is returning null in WINDOWPLACEMENT variable.
<br />
static BOOL CALLBACK EnumWindowsProc(HWND hwnd, LPARAM lParam)<br />
{<br />
char text[200];<br />
GetWindowText(hwnd,text,200);<br />
CString szWindowTitle=text;<br />
WINDOWPLACEMENT *WndPlacement=NULL;<br />
if(szWindowTitle=="My Window")<br />
{<br />
GetWindowPlacement(hwnd,WndPlacement);
szWindowTitle.Format("%d",WndPlacement->showCmd);<br />
AfxMessageBox(szWindowTitle);<br />
}<br />
<br />
return TRUE;<br />
};<br />
|
|
|
|
|
pther wrote: The below code is returning null in WINDOWPLACEMENT variable.
Well, of course it is since you initialize WndPlacement to NULL. You're not using the function correctly. You need to supply the buffer to receive the requesetd information. Try this.
WINDOWPLACEMENT WndPlacement;
if(szWindowTitle=="My Window")
{
GetWindowPlacement(hwnd,&WndPlacement);
szWindowTitle.Format("%d",WndPlacement.showCmd);
AfxMessageBox(szWindowTitle);
}
Judy
|
|
|
|
|
pther wrote: while(EnumWindows((WNDENUMPROC)EnumWindowsProc,lParam))
Why the cast?
pther wrote: EnumWindowsProc(hwnd,lParam);
Why are you calling this function directly? EnumWindows() will do that for you, hence the callback.
"Love people and use things, not love things and use people." - Unknown
"To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne
|
|
|
|
|
I'm tring to set the Font and Fontsize to "MS Sans Serif" and 14, the code below does not seem to do it...what am I doing wrong? Is there an easier way to do this?
Thanks
CFont LargeFont;
LOGFONT lf;
memset(&lf, 0, sizeof(LOGFONT));
lf.lfHeight = 24;
lf.lfWeight = 400;
strcpy(lf.lfFaceName, "MS Sans Serif");
GetDlgItem(IDC_STATIC5)->SetFont(&LargeFont);
|
|
|
|
|
You never initialize LargeFont.
Why don't you use CFont::CreatePointFont ?
|
|
|
|
|
As addendum to Cédric reply, please note you probably have to use
lf.lfHeight = -MulDiv(24, GetDeviceCaps(hDC, LOGPIXELSY), 72);
to obtain a 24 point sized font.
See [^].
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong.
-- Iain Clarke
|
|
|
|
|
C++NewBe wrote: CFont LargeFont;
Where is this object declared?
"Love people and use things, not love things and use people." - Unknown
"To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne
|
|
|
|
|
The original Post was missing this:
VERIFY(LargeFont.CreateFontIndirect(&lf));
|
|
|
|
|
Ok, but that did not answer my question.
Is your problem solved now?
"Love people and use things, not love things and use people." - Unknown
"To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne
|
|
|
|
|
This is my code....what am I missing? I thing it's the height and weight that is giving me problem. I am from VB world.
thanks
CFont LargeFont;
LOGFONT lf;
memset(&lf, 0, sizeof(LOGFONT));
lf.lfHeight = 24;
lf.lfWeight = 400;
strcpy(lf.lfFaceName, "MS Sans Serif");
VERIFY(LargeFont.CreateFontIndirect(&lf));
GetDlgItem(IDC_STATIC5)->SetFont(&LargeFont);
|
|
|
|
|
C++NewBe wrote: CFont LargeFont;
Where is this object declared? If it is not global, or is not a member of the dialog, it will go out of scope before SetFont() has a chance to work.
"Love people and use things, not love things and use people." - Unknown
"To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne
|
|
|
|
|
Now I understand....it is being declared on ::Paint()
|
|
|
|
|
C++NewBe wrote: it is being declared on ::Paint()
Therein lies the problem.
"Love people and use things, not love things and use people." - Unknown
"To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne
|
|
|
|
|
Hello all,
I need checkboxes in List box.I am using Visual Studio 2003.
please suggest some solution.
Thanks & Regards,
Rahul
|
|
|
|
|
Link[^]
Nobody can give you wiser advice than yourself. - Cicero
.·´¯`·->Rajesh<-·´¯`·.
Codeproject.com: Visual C++ MVP
|
|
|
|
|
|
Rajkumar R wrote: multi-check ListBox[^] may be useful,
Had you followed my link, that's the same article I suggested too, besides indirectly telling him to use Google too.
Nobody can give you wiser advice than yourself. - Cicero
.·´¯`·->Rajesh<-·´¯`·.
Codeproject.com: Visual C++ MVP
|
|
|
|
|
|
Hi,using native C++ in dlls called from a VB.NET application I want to dynamically allocate up to 3 GB of memory, in stages, using the “new” command.
The following code (example to illustrate the problem) produces the following error “Unhandled exception at 0x7c81eb33 n VMTest.exe: Microsoft C++ exception:std::bad_alloc at memory location 0x0012fe10..”
I have configured the virtual memory under control panel|system properties|Advanced tab|Advanced tab|settings to “System managed size” and customised with Initial size = 756 and Maximum size = 8192 with no success. I am using VS2005 on XP SP2.
Please can anybody advise me on a way forward using the "new" command or an alternative.
#include "stdafx.h"
#include <iostream>;
using namespace std;
int _tmain(int argc, _TCHAR* argv[])
{
int count = 1000000000;
char buf;
char * cmemblock;
char unsigned * cumemblock;
cout << "Start of program" << endl;
cmemblock = new char [count];
cout << "cmemblock created" << endl;
cin >> buf;
cumemblock = new char unsigned [count];
cout << "cumemblock created" << endl;
cout << "Memory taken" << endl;
delete[] cmemblock;
cout << "cmemblock deleted" << endl;
delete[] cumemblock;
cout << "cmemblock deleted" << endl;
cout << "Successfull completion of program" << endl;
cin >> buf;
return 0;
}
|
|
|
|
|
Member 3363498 wrote: I want to dynamically allocate up to 3 GB of memory,
Why do you want to ever do such a thing ?
|
|
|
|
|
Hi Cedric, system requirements change. The application I am working now has to process large amounts of raw (binary) data. I was under the impression that Windows XP virual memory management would take care of data larger than RAM size. I could change the program so that I read chuncks i.e 0.5 GB at a time but this will impact other parts of the system.
My current development PC has 1GB of memory so I have will be upgrading as soon as possible.
Cheers,
Aubs
|
|
|
|
|
Member 3363498 wrote: Windows XP virual memory management would take care of data larger than RAM size
It will but if you're gong to be manipulating those huge chunks of memory at once - as in repeatedly allocating 4 GB then running through the entire 4G allocation - you're system is going to be constantly thrashing on the paging file. The additional time spent accessing the hard drive is probably going to be greater than whatever time you will gain be rewriting your logic to use the bigger chunks of memory. Processor speeds blow away disk access speeds.
Also, even if you put more than 4G of physical memory in your machine, XP cannot access it. It has a hard upper limit of 43G (32G using the default settings).
Judy
modified on Tuesday, April 15, 2008 8:38 AM
|
|
|
|
|
If you want to do this sort of thing you're probably best off using the Virtual Memory Win32 API, ::VirtualAlloc etc. Windows doesn't cope all that well if you try and grab all the RAM off it through the normal heap mechanism. You're also incurring CRT overhead and possibly tripping over inherent 2GB limits in the CRT malloc etc implementations when you use new. If you don't want to use Virtual memory you could use the Win32 Heap API e.g. ::HeapAlloc instead. Depending on how much RAM you've actually got you might get away with it. If you do my advice is make sure your allocation size are multiples of 64K and don't make them larger than about 4MB max at a time. That might help Windows to cope well enough. There's all sorts of wiredness going on underneath as ever with disk cache sizes and paging stuff in and out so you might want to target a specific and relatively recent Windows version aswell e.g. at least Server 2003 by defining _WIN32_WINNT 0x0502 and WINVER 0x0502. I'm not certain this will help but it's worth a try.
"The secret of happiness is freedom, and the secret of freedom, courage."
Thucydides (B.C. 460-400)
|
|
|
|