|
I have a application have hte trayIcon with a Close menu, and it needs keep identical with task bar right click menu.
But if a Modal window shows, the application cannot be closed if uses [close] menu on the task bar, so I need to check if a modal window is showing, when user click the close menu on the tray icon.
|
|
|
|
|
I would suggest setting an application wide flag whenever a modal dialog is displayed.
The flag could be set in the WM_INITDIALOG handler.
When the modal dialog is closed, the flag can be reset.
These actions could be repeated for all modal dialogs in the application.
The same flag can then be checked from the tray.
|
|
|
|
|
Hi Superman,
Perhaps this will meet the recursion problem. And this project only use the C++ not MFC, so if there anyways to use the GetTopWindow or GetLastActivePopup to judge if there is a modal window showing?
|
|
|
|
|
Normally from the taskbar close menus you should send only WM_CLOSE to the main window and you should handle the program exit and "exit possible" flag from the WM_CLOSE handler of your main window. I would extend Superman's solution by using a counter instead of a bool, everytime a modal dialog opens increase the counter and everytime a modal dialog closes decrease the counter. If you have a lot of modal dialogs then you could automatize this by inheriting your dialog classes from a common class and you could implement this feature only once for all dialogs in the base class. So it is OK to close the main window only if your dialog counter is zero. Optionally you can grey out the close buttons/menuitems when the counter is nozero.
EDIT: Here is an alternative solution that MAY WORK, I haven't tried it: Usually when at least one modal dialog is active all other windows/dialogs in the background are disabled (with EnableWindow()[^]). So if the main window is disabled we can suspect that it is disabled because of a modal window (unless you are disabling it manually that I doubt). In this case you could use the IsWindowEnabled()[^] function on the main window to detect whether it is enabled or disabled. So all you have to do is cancelling the main window close (from your WM_CLOSE handler) if the main window is disabled (plus all you should do from your context menu close command is sending a WM_CLOSE to the main window so your WM_CLOSE handler will handle the main window close command regardless of the source of the command). CWnd also has an IsWindowEnabled()[^] method besides the winapi IsWindowEnabled().
modified 23-Sep-13 15:33pm.
|
|
|
|
|
|
Hey there
I have a HBITMAP object in my codeand now i want to use CreateFile function to open this object and then read it's contents.
How can i do that? Or is there another function to open and read the contents of the HBITMAP?
Thanks in advance.
|
|
|
|
|
HBITMAP is a handle to a bitmap object[^] in memory, not a file.
Veni, vidi, abiit domum
|
|
|
|
|
What do you want to do with the contents?
If you want to display the bitmap, you need to first create a device context using CreateDC and then select the HBITMAP into the device context using SelectObject .
You can then use the device context to display the image using the various bitmap functions - Bitmap functions[^]
|
|
|
|
|
|
How is the color of a font stored and processed? I see that the LOGFONT structure does not have a member for the color, nor does CFont .
How does the system keep track of the color of a font?
The difficult we do right away...
...the impossible takes slightly longer.
|
|
|
|
|
It doesn't; fonts do not have a colour attribute. When writing text to a device context you select the appropriate foreground and background colours that you wish to use.
Veni, vidi, abiit domum
|
|
|
|
|
Oh I see. I guess it depends upon what brush I use?
Thanks, Richard.
The difficult we do right away...
...the impossible takes slightly longer.
|
|
|
|
|
it's not a brush or pen, there's a GDI function called SetTextColor.
|
|
|
|
|
For text, the APIs used for color are SetTextColor and SetBkColor .
|
|
|
|
|
|
I have two applications that has a same structure and these two applications communicates values using the structure in shared memory created using CreateFileMapping, OpenFileMapping and MapViewOfFile. So Whenever a value in the structure is changed by application 1, it gets reflected in appliction 2 and viceversa. This is fine.
But the 2 applications are running in the same machine. Now I want to make the 2 applications run in separate machines connected within a LAN and I require the same functionality (i.e. Communication between the 2 applications) without any synchronization issues.
Anybody, Please suggest me the best way to implement this and also the step by step method of code to achieve this. .
|
|
|
|
|
Please do not crosspost the same message in multiple forums.
Veni, vidi, abiit domum
|
|
|
|
|
Hi Everyone,
I want to place MFC control in RunningObjectTable. Is this possible?. If yes how can we place it in RunningObjectTable?
Regards,
Rajendar.
|
|
|
|
|
|
For inter process communication
|
|
|
|
|
Rajendarmanda wrote: For inter process communication OK, and what exactly does that add by way of explanation? Please think about what problem you are trying to solve, and give some proper details of where you are stuck. If your question begins with "How do I ...", or "Is it possible ...", then you will most likely find some useful information through Google searches.
Veni, vidi, abiit domum
|
|
|
|
|
Actually we have placed COM object into RunningObjevtTable(ROT) but when we try same thing for MFC it is not working. we are suspecting whether we put MFC object into ROT or not?
|
|
|
|
|
Rajendarmanda wrote: when we try same thing for MFC it is not working. Then you will need to do some debugging to try and identify why.
Veni, vidi, abiit domum
|
|
|
|
|
I am trying to run a modal dialog in a property page.
The dialog is located in static library.
Here is the implemetation of DoModal
int C_MAINPropertyPage4::OnCreate(LPCREATESTRUCT lpCreateStruct)
{
if (CPropertyPage::OnCreate(lpCreateStruct) == -1)
return -1;
pCWaveInFFTDlg.DoModal();
return 0;
}
And here is where CDialog fails, in FindResource:
// load resource as necessary
LPCDLGTEMPLATE lpDialogTemplate = m_lpDialogTemplate;
HGLOBAL hDialogTemplate = m_hDialogTemplate;
HINSTANCE hInst = AfxGetResourceHandle();
if (m_lpszTemplateName != NULL)
{
hInst = AfxFindResourceHandle(m_lpszTemplateName, RT_DIALOG);
hInst looks OK
HRSRC hResource = ::FindResource(hInst, m_lpszTemplateName, RT_DIALOG);
hResource is NULL, so it fails from here on.
hDialogTemplate = LoadResource(hInst, hResource);
}
if (hDialogTemplate != NULL)
lpDialogTemplate = (LPCDLGTEMPLATE)LockResource(hDialogTemplate);
// return -1 in case of failure to load the dialog template resource
if (lpDialogTemplate == NULL)
return -1;
When I run this dialog in its own project the hInst returns same value as when I run it in my application. The m_lpszTemplateName is also same , empty, when run in its own project or in my application.
I did run the DoModal in property page OnInitDialog with same result.
I did copy the source from the original to my static library and I am at lost what “resource template” is missing.
Any help would be appreciated. Of course I am still using VC 6.0 and MFC.
Cheers
Vaclav
|
|
|
|
|
Every module (exe or dll or whatever) can contain a resource tree that contains different kind of resources (icon, dialog template, cursors, wav sound, popup menus, binary data, ... the list is increasing). You usually compile an .rc file into a .res file and currently you can link only one .res file into the final module (exe or dll) and the linker composes the (search) tree from the resource list. Resources declared in a static libs don't link to the modules from which you use the static libs themselves. Correct me if I'm wrong but I've burnt myself with this several times so I avoid using resources in static libs. To my best knowledge there is no solution to this problem in newer visual studio versions. http://stackoverflow.com/questions/531502/vc-resources-in-a-static-library[^]
If you compile your library as a DLL then your DLL can have its own resources and you can use the HMODULE received as the first parameter of the DllMain() as your hInst when you call FindResource().
Additional advice: Use ResHacker to check out the resource tree of an exe or dll.
|
|
|
|