2013-05-25 4 views
1

내가 그래서 난 자신의 코드 시도 C 프로그래밍 윈도우 ++에 대한 MSDN의 교훈을 복용했다 :정의되지 않은 참조

: 내가로 컴파일 된대로

#ifndef UNICODE 
#define UNICODE 
#endif 

#include <windows.h> 

LRESULT CALLBACK WindowProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam); 

int WINAPI wWinMain(HINSTANCE hInstance, HINSTANCE, PWSTR pCmdLine, int nCmdShow) 
{ 
// Register the window class. 
const wchar_t CLASS_NAME[] = L"Sample Window Class"; 

WNDCLASS wc = { }; 

wc.lpfnWndProc = WindowProc; 
wc.hInstance  = hInstance; 
wc.lpszClassName = CLASS_NAME; 

RegisterClass(&wc); 

// Create the window. 

HWND hwnd = CreateWindowEx(
    0,        // Optional window styles. 
    CLASS_NAME,      // Window class 
    L"Learn to Program Windows", // Window text 
    WS_OVERLAPPEDWINDOW,   // Window style 

    // Size and position 
    CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, 

    NULL,  // Parent window  
    NULL,  // Menu 
    hInstance, // Instance handle 
    NULL  // Additional application data 
    ); 

if (hwnd == NULL) 
{ 
    return 0; 
} 

ShowWindow(hwnd, nCmdShow); 

// Run the message loop. 

MSG msg = { }; 
while (GetMessage(&msg, NULL, 0, 0)) 
{ 
    TranslateMessage(&msg); 
    DispatchMessage(&msg); 
} 

return 0; 
} 

LRESULT CALLBACK WindowProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam) 
{ 
switch (uMsg) 
{ 
case WM_DESTROY: 
    PostQuitMessage(0); 
    return 0; 

case WM_PAINT: 
    { 
     PAINTSTRUCT ps; 
     HDC hdc = BeginPaint(hwnd, &ps); 

     FillRect(hdc, &ps.rcPaint, (HBRUSH) (COLOR_WINDOW+1)); 

     EndPaint(hwnd, &ps); 
    } 
    return 0; 

} 
return DefWindowProc(hwnd, uMsg, wParam, lParam); 

}

undefined reference to [email protected] 
:
g++ -c app.cpp -s app.o 
g++ -o app.exe app.o -s -Wl,--subsystem,windows 

는 내가 오류를 얻을

무엇이 부족합니까?

+1

아마도'WinMain'으로'wWinMain'의 이름을 변경해보십시오. –

+0

'GetCommandLineW'를 사용하여 커맨드 라인을 와이드 문자열로 얻을 수 있습니다. – chris

+0

@ HansPassant 튜토리얼의 Writer가 거기에 쓴다면, WinMain과 PSTR의 인수로 변경 했더라도 오류가 계속 발생합니다. 코드가 한 번 실행되었으므로 작동하도록해야합니다. –

답변

0

wWinMainWinMain ....

편집해야합니다 : 좋아, 당신이 wWinMain의 "폭"버전을 사용하려는 경우, 난 당신이 #include <windows.h>와 다른 비트가 데리러 너무 -D_UNICODE를 정의 할 필요가 기대 있도록 오른쪽 부분. (또는 소스에서 #define UNICODE#define _UNICODE으로 수정하십시오)

+0

여전히 동일한 효과, 나는 그 두 가지의 차이점은 WinMain이 PWSTR로 걸리는 동안 WSTRain이 PSTR로 세번째 인수를 취한다는 것입니다. –

+0

@MauriceRodriguez, 당신은 항상'int main()'만 시도 할 수 있습니다. 나는 대체로'nCmdShow'에 대한 대체물이 무엇인지 확실하지 않습니다. 나는 보통 WS_VISIBLE 만 사용한다. – chris