|
I don't know if that is what he wants, but I want to display a bitmap on a button with custom text.
We need to be able to read the button text from an INI file, and display it on a button with an icon.
|
|
|
|
|
See if this or this helps.
"Normal is getting dressed in clothes that you buy for work and driving through traffic in a car that you are still paying for, in order to get to the job you need to pay for the clothes and the car and the house you leave vacant all day so you can afford to live in it." - Ellen Goodman
"To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne
|
|
|
|
|
1) Based on your response, am I correct in assuming CBitmapButton does not have this capability?
2) IS it possible to use a transparent image, and set the text behind the image?
modified on Monday, February 04, 2008 3:19:01 PM
|
|
|
|
|
littleGreenDude wrote: 1) Based on your response, am I correct in assuming CBitmapButton does not have this capability?
Read the first few paragraph's of Dr. Newcomer's article.
"Normal is getting dressed in clothes that you buy for work and driving through traffic in a car that you are still paying for, in order to get to the job you need to pay for the clothes and the car and the house you leave vacant all day so you can afford to live in it." - Ellen Goodman
"To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne
|
|
|
|
|
Hi Friends,
I have a MHTML file, i have to Split it in to Number of files,
First from the Header of the file as header.
Then we have a String in as "PAGE-BREAK-AFTER". I have to read this file and find this string, till that string i have to make a new file1, like that there are lot of "PAGE-BREAK-AFTER" String, Could any one tell me.
How to do this, some logic.
Thanks and Regards.
SANTHOSH V
|
|
|
|
|
That can be easily done:
(0) if you have reached endo of file exit
(1) Read a line and append it to your buffer
(2) Search the line for the "PAGE-BREAK-AFTER" separator
(3) if the separator is not found go to point (0)
(4) write buffer content to new file
(5) erase buffer
(6) go to point (0)
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.
|
|
|
|
|
Dear all,
i am writing some simple program that contains few classes and a main..
once i am compiling that application i am getting following error
"Error 8 error C3381: 'sub' : assembly access specifiers are only available in code compiled with a /clr option c:\documents and settings\my documents\visual studio 2005\projects\trtrtr\trtrtr\astreo.cpp 16
"
what wrong is going on here..
please help me..
T@SU
|
|
|
|
|
tasumisra wrote: 'sub'
Post the releted code.
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.
|
|
|
|
|
Did you try to specify assembly access on a class,
something like
public class MyClass
{
...
You can only use the "public" access modifier in CLR code.
The above code should be
class MyClass
{
...
Mark
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
Actually you may not include clr inside your coding while building your project.Thats why you just try to go with project having clr option enabled while making new project.
|
|
|
|
|
Hi All,
I have little much confusion about CreateMutex() and CloseHandle(). I am using these functions to allow not to create multiple instances of the my application.
For that I have written below code...
Here juct consider that InstanceHandler is one Class and m_mutex is of the HANDLE type.
<br />
InstanceHandler::InstanceHandler():m_mutex(NULL)<br />
{<br />
}<br />
<br />
InstanceHandler::~InstanceHandler()<br />
{<br />
Release();<br />
}<br />
<br />
BOOL RTMPInstanceHandler::Init()<br />
{<br />
m_mutex = CreateMutex(NULL,FALSE,LPCWSTR(mutexname));<br />
if(m_mutex == NULL)<br />
{<br />
return FALSE;<br />
}<br />
<br />
if (GetLastError() == ERROR_ALREADY_EXISTS)<br />
{<br />
return FALSE;<br />
}<br />
return TRUE;<br />
}<br />
<br />
DWORD RTMPInstanceHandler::Release()<br />
{<br />
try <br />
{ <br />
CloseHandle(m_mutex);<br />
}<br />
catch (...)<br />
{<br />
}<br />
<br />
return GetLastError();<br />
}<br />
Here When I call these function like below....
<br />
<br />
RTMPInstanceHandler instancehan;<br />
if(!instancehan.Init())<br />
{<br />
MessageBox(NULL, CString("Another instance of Application is already running!!"), CString("Server Message"), MB_OK);<br />
instancehan.Release();<br />
}<br />
And here is my problem,, what happens everything runs complete but when I call Release() function then it executes but does not reomve from the Process list.
And Every time I run application then it shows the message indicating that another Instance is running but CloseHandle() function does not remove process.
If you have any idea then reply me.
Thanks in advance.
|
|
|
|
|
ashishbhatt wrote:
RTMPInstanceHandler instancehan;
if(!instancehan.Init())
{
// We don't allow multiple instances!
MessageBox(NULL, CString("Another instance of Application is already running!!"), CString("Server Message"), MB_OK);
instancehan.Release();
}
Where you have written the above code snippet? CloseHandle call in the release function will decrement handle count/Close the mutex you have created.
After detecting another instance your main thread should return. Probably you should do in WinMain() or InitInstace() of your Application class.
You should use your InstanceHandler class properly. i.e When first instance of the program creates, the MutexShould be created and valid throughout the life of the program.
Search in CP. it contains article on this issue.
-Sarath.
"Great hopes make everything great possible" - Benjamin Franklin
|
|
|
|
|
Thanks for reply.
I have already called this class from the winmain() function. And I hope it executes properly.
From testing my code I have come to the conclusion that the problem is with CloseHandle().because when I run another instance of my appliction then it creates new Mutex again (means that in Task Manager -> Process Tab ,it shows two instances of my application), but it also generates the error ERROR_ALREADY_EXISTS and then it goes to call the CloseHandle() function and it also executes but it does not close handle(means it does not delete instance from the Task Manager).
Is there ny other idea??
Thanks.
|
|
|
|
|
Hai Sarath,
I have a doubt. If i fulfill the same requirement by using CSemaphore as follows...
...
CSemaphore csLock(1,1,"MYSTRING",NULL);
...
BOOL CMyApplication::InitInstance()
{
...
if(csLock.Lock(100))
{
AfxMessageBox("One Instance is already running");
return false;
}
...
}
...
int CMyApplication::ExitInstance()
{
csLock.Unlock();
...
}
Is there anything wrong doing like this?
I would be thankful if you give me suggessions on using this.
Thank you
Saadhinchaali
|
|
|
|
|
Hello,
It's a good idea to make use of available class. There's nothing wrong with the method you have specified. It should work. The idea is only to make use of any named kernel object. CSemaphore is a wrapper which is doing the same operation of CreateSemaphore , WaitForSingleObject and ReleaseSemaphore functions (atleast for the operations you specified).
For the single instance purpose, we only need a mutex. Mutex is really like a binary semaphore (either free/owned state). It's a bad idea to use semaphore as we have mutex (you can also use CMutex instead of win32 APIs ) which is already available. Also you don't have to wait for 100 ms. you can pass 0 to the Lock function which will tests the object's state and returns immediately.
Another thing is advisable to make csLock as the member of App class. Nothing special but just being Object Oriented.
I don't know why Ashish's class is not working as it should work if properly used.
In An MFC App, it can be used as follows
BOOL MyApp::InitInstance()<br />
{<br />
<br />
if( !m_Instance.Init())
return 0;<br />
....<br />
}
-Sarath.
"Great hopes make everything great possible" - Benjamin Franklin
|
|
|
|
|
Thank sarath, for your kind reply.
So the CSemaphore should be used whene we want to allow a certain number of processes or threads to allow to access? is't it?
Saadhinchaali
|
|
|
|
|
The following seems to be the problem with the code LPCWSTR(mutexname).
ashishbhatt wrote: m_mutex = CreateMutex(NULL,FALSE,LPCWSTR(mutexname));
What's the type of mutexname. It's like type casting ASCII string into widestring which may cause unexpected behavior.
Seems this will do. Just try it
LPCTSTR mutexname = _T("MyMutex");
m_mutex = CreateMutex(NULL,FALSE,mutexname);
The following code worked fine for me.
<br />
class RTMPInstanceHandler<br />
{<br />
HANDLE m_mutex;<br />
public:<br />
RTMPInstanceHandler():m_mutex(NULL)<br />
{<br />
}<br />
<br />
~RTMPInstanceHandler()<br />
{<br />
Release();<br />
}<br />
<br />
BOOL Init()<br />
{<br />
m_mutex = CreateMutex(NULL,FALSE,_T("mutexname"));<br />
if(m_mutex == NULL)<br />
{<br />
return FALSE;<br />
}<br />
<br />
if (GetLastError() == ERROR_ALREADY_EXISTS)<br />
{<br />
return FALSE;<br />
}<br />
return TRUE;<br />
}<br />
<br />
DWORD Release()<br />
{<br />
try<br />
{<br />
CloseHandle(m_mutex);<br />
}<br />
catch (...)<br />
{<br />
}<br />
<br />
return GetLastError();<br />
}<br />
};<br />
<br />
int _tmain(int argc, TCHAR* argv[], TCHAR* envp[])<br />
{<br />
int nRetCode = 0;<br />
<br />
<br />
RTMPInstanceHandler inst;<br />
if ( !inst.Init())<br />
{<br />
cout<<"instance already exists";<br />
return nRetCode;<br />
}<br />
<br />
cin >> nRetCode;<br />
return nRetCode;<br />
}<br />
-Sarath.
"Great hopes make everything great possible" - Benjamin Franklin
|
|
|
|
|
Thank you very much for taking that too much interest in my problem.
I used your suggetion as you told to do but the same problem exists.
Thanks.
|
|
|
|
|
"And Every time I run application then it shows the message indicating that another Instance is running but CloseHandle() function does not remove process."
I think this is the source of the problem. The CloseHandle API doesn't control the running process. It is used to tell the running process that a previous instance exists and that it should not run. It is not clear from the code snippet that application is terminated when the first instance of the application is detected.
For a MFC CWinApp this text would occur in the InitInstance member function,
BOOL CMyApp::InitInstance()
{
m_hMutex = ::CreateMutex(0, FALSE, "TestApp");
if (::GetLastError() == ERROR_ALREADY_EXISTS) {
TRACE("TestApp: Already running");
::CloseHandle(m_hMutex);
return FALSE;
}
}
A return value of FALSE from CMyApp::InitInstance will terminate the second instance of the program. The important point is that the Mutex is a resource used by the process, not the process itself. When you detect the ERROR_ALREADY_EXISTS condition you must terminate the application yourself. You must close the handle because CreateMutex returned a valid handle.
|
|
|
|
|
Thanks to you.
Sorry For the very late Reply on this htread becaz I do not want to create new thread for the same problem.
As you told in your post to test the code you show ,, I tested it and works fine.But i want to know some more things,, As you told that I have to terminate my application myself but how can I do that???
My problem is that when I run another instance of application then from my code it shows the message that another instance is running and I also close the Mutex Handle,But it creates new entry into the Process list(in TaskManager->Process tab).So how can I remove this entry when one is already running??
Ashish Bhatt,
System Developer,
Avinashi System Pvt. Ltd.
|
|
|
|
|
It is not clear to me which instance of the process you are trying to terminate. I have been assuming you want to terminate the second instance. I'll address that.
First what are the results we are looking for? The test program I use is the MFC program generated by MSVC App Wizard. The produces a program that will run two instances. When you do the Windows task manager will show both instances in the process list. To make the test results easy to see, sort the Task Manager process list by name in order to see the two processes listed together. If you then terminate one instance it will be removed from the process list after it has terminated. This is the result we are seeking. What we want is a way for the second instance of the program to detect the first instance of the program. When the first instance is detected the second program instance should terminate itself, just as if we had done it from the application. As before, the task manager process list will reflect that the second instance of the program terminated and remove it from the process list, leaving just the first instance running.
The way we detect the second instance of the program is to use a mutex object. Each instance of the program tries to create the mutex. This is doen when the application starts during InitInstance().
BOOL CMfctestApp::InitInstance()
{
m_hMutex = ::CreateMutex(0, FALSE, "TestApp");
if (::GetLastError() == ERROR_ALREADY_EXISTS)
{
TRACE("TestApp: Already running");
::CloseHandle(m_hMutex), m_hMutex = 0;
return FALSE;
}
}
Note the use comma sequence operator and the explicit assignment of the mutex handle. A second instance of the application will get a valid handle to the existing mutex. Once we have closed the handle we do not want to use it again. We declare the m_hMutex handle as a private member variable in the application class,
class CMfctestApp : public CWinApp
{
private:
HANDLE m_hMutex;
};
Finally, we insure that the first instance of the application will properly release the mutex when the application terminates. This is done in ExitInstance()
int CMfctestApp::ExitInstance()
{
if (m_hMutex)
::CloseHandle(m_hMutex);
return CWinApp::ExitInstance();
}
The first instance of the program will have a valid, non null mutex handle and will close it. All other instances will have handle of 0.
If now run the program outside of the debugger and look at the Task Manager process list and you will see the first instance running. In the MSVC IDE place a breakpoint in the InitInstance member function and run the program under the debugger. When the breakpoint is hit look at the process list in the Task Manager and you will see both instances running. Let the second instance of the program, in the debugger, continue and you should see the process get removed from the task list.
|
|
|
|
|
Hi, i follow your way to create the program, so far is okay.
but i try to add the code below in
ExitInstance()
{
if(m_hMutex)
{
::CloseHandle(m_hMutex);
ReleaseMutex(m_hMutex);
}
if(m_hMutex)
{
::CloseHandle(m_hMutex);
ReleaseMutex(m_hMutex);
}
return CWinApp::ExitInstance();
|
|
|
|
|
The CreateMutex does not work on Win 7 32 bit. Even if the application already exists it returns a success..
Any thought?
Thanks..
|
|
|
|
|
Hi Experts,
Hi have 2 view(both ListView) in my application. One conataind the full path of files. I want to drag drop a file in other ListView from first ListView.
How can I do this ?
Thanx in advance.
|
|
|
|
|
Did you search on the codeproject?
|
|
|
|