|
I know this is not a nice solution, but it works...
Start another thread that calls Beep(), when you need to stop the tone, just kill the thread, and eventually start it again with another frequency...
something like:
DWORD WINAPI WorkThread(LPVOID lpParameter)
{
Beep(500, 1000000);
return 0;
}
int main(int argc, char* argv[])
{
DWORD dwThreadId, dwThrdParam;
HANDLE hThread;
dwThrdParam = 1;
hThread = CreateThread(NULL, 0, WorkThread, &dwThrdParam, 0, &dwThreadId);
Sleep(1000);
CloseHandle(hThread);
return 0;
}
- Anders
Money talks, but all mine ever says is "Goodbye!"
|
|
|
|
|
I have a question regarding the ADO Data Controls that Microsoft provides with C++ ( i.e. Adodc, DataCombo, DataGrid, DataList, DataRepeater) It seems that these controls were primarily designed for use in VB. However, I am a cheap C++ programmer and wish to include these tools in an application that I am building. The problem I am experiencing arises when I attempt to bind DataCombo and DataList and run time, as the interfaces for the controls don't exposes any methods/properties to assign the DataSource and the DataField. They only provide the methods/properties to assign the RowSource and ListField. I know the methods/properties exist cause VB shows them and the VC++ dialog editor shows them too. I also tried to just statically bind them, however it seems they lose their binding at run time. Where do the DataSource and DataField properties disappear too, or where do they come from? Why do the controls lose their binding at run time if I statically bind them in the dialog editor? Are these two problems related? I attempted to solve this problem myself however, documentation on using these controls in C++ is scarce. Any help would be greatly appreciated.
Luke Stamm
luke@win-world.com
Wholesale Information Network, Inc.
|
|
|
|
|
Writing a short routine which opens a file I noticed the following:
try {
CFile file;
file.Open(filename, CFile::modeRead);
file.Read(buffer, file.GetLength());
file.Close()
}
This will not throw an exception if the file does not exist.
A slight change:
try {
CFile file(filename, CFile::modeRead);
file.Read(buffer, file.GetLength());
file.Close()
}
This code will throw an exception if the file is missing.
It must just be a misunderstanding on my part about the purpose
of exceptions/handlers, but could someone explain it?
|
|
|
|
|
CFile::CFile() must throw an exception because it does not return a value.
CFile::Open() does not throw an exception because its return value and CFileException *pError parameter can be used to handle any unsuccessful calls.
|
|
|
|
|
Constructors cannot return a value, as such they must throw exceptions to signal exceptional activity. Functions like CFile::Open can return a value, and are there for situations where you don't want to throw an exception.
This is how it is supposed to work.
By the way, you should know that CException based objects are thrown by reference, not by value, which means you need to call the Delete() memeber function on them or you will get a memory leak.
try
{
CFile(filename);
}
catch (CFileException *e)
{
e->Delete(); // do not call "delete e;"
}
This is handled automatically for you with the uppercase macro's TRY and CATCH, which I don't like using. when using the lower case try and catch, just remember to call Delete() on CException based exceptions.
|
|
|
|
|
I have an MFC app that compiles in DEBUG but the compiler hangs in Release mode. If I kill Winoldap in the task list the compiler comes back and then I can finish the compile. Other release projects compile OK. Any ideas.
Win ME
VC6 SP 5
|
|
|
|
|
Have you tried deleting the Relase folder and trying a rebuild all?
Michael
|
|
|
|
|
Thanks
I did that but no joy.
It appears that my system is hooped. Another system compiled the project no problem so ----- FORMAT C:
|
|
|
|
|
Dear All
How to get LOGFONT from COleControl?
Please Help Me...
Best Regards,
======================
www.activePower.idv.tw
+886-932-306-142
Jason Liao
======================
|
|
|
|
|
Hi,,
my question is where to store my data. but i like to explain what my application does first.
I have a MDI application, it displays Bitmaps, then it detects a certain number of points on the displays image. the user can move the points, add point, and delete points.
i store all the points in a linked_list,, in CView
so basically i dead with CView alot..
but now i have to add serialization to my application.. so i could store and retrieve my work.
1- Should i add all the data in the CDoc class, or i can leave them in CView.
2- can i use serialization in CView.
Thanks
Ehsan Behboudi
|
|
|
|
|
i am displaying a cedit control, made using pnt->Create( WS_VISIBLE, r, this, ID_EDIT1), where r is a rect. this displays fine but then i cant click back onto the form and make it lose focus... why? im not doing modal or anything...
thanks in advance
|
|
|
|
|
In the Style put this.
WS_CHILD | WS_VISIBLE | WS_TABSTOP
Works fine?
Cheers!!!!
Carlos Antollini.
|
|
|
|
|
thanks for the idea, but no luck.... it loses focus when i click on a menu item but not on the document behind it - its part of the view class... any ideas?!
thanks
|
|
|
|
|
I'm working on an architecture that will require a DLL to host a singleton object that will be accessible by multiple applications. It's clear that I can store the pointer to the singleton in a shared data segment, so that it will be used by all instances of the DLL... but the pointer will point to a dynamically allocated object, which itself will contain pointers to other dynamically allocated objects.
Now as I understand it, these DA'd objects will be mapped into the address space of the app that first loade the DLL, correct? This means they won't be accessible to other applications, correct? If my logic is correct.. how can I share these objects between instances?
Color me puzzled.
|
|
|
|
|
You are correct they will be in their private address space.
However you could pass messages with object index in them.
Each process would have its own objects and you'd gain access to them
via the object index/id which you would use as a hashtable key/array index/
whatever.
You could also try something with a memory mapped file. All processes could
map the same file and try for the same load address. Then write your objects
in there. Yuck. Or worse, they don't load at the same address, so them you
are down to offsets from the memory mapped file address. Double yuck.
Can't think of anything for now...
Stephen Kellett
--
C++/Java/Win NT/Unix variants
Memory leaks/corruptions/performance/system problems. UK based.
Problems with RSI/WRULD? Contact me for advice.
|
|
|
|
|
I don't have too much experience with them, but couldn't you use an Atom if it's a string value that you're trying to store? Do Atoms work for non-string items?
Jamie Nordmeyer
Portland, Oregon, USA
|
|
|
|
|
Is an NT service an option? If so, this is a good way to do what you asked.
If not (and MFC is an option), look at the CMemFile class. There are samples on MSDN.
If MFC and CMemFile are not an option you can still use API functions to create memory mapped files. Check out this link to the MSDN library:
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dllproc/hh/winbase/dll_9khl.asp
If none of these options will work for you, you can create a second EXE which will host a named pipe or other inter-process communication layer (TCPIP listner) which can be launched to distribute the data. (This is probably overkill, though.)
Thanks
Matt Gullett
|
|
|
|
|
I have extensive experience with shared memory and, to the best of my knowledge, what you are attempting is not possible. What you could do though is separate the data from the methods and declare structures that you place in a memory mapped file. You could then create objects that map to invidual instances of the data structures. I have done similar things and, while it isn't exactly clean, it is workable and not overly complex. Unfortunately, character strings must be either of fixed length or allocated from a 'pool' of characters. If the data structures are highly dynamic then the fixed length option is probably better.
Best of luck.
|
|
|
|
|
Hello, today I've done my first DLL...
----------------------------------------
Environment:
VC++6 SP4.
MFC DLL.
The DLL must be called from a service.
----------------------------------------
I have placed on it the code that worked for me in another program.
I have exported the function (there is only one function in the DLL) using __declspec (dllexport) in the ".h" file, after doing so I have modified the DEF file and I've placed on it the name of the function a whitespace and @1.
(I don't know why the compiler knows wich is the function owner of that name, but this is only a little thing...)
After doing so I've compiled && linked the DLL, the service exe and the dll are in their respective RELEASE modes.
if in the dll function that starts the keyboard hook I write down a AfxGetApp()->m_hInstance, it crashes, if I write there a NULL, it doesn't make anything and if I write there a GetModuleHandle("aaa.DLL") it don't make anything too.
the code is correct (I think, at least it worked outside the DLL) and I know that I call the f(x) in the DLL because of some messageboxes placed in the DLL f(x).
I don't know why the keyboard hook is not working.
I need a Wide system keyboard hook...
As always thank you very much for your time and help.
if anybody wants to see the code or something else I can send it, I've not done it now because it would be a large download for everybody.
|
|
|
|
|
I'd like to have my MFC app run a separate console app and have its output redirected to an edit box inside of it -- sort of how Visual C++ works when you tell it to run a tool and it sends the output to the Output window.
How is that done?
Thanks,
Alvaro
|
|
|
|
|
Use hStdInput/hStdOutput/hStdError members of the strSTARTUPINFO structure. Don't forget about adding STARTF_USESTDHANDLES to dwFlags.
Tomasz Sowinski -- http://www.shooltz.com.pl
|
|
|
|
|
I have a window1. On some event, I create a message box using AfxMessageBox(). When the user enters ENTER or ESC in the latter one, it closes and the key is sent to the window1. As I need to handle these keys inside window1 for some other purposes, I would like to know if there is any way to prevent this sending.
Thank you in advance,
Andrei
|
|
|
|
|
I'm not sure if I've understood this right. Do you want to handle the returned result from the message box in window1 (the IDOK, IDCANCEL)? Or do you want the actual key press returned to the window. (VK_ESC, VK_ENTER)
The IDOK cancel is handled like below
int nResult = AfxMessageBox("My question here", MB_OK | MB_CANCEL");
if(nResult == IDOK)
{
// okay clicked
}
else
{
// cancel pressed
}
|
|
|
|
|
Sorry, it was my mistake. Now, I guess, question is more clear.
Actually, I need to prevent this sending a message to window1.
Now program operates like this:
1. some event;
2. message box;
3. user presses ESC or ENTER;
4. window1 operates like this key was pressed in it.
5. user gets not what he expected to see.
Andrei the Adroit
|
|
|
|
|
Thank you for reply.
I guess, my question was not so clear. Actually, I would like to have following results. I have ESC and ENTER keys handled in window1 for some purposes (say, events to draw something or not). When I call MessageBox the user answers it with a keyboard. The MB is closed AND the ESC or ENTER are then sent to my window1. As a result, user makes some changes in window1 even if he didn't want them. That's why I would like to prevent this sending.
|
|
|
|