기본 콘텐츠로 건너뛰기

6월, 2011의 게시물 표시

Join을 이용한 SELECT

EMP와 DEPT를 DEPTNO로 조인하여 쿼리하는 예제입니다. 예제: SELECT EMP.*,DEPT.DNAME FROM EMP JOIN DEPT ON EMP.DEPTNO=DEPT.DEPTNO;

CMarkup

C++에서 사용할수 있는 정말 괜찮은 XML 관련 라이브러리입니다. 예전에 TinyXML을 사용했었는데, 이것은 읽기만 되고 그리고 유니코드를 지원하지 못했던 걸로 기억하고 있는데, CMarkup은 읽기/쓰기가 가능하고요 또한 유니코드도 지원합니다. XML 관련 라이브러리를 찾으신다면 CMarkup 을 한번 사용해 보세요.

[IronPython] 변수로 함수 넘기기

SetVariable 함수로 C# 함수를 넘기는 것을 알아 보겠습니다. 먼저 public 함수를 하나 만드시구요, public class FuncForScript { /// <summary> /// return digit part from string /// </summary> /// <param name="sFromString"></param> /// <returns></returns> static public string GetDigitFromString(string sFromString) { string sDigitString = string.Empty; sFromString = sFromString.Trim(); foreach (char c in sFromString) { if (!char.IsLetter(c)) { sDigitString += c; } else { break; } } return sDigitString; } } ScriptScope에서 아래와 같이하여 함수를 넘길 수 있습니다. 1 2 oScriptScope.SetVariable( "GetDigitFromString" ,  new  Func < string ,  string > (FuncForScript.GetDigitFromString)); Colored by Color Scripter cs 이렇게 하면 Python Code에서  아래와 같이 GetDigitFromString함수를 사용할수 있습

ComboBox에 Datasource 연결하기

잊어버리지 않게 하기위해... 1. DataTable을 생성하여 ComboBox의 Datasource에 연결합니다. 2. ComboxBox의 DisplayMember에 ComboBox에 보여줄 테이블의 Column 이름을 설정합니다. 1 2 3 4 5 6 7 8 9 10 11 12 13 14 try  {     DataTable oTable  =  GetDataTable( "SELECT DISTINCT PREFIX FROM "   +  sTableName, sDataSource);      if  ( null   ! =  oTable)     {         comboBoxSystem.DataSource  =  oTable;         comboBoxSystem.DisplayMember  =   "PREFIX" ;     }      return   true ; } catch  (OleDbException ex) {     cMessageCenter.ShowMessage(ex.Message); } Colored by Color Scripter cs

log4net - Adding appenders programmatically

log4net에서 사용자 정의 appender를 추가하는 방법을 알아보도록 하겠습니다. 1. 먼저 xml을 아래와 같이 작성합니다. 1 2 3 4 5 6 7 8 9 10 11 12 < ?xml   version = "1.0"   encoding = "utf-8"   ? > < log4net >      < appender   name = "HtmlAppender"   type = "log4net.Appender.FileAppender" >          < file   type = "log4net.Util.PatternString"   value = "%property{LogName}"   / >              < appendToFile   value = "true"   / >              < datePattern   value = "-yyyy-MM-dd"   / >              < rollingStyle   value = "Date"   / >              < layout   type = "_7D_EPF.SimpleHtmlColoredLayout , _7D_EPF" >                  < conversionPattern   value = "%d [%t] %-5p %c - %m%n"   / >              < / layout >       < / appender >   < / log4net > Colored by Color Scripter cs HtmlAppender를 추가할려고 하고 있습니다. 잘 보시면 logger 파일 이름을 동적으로 주기 위해서 file

실행 파일 경로 구하기

출처 : http://silhouettes.hostple.net/silhouette/6069 C# 에서도 App.Path 같은 것은 있습니다. Application .ExecutablePath 입니다. 하지만 이것은 exe 파일의 이름까지 반환하기 때문에, 제대로 쓰기 힘듭니다. 제가 VB 6.0 에서 C#.NET 으로 넘어왔기 때문에 이게 적응이 안됐어서 그랬는지는 몰라도., App.Path 와 같이 쓸 수 있는 것을 만들었습니다. 아래는 소스코드입니다. string AppPath = Application .ExecutablePath.Substring(0, Application .ExecutablePath.LastIndexOf( "\\" )); // VB 의 App.Path 역할 넵. 이게 끝입니다. 저 상태에서 AppPath 를 사용해 보시면, Application .ExecutablePath 는  C:\1.exe 를 반환하겠지만 이런식으로 반환을 하는게 아니라 C: 으로 반환하게 될 겁니다. VB 는 맨 끝에 \ 를 안붙이기 때문에. 이만.

How to create annimated gif file by using giflib

giflib을 사용해서 annimated gif 파일을 만드는 법을 알아보도록 하겠습니다. giflib은 여기서 다운 받을수 있습니다.( http://sourceforge.net/projects/giflib/ ) 인터넷 상에서 gif file format은 검색해서 한번 보시는게 도움이 될것입니다. 예제 코드와 output입니다. 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 // giflib_test.cpp : Defines the entry point for the console application. //   #include   "stdafx.h" #include   < string .h > #include   "..\..\lib\gif_lib.h"   #define  WIDTH    200 #define  HEIGHT   200   GifFileType  * GIFfile  =   NULL ; ColorMapObject  * GIFcmap  =   NULL ;   void  initGIF() {      int  i;       GIFcmap  =  MakeMapObject( 256 ,  NULL );     GIFfile  =  EGifOpenFileName( "oscilout.gif" ,  0 );        for  (i  =   0 ; i  <   256 ; i + +

DLL calling convention

오늘 조금 희한한 경우를 발견했습니다. 다름이 아니라 VC++ 아래와 같이 정의한 함수를 extern "C" DLL_EXPORT void DGN2NSQ(const char* pExportFilePath,const char* pImportFilePath , const char* pIniFilePath ) { ... 생략 } VB에서 아래와 같이 선언한 뒤 VB CODE를 컴파일해도 아무런 에러를 발생시키지 않고 컴파일이 성공되었습니다. 매개 변수 하나를 선언하지 않았는데도 말이죠. Declare Sub DGN2NSQ Lib "IEManager.dll" _ (ByVal ExportFilePath As String, ByVal ImportFilePath As String) VC++의 함수에서 디버깅을 해보면 제일 마지막의 값은 쓰레기 값이 넘어오는 것을 확인할 수 있었습니다. DLL함수 호출 규약을  __stdcall으로 바꾸어 테스트를 한번 해 보아야 겠습니다. - 결론 : VB는 똑똑하게(?) 인자 갯수를 다르게 선언하고 또 사용하고 해도 컴파일때 에러를 내지 않습니다. 뭐 이런게 다 있을까요?

한글 인코딩, 소스의 한글 확장 완성형 글자 표현; Korean Hangul Encoding

아래 글은 Google에서 검색하여 어느 분의 블로그에서 퍼 왔습니다. 파이썬 소스에 한글 문자열이 있으면 다음과 같은 "SyntaxError: Non-ASCII character..."라는 에러가 납니다: File "D:\Z\0.py", line 4 SyntaxError: Non-ASCII character '\x8c' in file D:\Z\0.py on line 4, but no encoding declared; see http://www.python.org/peps/pep-0263.html for details 파이썬은 영문 인코딩이 기본이기에, 한글을 표현하기 위해서는 한글 인코딩을 지정해 주어야 합니다. # -*- coding: 949 -*- 위와 같은 행을, 파이썬 소스의 반드시 "1번째 줄" 또는 "2번째 줄"에 위치시켜야 합니다. 3번째 줄부터는 안됩니다. 또한 coding: 이곳의 콜론(:)기호를 coding : 이렇게 띄어쓰면 안됩니다. 파이썬 소스 한글 인코딩 지정 예제 파일명: 0.py #!/usr/bin/python # -*- coding: 949 -*- print "Hello World! 똠방각하" # 이 줄은 주석문(코멘트; Comment)입니다. # -*- coding: cp949 -*- 또는 # -*- coding: ms949 -*- 라고 해도 됩니다. 그러나 # -*- coding: euc-kr -*- 이라고 하면, "똠방각하"의 "똠"자 등이 표현되지 않습니다. "똠"자를 처리하지 못하고 이런 에러가 납니다: SyntaxError: 'euc_kr' codec can't decode bytes in position 20-21: illegal multibyte sequence 즉 확장완성형

Visual Installer에서 Start Menu 구성

Creating Windows Start Menu shortcuts To create folders and shortcuts in the Windows Start Menu , right-click on File System on Target Machine , and select Add Special Folder and then Custom . VSI will create a new sub-folder called NEWFOLDER . Rename this folder in ProgramMenuFolder . Write folder name exactly as shown. This is a Windows Installer constant, used to identify that particular folder. This new folder is the Program Files folder in the Start Menu . Now, you can add a new sub-folder under ProgramMenuFolder and name it as you like, adding here shortcuts as shown before.

다이얼로그에서 static text의 배경을 투명하게 하기

다이얼로그에서 사용하는 static text의 배경색을 투명하게 하는 방법입니다. 다이얼로그의 OnCtlColor를 아래와 같이 재정의합니다. HBRUSH COutstandingOptionDlg::OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor) { HBRUSH hbr; const UINT nID = pWnd->GetDlgCtrlID(); if(nCtlColor == CTLCOLOR_STATIC) { pDC->SetBkMode(TRANSPARENT); /// 배경을 투명하게 hbr = (HBRUSH)::GetStockObject(NULL_BRUSH); } else { hbr = CDialog::OnCtlColor(pDC, pWnd, nCtlColor); } return hbr; } 이것으로 투명한 static text를 만들수 있습니다. 다이얼로그의 배경으로 이미지를 넣었는데... 왼쪽 부분은 static text의 배경을 투명하게 하지 않은 것이고, 오른쪽 부분은 배경으로 투명하게 한것입니다. 오른쪽의 것이 훨씬 보기 좋죠?

프로젝트 기간중 자동으로 Database 구조 변경하기

여태까지 여러 프로젝트를 진행하면서 고민이었던 부분이었는데, 이번 프로젝트를 수행하면서 어느정도 해결이 된것 같다. 즉 개발 기간중 클라이언트에게 테스트하라고 프로그램을 주고 나서 이후에 Database 구조를 변경해야하는 일이 발생한다면, 그래서 다시 프로그램을 줘야 할때 조금 난감한 일이 발생한다. 즉 클라이언트가 가지고 있는 Database 구조가 현재 프로그램과 맞지 않는다는 것이다. 예전 같으면 전화를 걸어 Database 구조가 변경되었으니 새롭게 작업을 하셔야 합니다 라고 이야기 했을것이다. 기존에 작업했던 데이터가 날아가더라도 어쩔수 없이 말이죠... 또 이렇게 전화를 하는 것도 하나의 일이죠. (깜빡잊고 못하면 클라이언트에게서 전화가 오죠 '왜 되던게 안 되느냐고') 그래서 이번 프로젝트에서는 Database 구조를 정의한 파일을 가지도록 했습니다. Database 구조를 변경해야 한다면 Database를 직접 수정하는 것이 아니라 이 정의한 텍스트 파일을 수정하면, 프로그램 로딩시 자동으로 정의한 텍스트 파일의 내용에 맞게 Database 구조를 변경하도록 하였습니다. 이렇게 하니 Database 구조가 변경되더라도 일일이 클라이언트에게 알려줄 필요도 없고, 프로그래머도 Database 구조 변경에 따른 고민도 줄어들게 되었습니다. 프로그래밍시 참조할 필드 이름도 정의한 텍스트 파일이 있으니 쉽게 알수가 있습니다.(예전에는 필드 이름을 알려면 Database를 열어서 확인을 했습니다.) - 특히 모니터가 2개면 아주 편리합니다. % Database 필드를 추가/삭제하는 SQL문으로 위의 내용을 처리하였습니다.

2009년 3월 27일 오후 5시 33분에 저장한 글입니다.

VS2008에서 메서드를 설명을 위해 작성한 매크로입니다. Sub MethodDesc()         Dim time As Date         DTE.ActiveDocument.Selection.Text = "/**"         DTE.ActiveDocument.Selection.NewLine()         DTE.ActiveDocument.Selection.Indent()         DTE.ActiveDocument.Selection.Text = "@brief"         DTE.ActiveDocument.Selection.Indent()         DTE.ActiveDocument.Selection.NewLine(2)         DTE.ActiveDocument.Selection.Text = "@author BHK"         DTE.ActiveDocument.Selection.Indent()         DTE.ActiveDocument.Selection.NewLine(2)         DTE.ActiveDocument.Selection.Text = "@date " + Now().ToString()         DTE.ActiveDocument.Selection.Indent()         DTE.ActiveDocument.Selection.NewLine(2)         DTE.ActiveDocument.Selection.Text = "@param "         DTE.ActiveDocument.Selection.Indent()         DTE.ActiveDocument.Selection.NewLine(2)         DTE.ActiveDocument.Selection.Text = "@return "         DTE.ActiveDocument

MFC에서 윈도우 클래스명 변경

모처럼 강좌로 인해 MSDN 을 뒤적이다가 이런 것을 발견했습니다. 음...이건 어떤 회사들한테는 유용한 팁이라는 군요... 보통 win api 는 쉽게 클래스명을 바꿀수 있지만 MFC 는 좀 숨겨져 있군요...이걸 좀 알았습니다... Spy++로 다이얼로그 기반의 프로그램을 찍어보면 클래스의 기본값이 "#32770"으로 적혀져 있는데 이걸 바꾸는 팁입니다...음...MSDN을 뒤적이다 적은 거라서....뒷북일 것이냐 아니면  큰 볼거리는 안되겠네요 하여간 적어 본다면 우선 주의할 점은 다이얼로그 기반의 클래스 명 바꾸는 것이 SDI 나 MDI 에서는 통하지 않습니다... 이건 또 찾아보아야...긁적... app 분야에 요걸 적어 주시구... BOOL CLimitDlgInstanceApp::InitInstance() { WNDCLASS wc; // 바꾸고자 하는 클래스명임돠... wc.lpszClassName = "MyPrivateClassName"; // Register this class so that MFC can use it. AfxRegisterClass(&wc); 생략..... } 그리고 rc 파일을 텍스트 기반으로 읽으셔서 코딩함돠... IDD_LIMITDLGINSTANCE_DIALOG DIALOGEX 0, 0, 195, 44 STYLE DS_MODALFRAME | WS_POPUP | WS_VISIBLE | WS_CAPTION | WS_SYSMENU EXSTYLE WS_EX_APPWINDOW CAPTION "LimitDlgInstance" CLASS "MyPrivateClassName" // 여기를 추가.... FONT 8, "MS Sans Serif" BEGIN DEFPUSHBUTTON "OK",IDOK,138,7,50,14 PU

Excel automation from C++ with MFC

After digging through the newsgroups for hours, decoding a ton of VB code for automating Excel, converting it to C++ using VC 6.0 and MFC, and enough hair pulling to make me bald, I thought I'd post this to save others the trouble. I created the following include file containing the constants used in most common arguments to the Excel functions for searching, copying, sorting, etc. and a sample mfc program segment that demonstrates their use. Merry Christmas, Bob /* File: xlConstants.h ******************************************* / Constants used in Excel automation from / Visual C++ / / Courtesy of Bob Ray -- 2003 / / Note: The values of additional xl constants can be / found by running Excel and selecting / Tools | Macro | Visual Basic Editor. / / Press F2 to get to the Object Browser. / Type the name of the constant in the search window. / Find the constant and select it. Look at the lower / left of the window to get the value and add / it to this lis