|
Use a flag, when you press a button on a dialog or something, set your flag to TRUE and in WM_INITMENU you check whether your flag is TRUE or FALSE and then use EnableMenuItem() to disable/enable/etc your item.
Is everything clear?
Rickard Andersson8
Here is my card, contact me later!
UIN: 50302279
E-Mail: nikado@pc.nu
Interests: C++, ADO, SQL, Winsock, 0s and 1s
|
|
|
|
|
Thanks for your help. I used EnableMenuItem(0with an if statement and it worked.
|
|
|
|
|
You could use the ON_UPDATE_COMMAND_UI messages for your menu IDs if you're using MFC.
|
|
|
|
|
|
An application must use the MF_BYPOSITION flag to specify the correct menu handle. If the menu handle to the menu bar is specified, the top-level menu item (an item in the menu bar) is affected. To set the state of an item in a drop-down menu or submenu by position, an application must specify the handle to the drop-down menu or submenu.
When an application specifies the MF_BYCOMMAND flag, Windows checks all items that open submenus in the menu identified by the specified menu handle. Therefore, unless duplicate menu items are present, specifying the menu handle to the menu bar is sufficient.
// Afterall I realized that even my comment lines have bugs
|
|
|
|
|
Sorry but I forgot to mention that I got that from the API reference so you can refer to that for more information. I have used this function before, and I never had a problem with it.
// Afterall I realized that even my comment lines have bugs
|
|
|
|
|
I didn't realize that you were asking about MFC. My approach won't work with MFC. Sorry about that.
// Afterall I realized that even my comment lines have bugs
|
|
|
|
|
I want to get the word user typed and read it with SAPI.
The code as follow:
<br />
#pragma data_seg("shared")<br />
HHOOK m_hHook=NULL;<br />
ISpVoice * pVoice = NULL;<br />
HRESULT hr =NULL;<br />
#pragma data_seg()<br />
#pragma comment(linker,"/section:shared,rws")<br />
HINSTANCE glhInstance=NULL;<br />
<br />
.................<br />
BOOL CHookKBDApp::InitInstance() <br />
{<br />
glhInstance=::AfxGetInstanceHandle();<br />
if (FAILED(CoInitialize(NULL)))<br />
{<br />
AfxMessageBox("Error to intiliaze COM");<br />
return FALSE; <br />
}<br />
return CWinApp::InitInstance();<br />
}<br />
..............<br />
StartHook()<br />
{<br />
...<br />
m_hHook=::SetWindowsHookEx(WH_CALLWNDPROC,CallWndProc,glhInstance,0);<br />
......<br />
<br />
LRESULT CALLBACK CallWndProc(int nCode, WPARAM wParam, LPARAM lParam )<br />
{<br />
if( SUCCEEDED( hr ) )<br />
{<br />
hr = pVoice->Speak(test.AllocSysString(),SPF_DEFAULT,NULL); <br />
}<br />
}<br />
<br />
I don'y know where the bug is ,please someone tell me it!
thanks a lot!
Don't look at me in that way!
|
|
|
|
|
Hi!
I met some questions when I am doing some serial communication recently. I will appreciate it very much if anyone can give me tips or suggestions. And my question is described as follow:
When I communicate with another computer thru Null-cable with COM port, I found when my reading buffer is not big enough to contain the incoming data, certainly I cannot dispose the packet correctly. But when I give a bigger buffer, the seperate incoming packets will be merged in the incoming buffer. (I implement this by ReadFile(hComport, pReadBuf, nReadBufLen, &nRealBufLen, &osRead);). Is there any method to process the flow control? BTW, to manipulate RTS/CTS/DTR/DSR when there is no modem, does it have effect on the hardware/communication?
Thanks again!
|
|
|
|
|
I am not sure what the problem is but I'll try to make some sugestions.
If you are not currently using flow control (on transmit end) then you could use GetCommState(), to get the current DCB state and modify it, and then use SetCommState(). You may also need to use SetCommTimeouts() to set the time-out pramenters. (Search MSDN for examples of using GetCommState(), SetCommState(), and SetCommTimeouts())
If you know the size of the packets before they arrive you could use ClearCommError() to find out if there are at lease that many bytes in the InQue before you read out a packet size number of bytes. (or keep reading, and coping, until you receive packet size bytes)
If you do not know the packet sizes before hand then each packet needs to start with a header(record/struct) that gives you information on the packet, such as the number of bytes following the header and possibly a checksum for the packet, to insure the packet is not corrupt. For PC to PC transfer via comport the checksum is usualy not needed, but better safe than sorry.
There are some aticles on this sight that may be of some help (Search for "Serial port"). There are also some samples in the MSDN Library.
Trust in the code Luke. Yea right!
|
|
|
|
|
I'm writing a bucket hashTable template:
template<class Key, class Data, class HashFunc, class KeyEqualFunc>
class Hash
{
public:
typedef Key key_type;
typedef Data data_type;
typedef List< pair<key_type, data_type> >::iterator listIter ;
...
listIter find(const key_type& key) const;
..
private:
...
.
};
When implementing the find method, I cannot use listIter:
template<class Key, class Data, class HashFunc, class KeyEqualFunc>
listIter CsHash<Key, Data, HashFunc, KeyEqualFunc>::find(const key_type& key) const {....}
Instead I have to write this long declaration:
template<class Key, class Data, class HashFunc, class KeyEqualFunc>
CsHash<Key, Data, HashFunc, KeyEqualFunc>::listIter CsHash<Key, Data, HashFunc, KeyEqualFunc>::find(const key_type& key) const
{....}
Any suggestions how to make it shorter (and readable)?
|
|
|
|
|
If you're willing to live with #defines, I guess you could do something like this:
#define Template_CsHash template<class Key, class Data, class HashFunc, class KeyEqualFunc>
#define CsHash_T CsHash<Key, Data, HashFunc, KeyEqualFunc>
which allows this:
Template_CsHash
CsHash_T::listIter CsHash_T::find(const key_type& key) const
{....}
|
|
|
|
|
I did not know you could use typedef with in a class, it seems totaly ilogical to me. I would move the typedefs out side of the class if possible.
I suggest you look at the STL (standard template libraray) hash template, may be it will help.
Hey I am an expert on C not C++ (who is), even with 8 years of experiance in C++ (mosly MFC).
|
|
|
|
|
Does anybody knows how to open a txt file and display the results in a Listbox or edit box. The txt file contains 6 to 8 lines.
Any help will be greatly ppreciated
|
|
|
|
|
1. Take a look at CFile and CArchive in order to easily read the contents of the file.
2. ListBox: Create a var for the ListBox using the class wizard (Ctrl + W) and use Listbox.AddString this should do the thing.
3. EditBox: Create a var for the editctrl it can be a CString and then you can use that CString to modify the content of the control; read about UpdateData(); if you want, you can also declare a var of type CEditCtrl (control type in the class wizard) and then use controlvar.SetWindowText("...)...
Hope this helps...
|
|
|
|
|
Hi. I have a CMapWordToPtr object, the pointers in the CMap point to CStringArray.
The problem is, when i want to empty the cmap i don't free the memory. By MS documentation CStringArray::RemoveAt or RemoveALL should be enough, but it doesn't seem to work:
--------------------------
CMapWordToPtr *MyMap
...blablabla...
int size,i;
word key:
CStringArray *MyArray;
void *temp;
POSITION p=MyMap->GetStartPosition();
while(p){
MyMap->GetNextAssoc(p,key,temp);
MyArray= (CStringArray) temp;
size=MyArray->GetSize();
for(i=0;i<size;i++){
myarray-="">RemoveAt(0);
MyArray->FreeExtra();
}
}
MyMap->RemoveAll();
...blablabla
--------------------------
It's a major memory leak, I've tried a lot of ways and only managed to bang my head to the wall.
|
|
|
|
|
RemoveAll doesn't delete what the pointer points to. You need to go through and call "delete" on everything you called "new" on.
|
|
|
|
|
Heyas all,
Newbie Windows programmer here, I'm attempting to run an external batch file from within my console app like so:
ShellExecute(NULL, "open", "s:\\dir\\file.bat",NULL, NULL, SW_SHOWNORMAL);
The program works perfectly testing it locally, but when I run it on the target machine, the program runs but fails to run the specified batch file. s:\ is a mapped network drive.
Anyone have an info that may help me? Anything is greatly appreciated.
Thanks!
Digital Khaos
"Diplomacy is dead. Feel my wrath!"
|
|
|
|
|
Try to use WinExec( filename, SW_SHOW ) [check the parameters]. It's easier to use this until you learn how to use ShellExecute.
// Afterall I realized that even my comment lines have bugs
|
|
|
|
|
Check the return value!
I would not recommend you to use WinExec() becuse it is an old API for 16 bit system.
Rickard Andersson8
Here is my card, contact me later!
UIN: 50302279
E-Mail: nikado@pc.nu
Interests: C++, ADO, SQL, Winsock, 0s and 1s
|
|
|
|
|
How are you confirming that the batch file indeed did not run? Why are you not checking the return value of ShellExecute()?
As much as the S: drive has to be mapped on the other machine, so does the file.bat file need to exist.
HINSTANCE hInstance;
if (_access("s:\\dir\\file.bat", 0) == 0)
hInstance = ShellExecute(NULL, "open", "s:\\dir\\file.bat", NULL, NULL, SW_SHOWNORMAL);
To get more detailed information, you might consider using ShellExecuteEx().
|
|
|
|
|
Dear all,
I need to use an array of Book pointers (BookList) and Member (MemberList). Both of them are compound (container) classes.
The component objects are books and members (up to 10)for each list respectively. Is the below implementation of the array.h file correct?
#ifndef _ARRAY
#define _ARRAY
const int MAX_VALUE=10;
template<class Object>
class Array
{
public:
Array(int maximum=10);
~Array();
......
private:
Object* array_list[MAX_VALUE];
//To keep track of the elements into the list.
int num_of_elements;
};
#endif
Regards,
grscot
|
|
|
|
|
It looks OK, but does it compile? If it compiles, the rest is a matter of making sure it has no bugs, which the debugger will help you determine.
Now, as far as what I would do if I were you, I'd try to use a container class from one of the available libraries, be it MFC or STL. STL is more sophisticated and portable, but also more difficult for beginners. MFC is simpler and better documented. So take your pick:
MFC: typedef CTypedPtrArray<CPtrArray, Book> BookList;
STL: typedef vector< auto_ptr<Book> > BookList;
Regards,
Alvaro
When birds fly in the right formation, they need only exert half the effort. Even in nature, teamwork results in collective laziness. -- despair.com
|
|
|
|
|
Thanks a lot
Alvaro Mendez
Regards,
grscot
|
|
|
|
|
std::vector s of auto_ptr s are a no-no. There are tons of articles explaining why this is not safe --briefly put, STL assumes objects inside a container have standard copy semantics, which auto_ptr s do not have.
Instead, one can use boost::shared_ptr (see www.boost.org[^]).
Joaquín M López Muñoz
Telefónica, Investigación y Desarrollo
|
|
|
|
|