Nov
07
2008
0

Code::Blocks won’t edit wxSmith file, sloved

While I’m using Code::Blocks, it crashed suddenly and when I reopen the project, one of the newest panel created by wxSmith won’t open in Resources mode, instead, it opened as text file. Thus I can’t change the GUI in wxSmith. Here’s steps to fix the issue.

1. Add the .h, .cpp and .wxs into the project if it’s not there

2. Close project

3. Open cbp file in a text editor, btw I like PSPad and Notepad++ the most on Windows and Geany on Linux

4. Find the section in the cbp file:

<wxsmith version=”1″>
                <gui name=”wxWidgets” src=”wxTailApp.cpp” main=”wxTailFrame” init_handlers=”necessary” language=”CPP” />
                <resources>
                    <wxFrame wxs=”wxsmith/wxTailframe.wxs” src=”wxTailMain.cpp” hdr=”wxTailMain.h” name=”wxTailFrame” language=”CPP” />
                </resources>
</wxsmith>

5 Add this line into resources:

<wxPanel wxs=”wxsmith/NewPanel.wxs” src=”NewPanel.cpp” hdr=”NewPanel.h” name=”NewPanel” language=”CPP” />

rename the NewPanel.wxs, NewPanel.cpp, NewPanel.h, NewPanel accordingly.

6. Save the file, reopen the project, it’s solved!

Written by hkai in: wxWidgets | Tags: , ,
Nov
07
2008
0

Debugging and Logging in wxWidgets with wxLogWindow

wxLogWindow make it much easier to debugging and logging.

in the constructor add the following code:

#if defined(__WXDEBUG__ )
    //logging and debugging
    wxLogWindow *w= new wxLogWindow(this, wxT(”Logger”));
    w->Show();
#endif

Then, in anywhere, add the following:

wxLogDebug(wxT(”Debug message”));

If you are running in Debug build target, it’ll show a small console and displaying all the messages. If you are running in release mode, that console won’t appear and thus no log messages there.

Written by hkai in: wxWidgets | Tags:
Nov
07
2008
0

Setup wxWidgets and Code::Blocks on Windows Vista

Since I’m going to extend my knowledge of programming, I selected wxWidgets as the next target. It has some advantages when comparing with other frameworks:

  1. cross platform: vs Win32, Cocoa, Gnome, KDE
  2. can develop commercial applications: vs Qt
  3. has more features: vs FLTK
  4. active community

So here’s how to setup wxWidgets on Windows Vista. I assume you already setup MinGW and Code::Blocks.

  1. download and install wxWidgets: wxMSW-2.8.9-Setup.exe, I installed it to c:\apps\wxWidgets-2.8.9
  2. endter the directory wxWidgets-2.8.9\build\msw, run the command:
    make -f makefile.gcc BUILD=release SHARED=1 MONOLITHIC=1 UNICODE=1
    make -f makefile.gcc BUILD=debugSHARED=1 MONOLITHIC=1 UNICODE=1
  3. after finished, copy wxWidgets-2.8.9\lib\gcc_dll\wxmsw28u_gcc_custom.dll and wxmsw28ud_gcc_custom.dll to c:\windows\system32
  4. start code::blocks, create a wxWidgets project, when asking wxWidgets Library Settings, check the Use wxWidgets DLL, wxWidgts is built as a monolithic library and Enable unicode
  5. build and run the project, you should have your 1st wxWidgets applications with wxSmith GUI editor.

Here’s some wxSmith tutorial

Written by hkai in: C/C++ | Tags: , ,
Nov
07
2008
0

Setup C++ Development using MinGW, Code::Blocks on Windows Vista

Download and install MinGW:

1. download MinGW-5.1.4.exe, create c:\MinGW, and run it. It’ll download and install the current stable version of GCC, G++ etc.

2. set the environment, add c:\MinGW\bin;C:\MinGW\libexec\gcc\mingw32\3.4.5 to PATH

2.1 download gdb and extract to c:\MinGW

2.2 start a console, make sure you can run gcc -v and gdb -v

3. download code::blocks 8.02, install and start it

3.1 in code::blocks, settings->Global compiler settings, selected compiler=GNU GCC Compiler, then add the following into Search directories

Compiler tab

C:\MinGW\include
C:\MinGW\include\c++\3.4.5
C:\MinGW\include\c++\3.4.5\backward
C:\MinGW\include\c++\3.4.5\mingw32
C:\MinGW\lib\gcc\mingw32\3.4.5\include

Linker tab

C:\MinGW\lib
C:\MinGW\lib\gcc\mingw32\3.4.5

Resource compiler tab

C:\MinGW\include

Note if your GCC is not 3.4.5, please change to the correct version.

Now the most important part: START THE PROJECT in C: , don’t in D:, if you start the project in other disk, you’ll get the following error when you compile a standard C project:

ld: crt2.o: No such file: No such file or directory

I don’t know the reason, but if you copy crt2.o, crtbegin.o and crtend.o to the project directory, it’ll be able to show you another issue:

undefined reference to `WinMain@16′

If the project located at c:\somedir, the those issues will disappear. What a strange thing!

Written by hkai in: C/C++ | Tags: , , ,
Oct
08
2007
0

C Quiz 1

What’s the output of the following program?

#include <stdio.h>

#define MIN(A,B) ( ((A)<=(B))?(A):(B) )

void main()
{
    int i=1;
    int *p=&i;
    int result=MIN( (*p)++, i);
    printf(”%d,%d”, x,*p);
   
}

Written by hkai in: C/C++ |
Sep
27
2007
0

C programming by example: 3

一个整数,它加上100后是一个完全平方数,再加上168又是一个完全平方数,请问该数是多少?
(如果一个数的平方根的平方等于该数,这说明此数是完全平方数)
If compile in linux, please remember add -lm in the parameter

#include <stdio.h>
#include <math.h>

int main(int argc, char** argv)
{
    int i,x,y;
    for( i=0;i<1000000;i++)
    {
        x=sqrt(i+100);
        y=sqrt(i+268);
        if( x*x== (i+100) && y*y == (i+268))
            printf(”%d\n”, i);
    }
    return 0;
}

Written by hkai in: C/C++ |
Sep
27
2007
0

C programming by example: 2

企业发放的奖金根据利润提成。利润(I)低于或等于10万元时,奖金可提10%;利润高
于10万元,低于20万元时,低于10万元的部分按10%提成,高于10万元的部分,可可提
成7.5%;20万到40万之间时,高于20万元的部分,可提成5%;40万到60万之间时高于
40万元的部分,可提成3%;60万到100万之间时,高于60万元的部分,可提成1.5%,高于
100万元时,超过100万元的部分按1%提成,从键盘输入当月利润I,求应发放奖金总数?

#include <stdio.h>

int main(int argc, char** argv)
{
    long int iRevenue=0;
    float fBonus=0;
    int iaLevel[]={100000,200000,400000,600000,1000000};
    int iLevel;
    float faRate[]={0.1, 0.075,0.05,0.03,0.015,0.01};
    float fRate;
    int i;
    printf(”Please input revenue:”);
    scanf(”%ld”, &iRevenue);
    printf(”The revenue is $%ld\n”, iRevenue);
    for(i=0;i<5 && iRevenue>0;i++)
    {
        iLevel=iaLevel[i];
        fRate=faRate[i];
        if( iRevenue <=iLevel)
            fBonus+= iRevenue * fRate;
        else
            fBonus+= iLevel * fRate;
        iRevenue -= iLevel;
       
    }
    if( iRevenue >0)
        fBonus+= iRevenue * faRate[5];
       
    printf(”The bonus is $%.02f\n”,  fBonus);
   
       
   
    return 0;
}

Written by hkai in: C/C++ |
Sep
27
2007
0

C programming by example: 1

有4个数字,能组成多少个互不相同且无重复数字的三位数?都是多少?

#include

int main(int argc, char** argv)
{
int aNum[]={3,8,7,5};
int i,j,k;
int count=0;
int iNum1, iNum2, iNum3;
for( i=0;i<4;i++)
{
iNum1=aNum[i];
for(j=0;j<4;j++)
{
iNum2=aNum[j];
for(k=0;k<4;k++)
{
iNum3=aNum[k];
if( iNum1!=iNum2 && iNum1!=iNum3 && iNum2!=iNum3)
{
count++;
printf(”%d%d%d\n”,iNum1, iNum2,iNum3);
}
}
}
}
printf(”Total count:%d\n”, count);

return 0;
}

Written by hkai in: C/C++ |

Powered by WordPress | Aeros Theme | TheBuckmaker.com WordPress Themes