맨밑에 에러메세지 뭐뜨는지 써드림
-------------------------코드-----------------------------
#include <windows.h>
#define ID_OK_BTN 2000
HINSTANCE g_hInst;
LPCTSTR lpszClass = "HelloAPI";
LPCTSTR ChildClassName = "ChildWin";
LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM);
LRESULT CALLBACK ChildWndProc(HWND hWnd, UINT Messa, WPARAM wParam, LPARAM lParam);
int APIENTRY WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdParam, int nCmdShow)
{
HWND hWnd;
MSG Message;
WNDCLASS WndClass;
g_hInst=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.lpfnWndProc=(WNDPROC)WndProc;
WndClass.lpszClassName=lpszClass;
WndClass.lpszMenuName=NULL;
WndClass.style=CS_HREDRAW | CS_VREDRAW;
RegisterClass(&WndClass); //메인 윈도우 클래스 등록
OutputDebugString("메인 윈도우 클래스 등록n");
WndClass.lpfnWndProc=ChildWndProc; //차일드 윈도우 프로시저
WndClass.lpszClassName=ChildClassName;
RegisterClass(&WndClass);
OutputDebugString("차일드 클래스 등록n");
OutputDebugString("CreateWindow - 메인 윈도우의 생성 시작n");
hWnd=CreateWindow(lpszClass, "윈도우 프로그래밍", WS_OVERLAPPEDWINDOW | WS_VISIBLE, 200, 200, 600, 600, (HWND)NULL, (HMENU)NULL, hInstance, NULL);
OutputDebugString("메인 윈도우의 생성 완료n");
ShowWindow(hWnd, nCmdShow);
OutputDebugString("메인 윈도우의 Show 완료n");
while(GetMessage(&Message,0,0,0)) {
TranslateMessage(&Message);
DispatchMessage(&Message);
}
return Message.wParam;
}
LRESULT CALLBACK WndProc(HWND hWnd, UINT iMessage, WPARAM wParam, LPARAM lParam)
{
char text[] = "메인 윈도우 생성";
switch(iMessage) {
case WM_PAINT:
{
PAINTSTRUCT ps;
HDC hdc = BeginPaint(hWnd, &ps);
TextOut(hdc,100,100,text,strlen(text));
OutputDebugString("(메인 윈도우)WndProc의 WM_PAINT 발생 처리n");
EndPaint(hWnd,&ps);
return 0;
}
case WM_CREATE:
{
OutputDebugString("WndProc에서 child 윈도우 생성 시작n");
HWND hChildWnd = CreateWindow(ChildClassName, "차일드 윈도우", WS_OVERLAPPEDWINDOW | WS_CHILD, 150, 150, 260, 200, hWnd, (HMENU) 2000, g_hInst, (LPVOID) NULL);
ShowWindow(hChildWnd, SW_SHOW);
OutputDebugString("WndProc에서 child 윈도우 생성과 Show 완료n");
OutputDebugString("WndProc에서 버튼 윈도우 생성 시작n");
hChildWnd = CreateWindow("button","지역대학",WS_CHILD | WS_VISIBLE,20,400,100,30,hWnd,(HMENU) ID_OK_BTN,g_hInst,(LPVOID) NULL);
if (!hChildWnd) return -1;
OutputDebugString("WndProc에서 버튼 윈도우 생성 및 Show 완료n");
return 0;
}
case WM_COMMAND:
{
OutputDebugString("WM_COMMAND] 발생n");
if(LOWORD(wParam) == ID_OK_BTN)
{
MessageBox(hWnd,"[지역대학] 버튼이 클릭되었다","지역대학",MB_OK);
}
OutputDebugString("MessageBox [확인] 처리 완료n");
return 0;
}
case WM_DESTROY :
OutputDebugString("WndProc에서 WM_DESTROY 처리 시작n");
PostQuitMessage(0);
OutputDebugString("WndProc에서 WM_DESTROY 처리 완료n");
return 0;
}
return(DefWindowProc(hWnd,iMessage,wParam,lParam));
}
LRESULT CALLBACK ChildWndProc(HWND hWnd, UINT Messa, WPARAM wParam, LPARAM lParam)
{
char tsxt[] = "차일드 윈도우 생성";
switch(Messa)
{
case WM_PAINT:
{
PAINTSTRUCT ps;
HDC hdc = BeginPaint(hWnd, &ps);
TextOut(hdc, 10, 10, text, strlen(text));
EndPaint(hWnd, &ps);
OutputDebugString("ChildWndProc에서 WM_PAINT 처리 완료n");
return 0;
}
}
return DefWindowProc(hWnd, Messa, wParam, lParam);
}
----------------코드---------------
1>------ 빌드 시작: 프로젝트: HelloAPI-Debug, 구성: Debug Win32 ------
1>컴파일하고 있습니다...
1>HelloAPI.cpp
1>링크하고 있습니다...
1>MSVCRTD.lib(crtexe.obj) : error LNK2019: _main 외부 기호(참조 위치: ___tmainCRTStartup 함수)에서 확인하지 못했습니다.
1>C:UsersKimDesktopC++HelloAPI-DebugDebugHelloAPI-Debug.exe : fatal error LNK1120: 1개의 확인할 수 없는 외부 참조입니다.
1>빌드 로그가 "file://c:UsersKimDesktopC++HelloAPI-DebugHelloAPI-DebugDebugBuildLog.htm"에 저장되었습니다.
1>HelloAPI-Debug - 오류: 2개, 경고: 0개
========== 빌드: 성공 0, 실패 1, 최신 0, 생략 0 ==========
이 ㅅㅂ 시작부터 넘 코드가 기니깐 뭐가 문젠지 찾을라면 머리아파서 못 찾겠다
이건 보는 형들도 그렇겠지??
--------
울집 컴이 dc 댓글 작성이 자꾸 안되어서
연타했다가 도배 차단되어서 글 내용을 수정함
코세횽 말대로 프로젝트 시작을 잘못했었네여
아직 해보진 않았지만 win32프로젝트 - windows 응용 프로그램 으로 시작하려던게
win32 콘솔 응용 프로그램 - 콘솔 응용 프로그램 으로 시작되어있었음
복붙하러감;
김군여기서이러시면안됍니다
원래 여기서 공부핸는데;;
근데 지금 전에 해놨던 것도 안되네여 보니깐 먼가 설정을 바꿔야하던가
젤 윗줄에 때려넣어 #pragma comment(linker, \"/SUBSYSTEM:WINDOWS\")