-
[펌] 콘솔 어플리케이션에서 윈도우 만들기Window Programming 2007. 12. 6. 15:48728x90
[펌자료] 원문 : http://unfinished.egloos.com/3138081
C의 console application mode에서 윈도우를 만들기.
가장 핵심이 되는 것은 system에서 받아와야 옳지만, console application에서는 자동으로 받을 수 없는 WNDCLASS 구조의hInstance였다.
HINSTANCE hInstance = GetModuleHandle(NULL);
아래의 코드를 실행하면 이렇게 간단한 윈도우가 생성된다.
#include <windows.h>
LRESULT CALLBACK WndProc(HWND hWnd, UINT iMessage, WPARAM wParam, LPARAM IParam);
HINSTANCE g_Inst;
LPCTSTR lpszClass = TEXT("First");int main()
{
HWND hWnd;
MSG Message;
WNDCLASS WndClass;HINSTANCE hInstance = GetModuleHandle(NULL);
g_Inst = hInstance;WndClass.cbClsExtra = 0;
WndClass.cbWndExtra = 0;
WndClass.hbrBackground = (HBRUSH)GetStockObject(WHITE_BRUSH);
WndClass.hCursor = LoadCursor(NULL, IDC_ARROW);
WndClass.hIcon = LoadIcon(NULL, IDI_APPLICATION);
WndClass.hInstance = hInstance;
WndClass.lpszClassName = lpszClass;
WndClass.lpszMenuName = NULL;
WndClass.style = CS_HREDRAW|CS_VREDRAW;WndClass.lpfnWndProc = WndProc;
RegisterClass(&WndClass);
hWnd = CreateWindow(lpszClass, lpszClass, WS_OVERLAPPEDWINDOW,
0, 0, 640, 480,
NULL, (HMENU)NULL, hInstance, NULL);ShowWindow(hWnd, SW_SHOW);
while(GetMessage(&Message, NULL, 0, 0))
{
TranslateMessage(&Message);
DispatchMessage(&Message);
}return (int)Message.wParam;
}
LRESULT CALLBACK WndProc(HWND hWnd, UINT iMessage, WPARAM wParam, LPARAM IParam)
{
switch(iMessage)
{
case WM_DESTROY:
PostQuitMessage(0);
return 0;
}return(DefWindowProc(hWnd, iMessage, wParam, IParam));
}