|
Hello all,
I have quite a strange problem. My program is based on MFC dialog but modeless. It starts hidden and creates a tray icon. The user can exit it in two ways: if the program is visible the user can press the exit button; if the program is not visible the user can right click on the tray icon and press exit. Both of these message handle routines call CWnd::DestryWindow which calls my OnDestroy which calls Shell_NotifyIcon( NIM_DELETE, ... ). On XP and 7 everything works fine but on Vista when the app is exiting through the tray icon message handler the call to Shell_NotifyIcon( NIM_DELETE, ... ) returns FALSE with GetLastError() returning 0. The result is that the icon does not disappear with the exiting of the app but only when the tray bar is refreshed (the mouse goes over it).
Any ideas will be highly appreciated.
|
|
|
|
|
The NOTIFYICONDATA structure variable is probably changing or a different variable is used for NIM_DELETE .
The fact that it happens only for Vista is strange though.
|
|
|
|
|
Why not using a different variable?! On app startup the following code creates the icon:
NOTIFYICONDATA tnd;
tnd.cbSize = sizeof(NOTIFYICONDATA);
tnd.hWnd = this->GetSafeHwnd();
_tcscpy_s(tnd.szTip, _T("My app"));
tnd.uCallbackMessage = UWM_TRAY_ICON;
tnd.uFlags = NIF_MESSAGE | NIF_ICON | NIF_TIP;
tnd.hIcon = AfxGetApp()->LoadIcon(IDI_MAIN_ICON);
tnd.uID = ICONNUMBER;
::Shell_NotifyIcon(NIM_ADD, &tnd);
And on exit inside OnDescroy:
NOTIFYICONDATA tnd;
tnd.cbSize = sizeof(NOTIFYICONDATA);
tnd.hWnd = this->GetSafeHwnd();
tnd.uID = ICONNUMBER;
::Shell_NotifyIcon(NIM_DELETE, &tnd);
What is wrong with this code?! ICONNUMBER is the same. Isn't this relevant?
Martin
|
|
|
|
|
That is probably true, but you could try to use the same tnd variable by keeping it as a class member or making it global.
|
|
|
|
|
The result is the same. The interesting thing is that through one of the methods the icon is destroyed. Probably the answer has to be searched in the way the dialog is destroyed.
|
|
|
|
|
Actually the result IS NOT the same. When I made the structure a class member and used it to create and delete the icon everything works fine. The question still remains why is that.
|
|
|
|
|
mkoroudjiev wrote: tnd.uID = ICONNUMBER;
Do you have more than one icon associated with the window handle? If not, then this statement is unnecessary. Otherwise, you'll need to set the uFlags member to NIF_ICON .
"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
|
|
|
|
|
No, I don't have more than one icon but just in case in the future we decide to add additional one I set the uID field. And I set also the uFlags to NIF_ICON.
|
|
|
|
|
What does the following code declare?
I think it declares a structure 'node' comprising of a data value and other one is an address.
But cant we name the 'next' with a different pointer name?
Why is this named with the same name as of the structure?
struct node {
int data;
struct node* next;
};
The complete code is below:
struct node {
int data;
struct node* next;
};
/*
Build the list {1, 2, 3} in the heap and store
its head pointer in a local stack variable.
Returns the head pointer to the caller.
*/
struct node* BuildOneTwoThree() {
struct node* head = NULL;
struct node* second = NULL;
struct node* third = NULL;
head = malloc(sizeof(struct node)); // allocate 3 nodes in the heap
second = malloc(sizeof(struct node));
third = malloc(sizeof(struct node));
head->data = 1; // setup first node
head->next = second; // note: pointer assignment rule
second->data = 2; // setup second node
second->next = third;
third->data = 3; // setup third link
third->next = NULL;
// At this point, the linked list referenced by "head"
// matches the list in the drawing.
return head;
}<pre></pre>
|
|
|
|
|
Razanust wrote: Why is this named with the same name as of the structure?
Because next is also a node . Got it?
Best wishes,
Navaneeth
|
|
|
|
|
Razanust wrote: Why is this named with the same name as of the structure?
Because that is a pointer variable, which points to another similar structure (or may point to NULL if it is the last node). I suggest that you take a look at the Wikipedia Entry[^], which illustrates this with a diagrams (that must help you understand it better).
“Follow your bliss.” – Joseph Campbell
|
|
|
|
|
Razanust wrote: I think it declares a structure 'node' comprising of a data value and other one is an address.
Yes, the address field points to another 'node': this way linked lists work.
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]
|
|
|
|
|
Deleted.
modified 9-Jul-13 12:10pm.
|
|
|
|
|
Look at LayeredWindows[^] for starters. The only way i can think of to connect this with OpenGL is to render your graphic into a bitmap with OpenGL and then use this bitmap to update your layered window. Hope this helps something.
> 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. <
|
|
|
|
|
(Question 1): How do you obtain the data contained in the various CPropertyPage(s) that the CPropertySheet loaded by the AddPage() function?
(Question 2): How do you find out which page the User is presently on? Ex: how do I find out when all the data has been entered?, so I can collect the data entered(once I find out how to get the data from the CPropertyPage(s))
A C++ programming language novice, but striving to learn
|
|
|
|
|
1) CPropertySheet::GetPage(int index) will return a pointer to a CPropertyPage object, which can be cast to a specific CPropertyPage derived class pointer; e.g., CMyPage* page = (CMyPage*)MySheet->GetPage(0); .
2) Likewise, CPropertySheet::GetActivePage()will return a CPropertyPage pointer to the active page. There's also a GetActiveIndex() which returns the integer index of the active page.
|
|
|
|
|
1) treat each property page like a standard dialog: it reads and sets member variables that the owner can then set and read.
|
|
|
|
|
In a Standard dialog you have a CWnd object in it's constructor, the "CBCGPPropertySheet" constructor does not. (see constructor below
"CPropSheet(CBCGPPropertySheet::PropSheetLook look,UINT uiIconsResID = 0, int cxIcon = 0);"
If it had an CWnd object I could easily pass that to the propertypage, How could I obtain the CWnd of the "CBCGPPropertySheet" so I can use it for the propertypage could load inline functions in the CBCGPPropertySheet object?(see inlines below
" //inline functions:
void SetDate(CString csDate){ m_csDate = csDate;}"
A C++ programming language novice, but striving to learn
|
|
|
|
|
why do you need a CWnd ?
if you are creating the property sheets, you have the objects themselves - you don't need a CWnd.
|
|
|
|
|
Are you wanting the pages to communicate with the sheet, or the pages to communicate with each other?
"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
|
|
|
|
|
I may need both. I'm not certain yet which way is best. Could you show me an example of both. I'll try the examples an see which is best in my program.
A C++ programming language novice, but striving to learn
|
|
|
|
|
Store the data in the sheet, and use the QuerySiblings() method to forward a message to each page in the sheet. If a page needs to get/put the data, it can get to it via GetParent() .
"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
|
|
|
|
|
Thanks.
A C++ programming language novice, but striving to learn
|
|
|
|
|
I'm trying to write a program that will use ETW, but I'm feeling completely baffled by it. I've read as much documentation as I can find, I've tried looking for samples, and I've been Googling for two weeks. I don't understand much of what I read, and I have no idea how to apply what I do understand.
I think I'd understand it better if I had a very bare bones C/C++ program that used it. What I had in mind was a program that waits for one minute, and then couts the total amount of disk activity that occurred in that minute, as measured by ETW.
How would one do this?
|
|
|
|
|
i_kant_spel wrote: I'm trying to write a program that will use ETW...
Event Tracing for Windows?
"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
|
|
|
|