Posts

MFC: How to limit application instance or not allow multiple instance of the same application

1. Create the class #ifndef LimitSingleInstance_H #define LimitSingleInstance_H #include&LTwindows.h&GT //This code is from Q243953 in case you lose the article and wonder //where this code came from. class CLimitSingleInstance { protected:   DWORD  m_dwLastError;   HANDLE m_hMutex; public:   CLimitSingleInstance(TCHAR *strMutexName)   {     //Make sure that you use a name that is unique for this application otherwise     //two apps may think they are the same if they are using same name for     //3rd parm to CreateMutex     m_hMutex = CreateMutex(NULL, FALSE, strMutexName); //do early     m_dwLastError = GetLastError(); //save for use later...   }     ~CLimitSingleInstance()   {     if (m_hMutex)  //Do not forget to close handles.     {        CloseHandle(m_hMutex); //Do as late as possible.        m_hMutex = NULL; //Good habit to be in.     }   }   BOOL IsAnotherInstanceRunning()   {     return (ERROR_ALREADY_EXISTS == m_dwLastError);   }

How To Code Inheritance and Polymorphism in C

C++ Code -------------- #include &ltiostream&gt #include &ltcstdlib&gt using namespace std; class base { public:     base();     virtual ~base();     virtual void draw();     void initialize(); private:     int value; }; base::base() {     cout << "base\n"; } base::~base(){     cout << "~base\n"; } void base::draw(){     cout << "base draw\n"; } void base::initialize() {     cout << "initialize\n"; } class child : public base { public:     child();     ~child();     virtual void draw(); private:     int number; }; child::child(){     cout << "child\n"; } child::~child() {     cout << "~child\n"; } void child::draw() {     cout << " child draw\n"; } int main(int argc, char** argv) {     cout << "non dynamic\n";     child c;     c.initialize();     c.draw();     base* b = &c;     b->

How To Setup NetBeans in C/C++

If you have Visual Studio from Microsoft well great but if you're not fortunate to have the commercial tool you have NetBeans which can run in both MS Windows and Linux. So, to setup NetBeans you need the following, - Download and install NetBeans with C/C++ support - Download and install MingW - Download and install MSys inside the base directory of MingW - Point the environment variables "path" to where the /bin of MingW and MSys - Run NetBeans and go to \Tools\Options\C++ and add in the tool chain the base directory of MingW - For the C compiler point the path to C:\Program Files (x86)\mingw-w64\i686-5.1.0-posix-dwarf-rt_v4-rev0\mingw32\bin\i686-w64-mingw32-gcc.exe - For the C++ compiler point the path to C:\Program Files (x86)\mingw-w64\i686-5.1.0-posix-dwarf-rt_v4-rev0\mingw32\bin\i686-w64-mingw32-c++.exe - For the debugger point the path to C:\Program Files (x86)\mingw-w64\i686-5.1.0-posix-dwarf-rt_v4-rev0\mingw32\bin\gdb.exe - For the make point the path

How to setup Visual Studio 2008 to publish ASP.NET website to IIS 7.0 in Windows Server 2008

Image
1. Download and install FrontPage Extension for IIS 7.0  into Windows Server 2008 2. Download and install the .NET 3.5 into the Windows Server 2008 3. Go to Windows Server 2008 "Control Panel","Administrative Tools","Microsoft SharePoint Administrator" and select "Extend"

C++: Type Conversions

typedef std::wstring XSTRING; void Convert(LPCTSTR input, XSTRING &output) { output = input; } void Convert(int input, XSTRING &output) { output = L""; std::wostringstream ws; ws << input; output = XSTRING(ws.str()); } void Convert(unsigned int input, XSTRING &output) { output = L""; std::wostringstream ws; ws << input; output = XSTRING(ws.str()); } void Convert(unsigned long input, XSTRING &output) { output = L""; std::wostringstream ws; ws << input; output = XSTRING(ws.str()); } void Convert(std::string input, XSTRING &output) { output = L""; output = XSTRING(input.begin(), input.end()); } void Convert(XSTRING input, std::string &output) { output = ""; output = std::string(input.begin(), input.end()); } void Convert(char* input, XSTRING &output) { output = L""; output = XSTRING(input, input + strlen(input));

Visual Studio 2008 MFC: How to embed a dialog to a dialog

Image
I wanted to create a dialog based application that a user can select an item from the left and displays different dialog to the right. I drag and drop a picture control into the left side that will serve as container of the child dialog. Then, I created also a child dialog with button in the resource as, Right-click the child dialog and select properties. The following properties should be as, Border = None Style = Child System Menu = False Title Bar = False Visible = True I selected the child dialog and right-click to create a class as, After creating the class, add the code below in the constructor and first argument is your class name. Create(YourClassName::IDD,pParent); Then, to dynamically add the child dialog to the picture control in our main dialog you can do it as, m_pYourClassName = new YourClassName(this); CRect rc; GetDlgItem(IDC_STATIC_DEVICE)->GetWindowRect(rc); ScreenToClient(&rc); m_pYourClassName->MoveWi

Linux mount error when previously okay

Image
I've encountered an error when mounting in my Linux box. Previously it was okay but somehow now it didn't. To fix all I did is restart the service where the "//XXX.XXX.XXX.XXX/Share"  is located as below, That's it!