티스토리 뷰
데브피아 C#마을 조동현님께서 올리신 팁입니다.
개인 라이브러리에 추가해서 유용하게 잘 사용하고 있습니다.
아래 내용을 참고하면 아래와 같은 메세지 박스를 생성할 수 있습니다.
using System;
using System.Windows.Forms;
using System.Runtime.InteropServices;
public class MessageBoxEx
{
delegate int HookProc(int code, IntPtr wParam, IntPtr lParam);
[DllImport("user32.dll", SetLastError = true)]
static extern IntPtr SetWindowsHookEx(int hook, HookProc callback, IntPtr hMod, uint dwThreadId);
[DllImport("user32.dll")]
static extern bool UnhookWindowsHookEx(IntPtr hhk);
[DllImport("user32.dll")]
static extern int CallNextHookEx(IntPtr hhk, int nCode, IntPtr wParam, IntPtr lParam);
[DllImport("user32.dll")]
static extern IntPtr GetDlgItem(IntPtr hDlg, DialogResult nIDDlgItem);
[DllImport("user32.dll")]
static extern bool SetDlgItemText(IntPtr hDlg, DialogResult nIDDlgItem, string lpString);
[DllImport("kernel32.dll")]
static extern uint GetCurrentThreadId();
static IntPtr g_hHook;
static string yes;
static string cancel;
static string no;
/// <summary>
/// 메시지 박스를 띠웁니다.
/// </summary>
/// <param name="text">텍스트 입니다.</param>
/// <param name="caption">캡션 입니다.</param>
/// <param name="yes">예 문자열 입니다.</param>
/// <param name="no">아니오 문자열 입니다.</param>
/// <param name="cancel">취소 문자열 입니다.</param>
/// <returns></returns>
public static DialogResult Show(string text, string caption, string yes, string no, string cancel)
{
MessageBoxEx.yes = yes;
MessageBoxEx.cancel = cancel;
MessageBoxEx.no = no;
g_hHook = SetWindowsHookEx(5, new HookProc(HookWndProc), IntPtr.Zero, GetCurrentThreadId());
return MessageBox.Show(text, caption, MessageBoxButtons.YesNoCancel, MessageBoxIcon.Question);
}
static int HookWndProc(int nCode, IntPtr wParam, IntPtr lParam)
{
IntPtr hChildWnd;
if (nCode == 5)
{
hChildWnd = wParam;
if (GetDlgItem(hChildWnd, DialogResult.Yes) != null)
SetDlgItemText(hChildWnd, DialogResult.Yes, MessageBoxEx.yes);
if (GetDlgItem(hChildWnd, DialogResult.No) != null)
SetDlgItemText(hChildWnd, DialogResult.No, MessageBoxEx.no);
if (GetDlgItem(hChildWnd, DialogResult.Cancel) != null)
SetDlgItemText(hChildWnd, DialogResult.Cancel, MessageBoxEx.cancel);
UnhookWindowsHookEx(g_hHook);
}
else
CallNextHookEx(g_hHook, nCode, wParam, lParam);
return 0;
}
}
엄청난 DllImport와 static이지요...
ex)
MessageBoxEx.Show("정지 하시겠습니까?", "정지", "야스", "노노", "취소닷!");
'프로그래밍 > .NetFramework' 카테고리의 다른 글
WorkBook 을 이용해서 GridView 엑셀로 내려받기 (0) | 2012.04.23 |
---|---|
EXCEL2010(엑셀2010) 읽기 Workbook 이용 (엑셀읽기) (0) | 2012.04.13 |
강력한코드그룹 삭제 및, 클릭원스 온라인배포 프로그램 삭제방법 (0) | 2012.04.04 |
윈도우7 에서 관리자권한으로 실행하기. UAC 권한 상승. (0) | 2012.04.04 |
닷넷프레임워크 삭제 유틸리티 (0) | 2012.03.16 |
- Total
- Today
- Yesterday
- Style
- jQuery Mobile
- drag&drop
- JS
- 저장프로시저
- json
- 자바스크립트
- WCF
- IE
- html5
- radius
- 셀렉터
- workbook
- Mobile
- CSS
- JavaScript
- WebApi
- jquery chart
- MSSQL
- Chart
- 프로시저
- css3
- rowspan
- Excel
- SVG
- grid
- jQuery
- ASP.NET
- Ajax
- 제이쿼리
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
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 |