티스토리 뷰
MyFC.h
#pragma once
#include <windows.h>
#include <tchar.h>
#ifndef AFXAPI
#define AFXAPI __stdcall
#endif
////////////////////////////////////////
class CFrameWnd
{
public:
CFrameWnd();
BOOL Create(LPCTSTR lpszClassName, LPCTSTR lpszWindowName);
BOOL ShowWindow(int nCmdShow);
void UpdateWindow();
private:
HWND m_hWnd;
};
////////////////////////////////////////
class CWinApp
{
public:
CWinApp();
virtual BOOL InitInstance();
virtual int Run();
CFrameWnd* m_pMainWnd;
};
////////////////////////////////////////
#include <windows.h>
#include <tchar.h>
#ifndef AFXAPI
#define AFXAPI __stdcall
#endif
////////////////////////////////////////
class CFrameWnd
{
public:
CFrameWnd();
BOOL Create(LPCTSTR lpszClassName, LPCTSTR lpszWindowName);
BOOL ShowWindow(int nCmdShow);
void UpdateWindow();
private:
HWND m_hWnd;
};
////////////////////////////////////////
class CWinApp
{
public:
CWinApp();
virtual BOOL InitInstance();
virtual int Run();
CFrameWnd* m_pMainWnd;
};
////////////////////////////////////////
MyFC.cpp
#include "MyFC.h"
////////////////////////////////////////
int AFXAPI AfxWinMain(HINSTANCE, HINSTANCE, LPTSTR, int);
CWinApp* AFXAPI AfxGetApp();
LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM);
////////////////////////////////////////
HINSTANCE g_hInstance = NULL;
CWinApp* afxCurrentWinApp = NULL;
CFrameWnd* afxCurrentFrameWnd = NULL;
////////////////////////////////////////
int APIENTRY _tWinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPTSTR lpCmdLine, int nCmdShow)
{
return AfxWinMain(hInstance, hPrevInstance, lpCmdLine, nCmdShow);
}
int AFXAPI AfxWinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPTSTR lpCmdLine, int nCmdShow)
{
g_hInstance = hInstance;
int nReturnCode = -1;
CWinApp* pApp = AfxGetApp();
if (afxCurrentWinApp != NULL)
{
pApp->InitInstance();
if (afxCurrentFrameWnd != NULL)
{
nReturnCode = pApp->Run();
}
}
return nReturnCode;
}
////////////////////////////////////////
CWinApp* AFXAPI AfxGetApp()
{
return afxCurrentWinApp;
}
////////////////////////////////////////
LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
{
switch (message)
{
case WM_DESTROY:
PostQuitMessage(0);
return 0;
}
return DefWindowProc(hWnd, message, wParam, lParam);
}
////////////////////////////////////////
CFrameWnd::CFrameWnd()
{
afxCurrentFrameWnd = this;
}
BOOL CFrameWnd::Create(LPCTSTR lpszClassName, LPCTSTR lpszWindowName)
{
TCHAR szClass[100];
TCHAR szTitle[100];
lstrcpy(szClass, lpszClassName);
lstrcpy(szTitle, lpszWindowName);
WNDCLASSEX wcex;
wcex.cbSize = sizeof(WNDCLASSEX);
wcex.style = CS_HREDRAW | CS_VREDRAW;
wcex.lpfnWndProc = (WNDPROC)WndProc;
wcex.cbClsExtra = 0;
wcex.cbWndExtra = 0;
wcex.hInstance = g_hInstance;
wcex.hIcon = LoadIcon(NULL, IDI_APPLICATION);
wcex.hCursor = LoadCursor(NULL, IDC_ARROW);
wcex.hbrBackground = (HBRUSH)GetStockObject(WHITE_BRUSH);
wcex.lpszMenuName = NULL;
wcex.lpszClassName = szClass;
wcex.hIconSm = LoadIcon(NULL, IDI_APPLICATION);
::RegisterClassEx(&wcex);
m_hWnd = ::CreateWindowEx(NULL, szClass, szTitle, WS_OVERLAPPEDWINDOW,
CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT,
NULL, NULL, g_hInstance, NULL);
return TRUE;
}
BOOL CFrameWnd::ShowWindow(int nCmdShow)
{
return ::ShowWindow(m_hWnd, nCmdShow);
}
void CFrameWnd::UpdateWindow()
{
::UpdateWindow(m_hWnd);
}
////////////////////////////////////////
CWinApp::CWinApp()
{
afxCurrentWinApp = this;
}
BOOL CWinApp::InitInstance()
{
return TRUE;
}
int CWinApp::Run()
{
MSG msg;
while (::GetMessage(&msg, NULL, 0, 0))
{
::TranslateMessage(&msg);
::DispatchMessage(&msg);
}
return (int)msg.wParam;
}
////////////////////////////////////////
////////////////////////////////////////
int AFXAPI AfxWinMain(HINSTANCE, HINSTANCE, LPTSTR, int);
CWinApp* AFXAPI AfxGetApp();
LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM);
////////////////////////////////////////
HINSTANCE g_hInstance = NULL;
CWinApp* afxCurrentWinApp = NULL;
CFrameWnd* afxCurrentFrameWnd = NULL;
////////////////////////////////////////
int APIENTRY _tWinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPTSTR lpCmdLine, int nCmdShow)
{
return AfxWinMain(hInstance, hPrevInstance, lpCmdLine, nCmdShow);
}
int AFXAPI AfxWinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPTSTR lpCmdLine, int nCmdShow)
{
g_hInstance = hInstance;
int nReturnCode = -1;
CWinApp* pApp = AfxGetApp();
if (afxCurrentWinApp != NULL)
{
pApp->InitInstance();
if (afxCurrentFrameWnd != NULL)
{
nReturnCode = pApp->Run();
}
}
return nReturnCode;
}
////////////////////////////////////////
CWinApp* AFXAPI AfxGetApp()
{
return afxCurrentWinApp;
}
////////////////////////////////////////
LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
{
switch (message)
{
case WM_DESTROY:
PostQuitMessage(0);
return 0;
}
return DefWindowProc(hWnd, message, wParam, lParam);
}
////////////////////////////////////////
CFrameWnd::CFrameWnd()
{
afxCurrentFrameWnd = this;
}
BOOL CFrameWnd::Create(LPCTSTR lpszClassName, LPCTSTR lpszWindowName)
{
TCHAR szClass[100];
TCHAR szTitle[100];
lstrcpy(szClass, lpszClassName);
lstrcpy(szTitle, lpszWindowName);
WNDCLASSEX wcex;
wcex.cbSize = sizeof(WNDCLASSEX);
wcex.style = CS_HREDRAW | CS_VREDRAW;
wcex.lpfnWndProc = (WNDPROC)WndProc;
wcex.cbClsExtra = 0;
wcex.cbWndExtra = 0;
wcex.hInstance = g_hInstance;
wcex.hIcon = LoadIcon(NULL, IDI_APPLICATION);
wcex.hCursor = LoadCursor(NULL, IDC_ARROW);
wcex.hbrBackground = (HBRUSH)GetStockObject(WHITE_BRUSH);
wcex.lpszMenuName = NULL;
wcex.lpszClassName = szClass;
wcex.hIconSm = LoadIcon(NULL, IDI_APPLICATION);
::RegisterClassEx(&wcex);
m_hWnd = ::CreateWindowEx(NULL, szClass, szTitle, WS_OVERLAPPEDWINDOW,
CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT,
NULL, NULL, g_hInstance, NULL);
return TRUE;
}
BOOL CFrameWnd::ShowWindow(int nCmdShow)
{
return ::ShowWindow(m_hWnd, nCmdShow);
}
void CFrameWnd::UpdateWindow()
{
::UpdateWindow(m_hWnd);
}
////////////////////////////////////////
CWinApp::CWinApp()
{
afxCurrentWinApp = this;
}
BOOL CWinApp::InitInstance()
{
return TRUE;
}
int CWinApp::Run()
{
MSG msg;
while (::GetMessage(&msg, NULL, 0, 0))
{
::TranslateMessage(&msg);
::DispatchMessage(&msg);
}
return (int)msg.wParam;
}
////////////////////////////////////////
Program.cpp
#include "MyFC.h"
class CMyWinApp : public CWinApp
{
public:
BOOL InitInstance()
{
CFrameWnd *pFrameWnd = new CFrameWnd;
m_pMainWnd = pFrameWnd;
pFrameWnd->Create(TEXT("MyClass"), TEXT("Hello World~")); // calls ::RegisterClassEx & ::CreateClassEx
pFrameWnd->ShowWindow(SW_SHOW); // calls ::ShowWindow
pFrameWnd->UpdateWindow(); // calls ::UpdateWindow
return TRUE;
}
};
CMyWinApp theApp;
class CMyWinApp : public CWinApp
{
public:
BOOL InitInstance()
{
CFrameWnd *pFrameWnd = new CFrameWnd;
m_pMainWnd = pFrameWnd;
pFrameWnd->Create(TEXT("MyClass"), TEXT("Hello World~")); // calls ::RegisterClassEx & ::CreateClassEx
pFrameWnd->ShowWindow(SW_SHOW); // calls ::ShowWindow
pFrameWnd->UpdateWindow(); // calls ::UpdateWindow
return TRUE;
}
};
CMyWinApp theApp;
[MFC] Simplest MFC Program
'Code > C C++' 카테고리의 다른 글
[C++] How to: Convert Between Various String Types (0) | 2010.05.17 |
---|---|
[C++] vector shared_ptr sample (0) | 2010.05.15 |
[MFC] Simplest MFC Program (0) | 2010.04.23 |
[C++] Regular Expressions Class: regex (0) | 2010.04.18 |
[C++/CLI] #pragma managed, #pragma unmanaged (0) | 2009.05.09 |
공지사항
최근에 올라온 글
최근에 달린 댓글
- Total
- Today
- Yesterday
링크
TAG
- Phalanger
- .net framework
- registry
- 유틸리티
- windows
- tagREADYSTATE
- READYSTATE_COMPLETE
- iText
- ScreenHunter
- 애드센스감추기
- iTextSharp
- AxWebBrowser
- Automation
- download.com
- Service pack
- java
- 스크린캡쳐
- WinAutomation
- 애드센스숨기기
- Microsoft
- Rollback Rx
- Regular Expressions
- c#
- Sample Code
- AdSense숨기기
- AdSense감추기
- DotNetMagic
- jre
- autohotkey
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
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 |
글 보관함