|
the magic words are "owner drawn menu". there are a few articles here on CodeProject which can get you started.
|
|
|
|
|
thanks for the replies
I've managed to change the look of a menu
but now i've realised i don't know how to get the item selected for the WM_UNINITMENUPOPUP message. well, i can get the item the mouse was last over while the menu is still popped up, but if the user cancels the popup menu i want to set the item_selected to -1. it's difficult to explain. i think the WM_UNINITMENUPOPUP message is sent before the WM_COMMAND message so when the popup is destroyed i can't get the item clicked (command made) at destruction / cancelation time. how do i go about getting the command when the popup has sent the WM_UNINITMENUPOPUP ?
hope this makes sense, i've tried different things like GetMenuItemInfo, GetMenuState during WM_UNINITMENUPOPUP, but with no luck ??
|
|
|
|
|
ah, i've now realised there was no need for a message loop. so i made it so TrackPopupMenu returns the selected item. but now i can't understand why a message box won't show after TrackPopupMenu is called.
this is what i have :
item_selected = TrackPopupMenu(menu, flags, x, y, 0, hwnd, NULL);<br />
<br />
MessageBox(NULL, "Got to the end of showPopupMenu !", "Success!", MB_ICONEXCLAMATION | MB_OK);<br />
<br />
return item_selected;
any idea why the message box won't show ?
if i put it before TrackPopupMenu it shows but not after
|
|
|
|
|
i fixed the problem
because my program is a dll
i actually create an invisible window so i have a window procedure for the popup menu, when the popup menu gets destroyed it calls DestroyWindow to destroy the invisible window.
for some reason when i use a message loop after TrackPopupMenuEx the loop catches the WM_DESTROY message, quits the loop and after that MessageBox works.
it fixes the problem (MessageBox didn't show) but i don't quite understand why ?
here's a snippet of code
item_selected = TrackPopupMenuEx(menu, flags, x, y, hInvisibleWindow, NULL);<br />
<br />
<br />
int result = 0;<br />
<br />
MSG msg;<br />
<br />
while( (result = GetMessage( &msg, NULL, 0, 0 )) != 0)<br />
{ <br />
if (result == -1)<br />
{<br />
}<br />
else<br />
{<br />
TranslateMessage(&msg); <br />
DispatchMessage(&msg); <br />
}<br />
}<br />
<br />
MessageBox(NULL, "Got to the end of showPopupMenu !", "Success!", MB_ICONEXCLAMATION | MB_OK);
code from the WndProc
case WM_UNINITMENUPOPUP:<br />
DestroyWindow(hInvisibleWindow);<br />
break;<br />
case WM_DESTROY:<br />
PostQuitMessage(0);<br />
break;<br />
default:<br />
return DefWindowProc(hwnd, msg, wParam, lParam);
|
|
|
|
|
/*
Visual Studio 2008
Vector is a template class,and there is a class iterator in Vector;
I declare the function operator== as the iterator's friend function
(according to C++Primer,we'd better declare operator== as a friend function)
then how to do that? how to write the friend function operator== ?
the compiler can not deduce T,help me please!
I am a Chinese student,my English is not very good,I hope
you can understand me! ^-^
*/
#include<iostream>
using namespace std;
template<typename T> class Vector;
template<typename T> bool operator==(typename Vector<T>::iterator it1,typename Vector<T>::iterator it2);
template<typename T> class Vector
{
public:
class iterator
{
friend bool operator==(typename Vector<T>::iterator it1,typename Vector<T>::iterator it2);
};
};
template<typename T> bool operator==(typename Vector<T>::iterator it1,typename Vector<T>::iterator it2)
{
return true;
}
int main()
{
Vector<int>::iterator it1,it2;
//cout<<(it1==it2)<<endl;//failed,can not deduce the T,why? help me!
cout<<operator==<int>(it1,it2)<<endl;//success,but not very useful
return 0;
}
|
|
|
|
|
As workaround, you may define the == operator as member of th iterator class:
template<typename T> class Vector
{
public:
class iterator
{
public:
bool operator==(iterator it2)
{
}
};
};
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
[My articles]
|
|
|
|
|
This should be fine.
template<typename T>
bool operator==(T it1, T it2)
{
return true;
} Now compiler will be able to infer the type correctly.
wanchao507 wrote: according to C++Primer,we'd better declare operator== as a friend function)
Scott Meyers says, declare operator overload functions as non-member functions and make it friend only if it requires access to internals.
Best wishes,
Navaneeth
|
|
|
|
|
Thanks for Navaneeth.
You inspired Me.
I solved the problem successfully.
A very hard question? friend function again! remember my Question.
I declare the operator== as the class iterator's friend function just because
i want to access its private members.you mentioned that.
I reply the Question too,so others who meet with the same Question can get help!
my answer is just below yours!
Anyway,here I want to Thank You for your help!
|
|
|
|
|
You are welcome. You really don't have to make iterator a class. Iterators can be implemented using simple pointers.
Best wishes,
Navaneeth
|
|
|
|
|
Thanks for Navaneeth.
You inspired Me!
I solved the problem successfully
I hope my source code below can help others who meet with the same problem!
#include<iostream>
using namespace std;
template<typename T> bool operator==(T it1,T it2);
template<typename T> class Vector
{
public:
class iterator
{
friend bool operator==<Vector<T>::iterator>(typename Vector<T>::iterator it1,typename Vector<T>::iterator it2);
public:
iterator(int a=0):value(a){}
private:
int value;
};
};
template<typename T> bool operator==(T it1,T it2)
{
if(it1.value!=it2.value)
{
return false;
}
return true;
}
int main()
{
Vector<int>::iterator it1(0),it2(1);
cout<<(it1==it2)<<endl;
return 0;
}
|
|
|
|
|
Hi ,
May i know how the static variable is stored in memory...
and is it right if i declare static variable inside class but not outside the clas...
|
|
|
|
|
kumar sanghvi wrote: May i know how the static variable is stored in memory...
I'm not sure what you mean by this. The variable is stored in the program's data space and exists for the life of the program.
kumar sanghvi wrote: and is it right if i declare static variable inside class but not outside the clas...
A static declared inside a class is a class variable and can only be accessed through the class name. A static declared outside a class may be accessed directly in a function, module or application depending on where it is declared.
I suggest a re-reading of the C++ documentation on variables for more information.
|
|
|
|
|
Alright, I've ran into a problem that I'm really confused over:
I'm writing a simple mail client. It runs fine on my computer (Windows XP, SP2). However, when ran on a Vista machine, it crashes. Not as in BSOD-crash, it's more like the whole system just freezes over. A friend of mine, who was testing it on her vista machine, she says that everything just freezes (including the mouse) and the few times she had music on,
*the last few times
*i had musci on
*but not this time
*and it like..
*Stutters
*in that spot
I managed to trace it down to here:
MessageBox(NULL,"got here 1","okay",MB_OK);
closesocket(hSocket);
hSocket = NULL;
MessageBox(NULL,"got here 3","okay",MB_OK);
The first msgbox shows, but the second doesn't. (friend of mine isn't exactly computer-savvy, so I put the messageboxs in there so she could test the app).
I'm really stumped by this, because it works fine on XP. What does Vista change that doesn't allow the proper disconnection and closing of a socket?
If it changes anything, this is all happening in a seperate thread, started by a call to AfxBeginThread inside a WH_KEYBOARD_LL callback function. But that shouldn't make a difference, should it?
If any more info is needed, just ask. It's a rather large piece of code, so it's hard for me to describe everything that's going on.
Thanks in advance.
|
|
|
|
|
Did you try it on more than one Vista machines? Does it crash at the same spot on every vista computers? You mentioned that it is happeneding in a separate thread, so, could it be a synchronization error? I mean, synchronization errors tend to be different depending on a lot of things, for example we had such error(s) that would never pop up on a single core muchine but they would happen almost every time on dual core systems, also they can depend on timings, for example you could have such an error that doesn't pop up at first but if you run winamp and start playing your favourite music then it does because if the computer has more things to do then your process/threads get less CPU time and then somethings that before did not happen simulteniously before will happen now and cause the problem...
Also, are you sure your hSocket is valid?
> The problem with computers is that they do what you tell them to do and not what you want them to do. <
> Sometimes you just have to hate coding to do it well. <
|
|
|
|
|
Again, sorry for the vagueness.
No, I haven't tried it on more than 1 Vista machines, and I doubt it's a synchronization error. All the thread does is create an email header and sends it, while the main thread is open for the UI. Aside from the 4 variables passed to the thread at the start, the thread doesn't even use any of the variables used in the main thread.
Yes, I'm sure my hSocket is valid, as I seem to be able to send emails using it.
I'm going to try it on some more vista machines today, thanks for the suggestion.
|
|
|
|
|
hxhl95 wrote: If it changes anything, this is all happening in a seperate thread, started by a call to AfxBeginThread inside a WH_KEYBOARD_LL callback function. But that shouldn't make a difference, should it?
Introducing multiple threads will always make a difference. Race conditions, sharing of resources, deadlocks, and context switches are just some of the things that come into play above and beyond the normal stuff.
"Old age is like a bank account. You withdraw later in life what you have deposited along the way." - Unknown
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
|
|
|
|
|
im develping a Win32 Program with the name """"Add"""" that takes a """string""" as input at command line. The command line argument should be of the following format (commandline argument may be provided from DOS console):
D:\Add\Debug>Add 2,4
The program will extract the integer values from commandline string (e.g. it will extract the values “2” and “4” in above argument) and will add them, finally the result will be displayed in a message box:
wht i did so far
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE prevInstance, LPSTR lpCmdLine, int nShowCmd)
{
LPWSTR *szArgList;
int argCount;
szArgList = CommandLineToArgvW(GetCommandLine(), &argCount);
if (szArgList == NULL)
{
MessageBox(NULL, L"Unable to parse command line", L"Error", MB_OK);
return 10;
}
for(int i = 0; i++; i < argCount)
{
MessageBox(NULL, szArgList[i], L"Arglist contents", MB_OK);
}
LocalFree(szArgList);
return 0;
}
|
|
|
|
|
can anyone help me to complete it ,im stuck
thanks
|
|
|
|
|
Is your application compiled with UNICODE support?
Write your WinMain as _tWinMain .
Also you command line must look like Add 2 4 .
Your for loop is wrong.
It must be -
for (int i = 0; i < argCount; ++i)
{
MessageBox(NULL, szArgList[i], L"Arglist contents", MB_OK);
}
|
|
|
|
|
did you mean the fllowing code i tried? having errors
really not getting through !! kindly help me
what i want to have is
------------------------
a Win32 Program with the name “Add” that takes a string as input at command line. The command line argument should be of the following format (commandline argument may be provided from DOS console):
D:\Add\Debug>Add 2,4
The program will extract the integer values from commandline string (e.g. it will extract the values “2” and “4” in above argument) and will add them, finally the result will be displayed in a message box:
-----------------------
what i did
#include "stdafx.h"
int APIENTRY WinMain(HINSTANCE hInstance,
HINSTANCE hPrevInstance,
LPSTR lpCmdLine,
int nCmdShow)
{
LPWSTR *szArgList;
int argCount;
szArgList = CommandLineToArgvW(GetCommandLine(), Add 2 4 );
if (szArgList == NULL)
{
MessageBox(NULL, L"Unable to parse command line", L"Error", MB_OK);
return 10;
}
for (int i = 0; i < argCount; ++i)
{
MessageBox(NULL, szArgList[i], L"Answer is", MB_OK);
}
LocalFree(szArgList);
return 0;
}
|
|
|
|
|
Get a book and learn the basics.
Assignment questions are not appreciated here.
|
|
|
|
|
Ok, so what exactly is the problem? Hint: "It doesn't work" does not qualify as an answer.
"Old age is like a bank account. You withdraw later in life what you have deposited along the way." - Unknown
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
|
|
|
|
|
Hi,
I have successfully implemented serialization of various collection classes even when the data contained CStrings so I'm very familiar with the requirements.
However, I have attempted to serialize a CArray <myclass, myclass&=""> MyCArray from a CPropertyPage class (to save various page defaults) and I noticed that the following serialize overrides are never executed when MyCArray.Serialize(archive) is called and CStrings recovered from the archive are either empty or have a bad pointer. Integers recovered from the archive are correct.
CMyClass : public CObject
{
DECLARE_SERIAL(CMyClass)
public:
void Serialize(CArchive& ar);
....
}
class CMyPage : public CPropertyPage
{
DECLARE_DYNAMIC(CMyPage)
public:
CArray < CMyClass, CMYClass& > MyArray;
.....
}
MyClass::Serialize(CArchive& ar)
{
}
and
template <> void AFXAPI SerializeElements < CMYClass > (.....)
Assuming there no's easy fix, is there another simple method could I use to save a small amount of default data to disk (integers and CStrings). I'm just trying to allow the user to save the various property page settings so they do not have to enter them each time.
Thanks
P.S. What's really strange and really frustrating is that on another property page I have a CArray < CString, CString& > MYStringArray and it serializes correctly! Could CPropertyPages have it's own Serialize function ?
modified on Saturday, November 7, 2009 9:12 PM
|
|
|
|
|
Try changing DECLARE_DYNAMIC(CMyPage) to DECLARE_SERIAL(CMyPage)
|
|
|
|
|
Superman,
DECLARE_SERIAL did not help but I forgot to mention that in the module where I write the archive, I have some test code which immediately reads back the archive. In this case, the CArray is always correct.
It's when the Property page is closed, re-entered and the archive read that the CStrings have bad pointers. The doubles and ints are OK. I also occasionally get some odd errors like "out of memory" or a locked buffer assertion when I exit the property page (but only when the property page has read the archive).
I can seperate the CStrings and ints/doubles into 2 different archives/files since the files are transparent to the users anyhow. As I said, a CArray < CString, CString& > serializes OK.
modified on Sunday, November 8, 2009 5:31 PM
|
|
|
|
|