Posts

Showing posts from 2014

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!

How to call Java code from C/C++

Image
I wanted to call Java functions from C++ and searching in the internet I found some codes but seems lacking more details. What I will do here is to make it complete. CALLING JAVA IN C++ USING MS VISUAL STUDIO 2008 Requirements: -JDK ( I used jdk1.7.0_55 32bit)  -Visual Studio 2008 Procedure: 1. Add the library "jvm.lib". Remember this library exist when you install the JDK 2. Add the 2 path of the include files of the JDK 3. Add the library path 4. Create the Java source and compile them (javac * to compile everything in the folder). The source location in my MS Windows environment is D:\MyFiles\Downloads\Java Src\TestStruct //HelloWorld.java public class HelloWorld {       public static void main(String args[])       {          System.out.println("Hello World!");          System.out.println("This is the main function in HelloWorld class");       }       public s

How to implement mouse drag using wxWidgets

I have an application without borders so I cannot move the application. This application has a wxPanel so the only way I can click and drag is thru the wxPanel. How to implement mouse drag? class myFrame : public wxFrame { public: myFrame(const wxString& title, wxWindow *parent=NULL); wxWindow* parent; private: wxDECLARE_EVENT_TABLE(); } class myPanel : public wxPanel { public: myPanel (wxWindow* parent)     { this->parent = parent; dragging=false; x=0,y=0;               Create(parent, wxID_ANY,wxDefaultPosition, *new wxSize(100,100));     } void onMouseDown(wxMouseEvent& evt) { CaptureMouse(); x = evt.GetX(); y = evt.GetY(); dragging=true; } void onMouseUp(wxMouseEvent& evt) { ReleaseMouse(); dragging=false; } void onMove(wxMouseEvent& evt) { if(dragging) { wxPoint mouseOnScreen = wxGetMousePosition(); int newx = mouseOnScreen.x - x;

How to put an image to wxPanel using wxWidgets

Image
1. I created the class xOsdHeaderPanel 2. Must call the function wxInitAllImageHandlers(); 3. Create a wxBitmap object and call SetBackgroundBitmap(..) class xOsdHeaderPanel : public wxCustomBackgroundWindow<wxPanel> { public: xOsdHeaderPanel(wxWindow* parent)     { wxInitAllImageHandlers(); const wxSize xxsize(733,80);         Create(parent, wxID_ANY,wxDefaultPosition,xxsize); wxBitmap bitmap(*new wxImage(wxT("./Header.png"),wxBITMAP_TYPE_PNG)); SetBackgroundBitmap(bitmap); new wxButton(this,wxID_ANY,wxT("Sample Button"));     } }; Result:

How to build Boost in Windows and Linux

============ WIN7 ============ Prerequisites -------------- -  Visual Studio 2008 Professional with SP3 Build Steps -------------- 1. Unzipped boost_1_55_0.zip 2. Execute \boost_1_55_0\bootstrap.bat 3. Use the following command to generate files of release    bjam toolset=msvc-9.0 variant=release threading=multi link=shared define=_BIND_TO_CURRENT_VCLIBS_VERSION 4. The binaries can be found in \boost_1_55_0\bin.v2 ============= SLEPOS11SP3 ============= Prerequisites -------------- - GCC 4.3.4 - Linux 3.0.93 Build Steps ------------- 1. Unzipped boost_1_55_0.zip 2. Execute ./bootstrap.sh --with-libraries=all --with-icu --prefix=/usr/local/boost 3. Execute ./b2 variant=release toolset=gcc link=shared threading=multi runtime-link=shared install 4. The files can be found in \usr\local\boost That's it!

How to build Xerces-c in Windows and Linux

================= MS Windows (Win7) ================= Prerequisite: - Visual Studio 2008 SP3 - xerces-c-3.1.1.zip Build Steps: 1. Unzipped xerces-c-3.1.1.zip 2. Open the solution in VS 2008 \xerces\xerces-c-3.1.1\projects\Win32\VC9\xerces-all\xerces-all.sln 3. Build the projects in "Release" mode 4. The binaries can be found in \xerces\xerces-c-3.1.1\Build\Win32\VC9\Release =========== Linux (Suse) =========== prerequisites -------------- - GCC 4.3.4 - Linux 3.0.93 xerces -------- 1. Unzipped xerces-c-3.1.1.zip in \usr\local 2. Create another folder (any folder name but in this example it's "xerces") 3. Choose current directory "xerces" and call "../xerces-c3.1.1/configure 4. Choose current directory "xerces" and call "make build" 5. Choose current directory "xerces" and call "make install" 6. The libraries can be found in \usr\local\lib 7. The b