|
I sometimes use the following method to only run a single instance, I simply use FindWindow to look for the window's title.
Yes, I know if two programs have the same title this logic will fail, but that is 'unlikely'
if((hWnd = FindWindow(NULL, szTitle)) != NULL)<br />
{<br />
ShowWindow(hWnd, SW_RESTORE);<br />
SetForegroundWindow(hWnd);<br />
MessageBeep(MB_ICONEXCLAMATION);<br />
return(0);<br />
}<br />
"An education isn't how much you have committed to memory, or even how much you know. It's being able to differentiate between what you do know and what you don't." - Anatole France
|
|
|
|
|
It will also fail if the app is an MDI or SDI app that has the opened file name in the caption.
"You're obviously a superstar." - Christian Graus about me - 12 Feb '03
"Obviously ??? You're definitely a superstar!!!" - mYkel - 21 Jun '04
"There's not enough blatant self-congratulatory backslapping in the world today..." - HumblePie - 21 Jun '05
Within you lies the power for good - Use it!
|
|
|
|
|
http://www.codeproject.com/cpp/avoidmultinstance.asp[^]
laiju wrote:
Whenever there is an attempt to run multiple instance the current running instance should be restored to full view.
I used the technique described in Dr Newcomer's article to do just that in two of my articles, for an MFC example see here[^] and for a Win32 API example see here[^].
"You're obviously a superstar." - Christian Graus about me - 12 Feb '03
"Obviously ??? You're definitely a superstar!!!" - mYkel - 21 Jun '04
"There's not enough blatant self-congratulatory backslapping in the world today..." - HumblePie - 21 Jun '05
Within you lies the power for good - Use it!
|
|
|
|
|
One way to do it is to create a mutex and an event in the application. The mutex is used to determine whether the application is already running or not. The event is used to signal the process which created it to show itself. All you need to do in the "single instance" process, is to listen to the event and respond to signals sent on it.
See CreateEvent(), SetEvent(), and ResetEvent() in the MSDN docs.
Good music: In my rosary[^]
|
|
|
|
|
laiju wrote:
Whenever there is an attempt to run multiple instance the current running instance should be restored to full view.
See here.
"One must learn from the bite of the fire to leave it alone." - Native American Proverb
|
|
|
|
|
hi,
Obviously u know the caption of your application..[I mean caption on the tittle bar of parent window]
use FindWindow API to search with that window caption...if FindWindow API succeeds u will get the handle for that..
then u send the window resize message with that handle otherwise go as normal...
try this in InitInstance...
With Regards
Prabhu.S
www.PraxUnited.com
|
|
|
|
|
Can anybody mail me the file jpeglib.h
aasstt
|
|
|
|
|
if you mean the one in the IJG's[^] source code, you can get it from the link...
- Indivara
"...This city desert makes you feel so cold.
It's got so many people but it's got no soul..."
- Gerry Rafferty, Baker Street
|
|
|
|
|
Hi all
Am familiar with serial port communication in VC++.
I have written a software for connecting a datalogger device into the serial port and reading the data from the device.
Now I want to make this device and software able to be connected to the USB port, since most the laptops have only USB.
Please help me regarding how I can start sending and recieving data via the USB port in windows.
The Best Relligion is Science.
Once you understand it, you will know God.
|
|
|
|
|
If using a standard USB to serial convertor your code "should" work just fine using the COMx port installed by the driver (usually COM3 or higher), however the USB serial ports so not act quite the same as UART based serial ports, in particular they tend to appear "blockier" (data arrives in distinct blocks rather than in a more continual stream).
I have found that this can interfere with the expected action, particularly the timing of serial messages.
If you want to add the USB port to the actual datalogger hardware I suggest you look at something like the CP2102 (Silicon Laboratories). This is a very small IC that can easily be added to your product and converts from serial to USB (no crystal required which keeps the cost down).
|
|
|
|
|
Extreme caution is preserved when using those port converters. I've used some and all of them mananged to blue screen WindowsXP! I've never seen one of those since Windows 98.
The problem with those USB serial ports is that most of the drives implement CancelIO wrong and that causes a lot of trouble. More information about this can be found in the CSerial[^] article.
Behind every great black man...
... is the police. - Conspiracy brother
Blog[^]
|
|
|
|
|
After derived my view from CPreview, I have now a preview screen but, when i print from it or when i close this screen, the program broken down. what to do ?
I learn my self
|
|
|
|
|
mikobi wrote:
...the program broken down. what to do ?
Describe, in detail, what the problem is. Simply saying that it is broken is not very helpful.
"One must learn from the bite of the fire to leave it alone." - Native American Proverb
|
|
|
|
|
When I clic on the print button on the printpreview screen there is this message : this program will be stopped because it does an operation not permit. If this error continue, let contact your reseller.
I learn my self
|
|
|
|
|
So what does the code look like that runs when the Print button is clicked?
"One must learn from the bite of the fire to leave it alone." - Native American Proverb
|
|
|
|
|
Hi all,
Now I have a list controls; the list is set in Icon mode and I use it to display thumnail image (look like explorer in winxp to show images in thumbnail mode).
When I put scroll (Vertical) position at the min position (zero value); items rectange (GetItemRect(0,&rect, LVIS_BOUNDS)) at the first line always is zero value! How can I change this value? (mean I can make a distance between item and the ceil of list control rect);
Similarily with items at the last line when I put scroll position at the maximum value: bottom value of these items always dash the floor of list controls rect! Can I change this distance?
In otherwise, if list control is a box; I see items always are fixed in the box; How can I enlarger this box???
Please tell me some ideas!
Thanks!
|
|
|
|
|
I dont think you can change the layout algorithm of the list control.
-Atul, Sky Software http://www.ssware.com
Shell MegaPack For ActiveX & .Net - Windows Explorer Like Shell UI Controls
|
|
|
|
|
yes i wana make a vector for a object
eg. **************PROPERTY.h FILE***********
#ifndef Property_h
#define Property_h
#include <string>
#include <vector>
using std::string;
using std::vector;
class Property
{
public:
Property();
Property (string a_address, string a_suburb, int a_price);
void print() const;
void getProperty();
//int readFile(vector<property>, myCard);
void listAll(vector<property> propvect); <<<<<< thing to look at error possibly here
int menu();
private:
string address_string;
string suburb_string;
int price_int;
};
#endif
**********PROPERTY.CPP FILE************
#include <iostream>
#include <string>
#include "Property.h"
#include <vector>
#include <fstream>
using namespace std;
Property::Property()
{
}
Property::Property(string a_address, string a_suburb, int a_price)
{
address_string = a_address;
suburb_string = a_suburb;
price_int = a_price;
}
void Property::print() const
{
cout << address_string << " " << suburb_string << " " << price_int << endl;
system("Pause");
}
void Property::getProperty()
{
cout << "Enter address: ";
getline(cin, address_string);
cout << "Enter suburb: ";
getline(cin, suburb_string);
cout << "Enter price: ";
cin >> price_int;
}
int Property::menu()
{
int option = 0;
cout << endl;
cout << "Menu:" << endl;
cout << "1 - List all properties" << endl;
cout << "2 - Property search" << endl;
cout << "3 - Add a property" << endl;
cout << "4 - Save property list" << endl;
cout << "5 - Exit" << endl << endl;
cout << "Please enter option: ";
cin >> option;
string remainder;
getline(cin, remainder);
cout << endl;
return option;
}
void Property::listAll(vector<property> propvect) <<<<<<< FUCTION THAT HAS THE ERROR
{
for (int i = 0; i < propvect.size(); i++)
{
cout << "$" << propvect[i].address_string << " ";
cout << propvect[i].suburb_string << " ";
cout << propvect[i].price_int << endl;
}
}
***********PROPERTY_TEST.CPP ********** TEST HARNESS FOR PROPERTY PROGRAM
#include <iostream>
#include <string>
#include <vector>
#include "Property.h"
using namespace std;
int main()
{
int option = 0;
bool done = false;
vector<property> propvect;
Property Properties;
// readFile(vector<property>, myCard);
do
{
option = Properties.menu();
switch (option)
{
case 1: Properties.listAll(vector<property> propvect);
/*Properties.print();*/break;
case 2: //search(properties, items); break;
case 3: Properties.getProperty();
propvect.push_back(Properties); break;
case 4: //saveProperties(properties, items); break;
case 5: done = true; break;
default: cout << "Illegal menu option" << endl;
}
} while(!done);
return 0;
}
____________________________________________________________________________________________
now when i run it without the ListALL fuction it works but when i run it with the ListALL fuction i get syntax errors can anyone see what im doing wrong.
|
|
|
|
|
you'll need to edit your post to make sure all the <'s and >'s show up. as it is now, we can't tell how you've declared the vectors.
Cleek | Image Toolkits | Thumbnail maker
-- modified at 10:04 Saturday 10th September, 2005
|
|
|
|
|
|
I have created a SDI application (with no Document/View) support. I 'm trying to attach a CBitmap button, but dose not displayed at all.
Here is my code (that handles the WM_CREATE message on the CChildView class):
<br />
int CChildView::OnCreate(LPCREATESTRUCT lpCreateStruct)<br />
{<br />
if (CWnd::OnCreate(lpCreateStruct) == -1)<br />
return -1;<br />
<br />
RECT rect;<br />
rect.left = 20;<br />
rect.right = rect.left + 20;<br />
rect.top = 100;<br />
rect.bottom = rect.top + 20;<br />
<br />
CBitmapButton bnPlay;<br />
if(bnPlay.Create(NULL, WS_CHILD|WS_VISIBLE|BS_OWNERDRAW, <br />
CRect(&rect), this, IDC_BN_PLAY)==0)<br />
{<br />
AfxMessageBox("BnPlay cannot be created", MB_ICONSTOP);<br />
return -1;<br />
}<br />
<br />
bnPlay.LoadBitmaps(IDB_BNPLAY);<br />
bnPlay.SizeToContent();<br />
return 0;<br />
}<br />
The result of this code is an empty window...
|
|
|
|
|
|
I have created a CBitmapButton in the main window of an SDI application, but I can't figure out how to implement the button. I would like to use it to open a dialog. Here is the code I used to create the button. Thanks for any help you can give.
RECT rc;
rc.top=10;
rc.left=10;
rc.right=95;
rc.bottom=95;
CBitmapButton *Winbut = new CBitmapButton;
Winbut->Create(NULL,WS_CHILD|WS_VISIBLE|BS_OWNERDRAW,rc,this,IDB_SITBUT);
Winbut->LoadBitmaps("SITEIMAGEU","SITEIMAGED","SITEIMAGEU","SITEIMAGEX");
Winbut->SizeToContent();
|
|
|
|
|
The last parameter of the create function is the ID of the control you are creating. It is an integer.
Let it be 200.
Then declare a function in the header for the class.
afx_msg void OnButtonWhatever();
In the message map in the .cpp file:
...<br />
...<br />
ON_COMMAND(200,OnButtonWhatever)<br />
END_MESSAGE_MAP()
Then implement the function:
void [Your Class Name Here]::OnButtonWhatever()<br />
{<br />
MessageBox("The button was clicked. He He!");<br />
}
this is this.
|
|
|
|
|
Thanks for the help. Worked like a champ.
|
|
|
|