|
See here.
"Ideas are a dime a dozen. People who put them into action are priceless." - Unknown
|
|
|
|
|
|
Hi everybody,
I have created an PopUp Menu in a CDialog...it works OK.
Now I want to create a PopUp Menu inside an ActiveX every time I click Button RIGHT of the mouse...
I have copied the code inside the function WM_RBUTTONDOWN...The problem is that it shows the Menu but it is DISABLED (it is shown but I can not select an option).
How can I do it to solve it...to make it enable?Someone has told me that it doesn't work 'cause I need to call a function for each Item of the Menu...but
Thanks
Here the code :
HMENU hMenu = ::CreatePopupMenu();
if (NULL != hMenu)
{
// add a few test items
::AppendMenu(hMenu, MF_ENABLED | MF_STRING , 1, "Change Color");
::AppendMenu(hMenu, MF_ENABLED | MF_STRING , 2, "Hide");
::AppendMenu(hMenu, MF_ENABLED | MF_STRING , 3, "Item 3-");
ClientToScreen(&point);
int sel = ::TrackPopupMenuEx(hMenu,
TPM_CENTERALIGN | TPM_RETURNCMD,
point.x,
point.y,
m_hWnd,
NULL);
CString s;
s.Format("The selected item is %d", sel);
TRACE(s);
::DestroyMenu(hMenu);
|
|
|
|
|
create a menu in your ressources
create a wm_command message handler for your menu items with the class wizard
alternatively, you can handle the wm_contextmenu message:
void CCtrl::OnContextMenu(CWnd* pWnd, CPoint point)
{
CMenu menu;
CMenu* submenu;
menu.LoadMenu(IDR_POPUPMENU);
submenu = menu.GetSubMenu(0);
submenu->TrackPopupMenu(TPM_LEFTALIGN|TPM_RIGHTBUTTON, point.x, point.y, pWnd);
}
that's it
thomas
|
|
|
|
|
I have a problem with multiple tcp (http) connections on Windows. When my program sent many (says, 300 http-connections. The critical number of http-connections depends on speed of Internet connection) http-requests, part of them are stuck. That means, request is sent, but response is either received partly or not received at all. At that, a stuck connection isn’t dropped by web server.
This problem is present only in the Internet. There is no such problem on local machine. Based on experiment, the problem doesn’t depend on either my application sends all 300 requests to single web server or my app sends requests, says, to 6 servers by 50 requests to each server. The result is the same: some of connections are stuck for a long time.
I made a small program to investigate this problem. The program sends http-requests and receives http-response. The program creates the thread for each connection. There is opportunity to set timeout between creating connections. By default, there is no timeout and all connections are created at the same time. When I was playing with this app, I found that if I set the timeout (10-100 millisecond), http-requests worked more effectively. Sometimes, if to choose the right timeout, there are no stuck and the app uses almost all available bandwidth.
Can somebody write what’s the problem? Why are requests are stuck? What’s the cause? I could send the test app with source codes (c++) by request.
Thanks!
--
Vadim
|
|
|
|
|
The HTTP protocol requires that a client has no more than 2 open connections to the same server. Windows enforces this at the API level. There are registry entries you can change to modify this behavior. See this[^] link.
/ravi
My new year's resolution: 2048 x 1536
Home | Articles | Freeware | Music
ravib@ravib.com
|
|
|
|
|
I'm sorry for the late response.
I don't use WinInet API. I use Windows Sockets, no such limitations should be there. Plus all is working perfectly with local web server. There is the problem only through Internet.
|
|
|
|
|
meremortal wrote:
I use Windows Sockets, no such limitations should be there.
Have you confirmed this by modifying the registry settings?
/ravi
My new year's resolution: 2048 x 1536
Home | Articles | Freeware | Music
ravib@ravib.com
|
|
|
|
|
|
No. I'm using Win2k and all requests are sending to valid IP addresses.
|
|
|
|
|
Well it doesn't matter if it is to valid or invalid address. But anyway, you don't use XP
Because as you said, if used locally it works perfectly, I would say that there will be a problem in IP stack - either on your machine or on the peer - if you open hundreds of connections simultaneously, it can have reach some SYN flood protection on the peer side or something like that. I think some tool like TCPView from sysinternals can help revealing what's up.
Anyway what's the ping time between the machines?
|
|
|
|
|
I am trying to build a Java launcher for a Java Product. Executing a Java application with a Batch file looks akward. I want a write code so that a native application written in VC++ can launch the Java application. The batch file of the application looks like this
---------------------------------------------------------------------------------------------------
set path=%PATH%;.\java\j2re1.4.2_07\bin;.\java\j2re1.4.2_07\lib;.\JMF2.1.1e\bin;
set classpath=.\JMF2.1.1e\lib\sound.jar;.\JMF2.1.1e\lib\jmf.jar;
java -classpath Sample.jar;%CLASSPATH%;%JMFHOME% -Djava.library.path=./Samplelib NrthSample.SampleMainApplication
---------------------------------------------------------------------------------------------------
Is there any way to lauch the Java application straight for the native application without the batch file? Can someone tell me which functions to use??
Regards.
|
|
|
|
|
Why don't you just ShellExecute java.exe with all the environment variables specified as command line arguments?
Regards
Senthil
_____________________________
My Blog | My Articles | WinMacro
|
|
|
|
|
iz there any restriction regarding the amount of heap memory that can be used by a program?does windows put a restriction to that?
"faith, hope, love remain, these three.....; but the greatest of these is love" -1 Corinthians 13:13
|
|
|
|
|
I think it is about 4GB and the reason is that we are using 32bit system. Therefore, the amount of memory used by an application must not exceed 4GB.
Cheers...
|
|
|
|
|
Well actually, Windows reserves 2GB for internal use (other DLL's and such). Substract from the 2 GB the amount required by your program (total stack size of all your threads, etc..) and than the remaining memory can be used as the heap.
But if you really need to extend the amount of heap memory, you can easely write yourself a heap manager and a pointer wrapper for a file or whatever that simulates 'real' memory. And there you go, per instance of the class, you have 4GB of extra heap. (Maybe I'll write an article about it one day)
I also got the blogging virus..[^]
|
|
|
|
|
Hi Bob, I will be very interested to read your article on this. Do you mind to let me know if you have published your article on this area? My email address is ryu_thomas@hotmail.com.
Thank you...
|
|
|
|
|
|
|
No, I use some other technique which creates some files that are used as a heap.. This allows me to allocate virtual unlimited memory! Confused? Let me elaborate:
I have a class, which uses a file where you can allocate data in. You don't get an ordinary file pointer, or just an adress, you get a struct, which has a heap id (the object which handles the file) and a block id ( a ID from the index ). This allows me to move all the memory I want without affecting anything I don't want.
How do I access the memory like anything else you ask? Well, I use a heap manager that manages the heap objects (the files) and a cache. When you request a certain data block, the heap manager loads the block into the cache and you get a pointer to it. When you write to the address, it's marked as dirty, and when the cache is cleaned up, it's written back to the file.
I've almost finished the design of the little library and if you watch my blog once in a while, you should notice it when I post the first of three articles. Maybe you find them interesting.
Behind every great black man...
... is the police. - Conspiracy brother
Blog[^]
|
|
|
|
|
No? It is 2 Gigabytes address space for the Kernel and 2 Gigabytes address space for User by default.
I would recomend a much simpler and faster mechanism for a dynamic heap such as using a memory mapped file implementation.
8bc7c0ec02c0e404c0cc0680f7018827ebee
|
|
|
|
|
I should probably elaborate on this a little bit.
Everything in Windows is a memory mapped file. Your executables, your dll's, everything on the system is actually treated as a memory mapped file.
These give you two distinct advantages.
1. The memory manager will manage dirty cache for you, so you will have no effort in attempting to track dirty regions.
2. The memory manager DOES NOT remove a memory mapped file just because you unmapped it! It will actually still attempt to keep it in memory as long as it can. You can actually unmap a file, come back hours later and re map it and it would never have been re-read from disk.
These are neat optimizations and they are provided to you for free by the Operating System so I would definately attempt to take advantage of them.
8bc7c0ec02c0e404c0cc0680f7018827ebee
|
|
|
|
|
Yes, but the addresses of this file are within your address space, so basically you consume your own 2gb of adress space. My technique bypasses this problem by creating it's own 'heap'. The key in the technique is that the memory doesn't get allocated on the native heap (in your 2gb adress space), but somewhere on the disk, which is not limited to the adress space given to your process. Using sophisticated 'heap' pointers, I can move these blocks from the file to the cache, which is in the native heap, and vice versa. I could use memory mapped files as the cache, but this would not be very efficient, cause I would be moving the memory blocks from one file to another. I also could use multiple memory mapped files and map / unmap them on demand, but that would require me to update all the pointers that point to the memory in the mapped file, which is not very feasible...
So basically my techique is a workaround for the 2 GB adress space limitation.
Behind every great black man...
... is the police. - Conspiracy brother
Blog[^]
|
|
|
|
|
Yes, that is the point; you can use memory mapped files to access more than 2 Gigabytes of address space without doing the overhead of a copy.
Your cache is not on disk, you said it yourself it is in the native heap. The point is that you do not want to copy memory around, so you directly access and use the memory mapped file as it is very flexible.
So in the case of memory mapped files you do not need a "cache" since it handles it all by itself.
Mapped files are very flexible in that you can create a single file and then map any portion of the file you want into memory at once, thus creating a view.
So, actually what you are creating is all already done by Memory Mapped Files.
8bc7c0ec02c0e404c0cc0680f7018827ebee
|
|
|
|
|
Take this very simple (and ugly) example, as long as you have the disk space. It will allocate a memory mapped file of 65 Gigabytes. To make this easier to use since pages can only be mapped on boundaries you could have a thin wrapper library around this to help out with that issue, but one large file can be mapped multiple views and take care of caching and writing out dirty regions.
#include <windows.h>
#include <stdio.h>
int _cdecl main(void)
{
HANDLE hFileMapping, hFile;
PVOID pLowMemoryMap, pHighMemoryMap;
hFile = CreateFile(L"C:\\temp.sys", GENERIC_READ | GENERIC_WRITE, 0, NULL, OPEN_EXISTING, 0, NULL);
hFileMapping = CreateFileMapping(hFile, NULL, PAGE_READWRITE, 0xf, 0xffff, NULL);
pHighMemoryMap = MapViewOfFile(hFileMapping, FILE_MAP_WRITE, 0, 0xF000000, 1024*1024);
pLowMemoryMap = MapViewOfFile(hFileMapping, FILE_MAP_WRITE, 0, 0, 1024*1024);
*((DWORD *)pLowMemoryMap) = 0x1234;
*((DWORD *)pHighMemoryMap) = 0x5678;
UnmapViewOfFile(pLowMemoryMap);
UnmapViewOfFile(pHighMemoryMap);
pHighMemoryMap = MapViewOfFile(hFileMapping, FILE_MAP_WRITE, 0, 0xF000000, 1024*1024);
pLowMemoryMap = MapViewOfFile(hFileMapping, FILE_MAP_WRITE, 0, 0, 1024*1024);
printf("0x%0x, 0x%0x\n", *((DWORD *)pLowMemoryMap), *((DWORD *)pHighMemoryMap));
UnmapViewOfFile(pLowMemoryMap);
UnmapViewOfFile(pHighMemoryMap);
CloseHandle(hFileMapping);
CloseHandle(hFile);
return 0;
}
8bc7c0ec02c0e404c0cc0680f7018827ebee
|
|
|
|
|