아래 라이브러리들을 링크한다. (순서도 중요할거다)
-lmingw32 -lgdi32 -lkernel32 -luser32 -lws2_32
단순한 윈도우 샘플 코드:
#include <windows.h> HWND hWnd; TCHAR appName[256] = TEXT("Hello"); TCHAR className[256] = TEXT("example1"); LRESULT CALLBACK WndProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam); int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nShowCmd) { MSG msg; WNDCLASS wc; wc.cbClsExtra = 0; wc.cbWndExtra = 0; wc.hbrBackground = (HBRUSH)GetStockObject(WHITE_BRUSH); wc.hCursor = LoadCursor(NULL, IDC_ARROW); wc.hIcon = LoadIcon(NULL, IDI_APPLICATION); wc.hInstance = hInstance; wc.lpfnWndProc = (WNDPROC)WndProc; wc.lpszClassName = className; wc.lpszMenuName = 0; wc.style = CS_HREDRAW | CS_VREDRAW; RegisterClass(&wc); hWnd = CreateWindow(className, appName, WS_OVERLAPPEDWINDOW, 10, 10, 500, 400, NULL, (HMENU)NULL, hInstance, NULL); ShowWindow(hWnd, SW_SHOW); while(GetMessage(&msg, 0, 0, 0)) { TranslateMessage(&msg); DispatchMessage(&msg); } return 0; } LRESULT CALLBACK WndProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam) { switch(message) { case WM_DESTROY: PostQuitMessage(0); return 0; default: break; } return DefWindowProc(hwnd, message, wParam, lParam); }
실행하면 아래 같이 나온다.
!) 만약 cmd 에서 컴파일 한다면 -mwindows 라고 명시해야 한다
참고: http://stackoverflow.com/a/12651975
예) gcc -Wall -mwindows -lmingw32 -lgdi32 -lkernel32 -luser32 -lws2_32 main.c
댓글 없음:
댓글 쓰기