여기 뭔가 잘못되었지만 오류 메시지가 나에게 단서를주지 않습니다. CreateWindow에 대한 호출이 항상 실패하고 (NULL을 반환하고 GetLastError()가 50을 반환합니다). 내가 원하는 것은 간단하고 빈 창이지만 내 요청은 "지원되지 않는다"는 것입니다.CreateWindow가 실패합니다. 오류 50 (요청이 지원되지 않습니다.)
// gcc basic.c -o basic.exe -mwindows
#include <stdio.h>
#include <windows.h>
// Function prototypes.
int WINAPI WinMain(HINSTANCE, HINSTANCE, LPSTR, int);
BOOL InitApplication(HINSTANCE);
BOOL InitInstance(HINSTANCE, int);
LRESULT CALLBACK MainWndProc(HWND, UINT, WPARAM, LPARAM);
// Application entry point.
int WINAPI WinMain(HINSTANCE hinstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow)
{
MSG msg;
if (!InitApplication(hinstance))
return FALSE;
if (!InitInstance(hinstance, nCmdShow))
return FALSE;
BOOL fGotMessage;
while ((fGotMessage = GetMessage(&msg, (HWND) NULL, 0, 0)) != 0 && fGotMessage != -1)
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
return msg.wParam;
}
BOOL InitApplication(HINSTANCE hinstance)
{
WNDCLASSEX wcx;
wcx.cbSize = sizeof (wcx); // size of structure
wcx.style = CS_HREDRAW | CS_VREDRAW;
wcx.lpfnWndProc = MainWndProc; // points to window procedure
wcx.cbClsExtra = 0; // no extra class memory
wcx.cbWndExtra = 0; // no extra window memory
wcx.hInstance = hinstance; // handle to instance
wcx.hIcon = NULL;
wcx.hCursor = NULL;
wcx.hbrBackground = GetStockObject(WHITE_BRUSH); // white background brush
wcx.lpszMenuName = NULL; // name of menu resource
wcx.lpszClassName = "MainWClass"; // name of window class
wcx.hIconSm = NULL; // small class icon
return RegisterClassEx(&wcx);
}
BOOL InitInstance(HINSTANCE hinstance, int nCmdShow)
{
HWND hwnd;
// Create the main window.
hwnd = CreateWindow(
"MainWClass", // name of window class
"Sample", // title-bar string
WS_OVERLAPPEDWINDOW, // top-level window
CW_USEDEFAULT, // default horizontal position
CW_USEDEFAULT, // default vertical position
CW_USEDEFAULT, // default width
CW_USEDEFAULT, // default height
(HWND) NULL, // no owner window
(HMENU) NULL,
hinstance, // handle to application instance
(LPVOID) NULL); // no window-creation data
if (!hwnd) {
int error_code = GetLastError();
char caption[256];
snprintf(caption, sizeof caption, "CreateWindow: error %d", error_code);
MessageBox(NULL, caption, "CreateWindow error", MB_OK);
return FALSE;
}
ShowWindow(hwnd, nCmdShow);
UpdateWindow(hwnd);
return TRUE;
}
LRESULT CALLBACK
MainWndProc(HWND hwnd, UINT uMsg, WPARAM wparam, LPARAM lparam)
{
switch (uMsg) {
case WM_CLOSE:
DestroyWindow(hwnd);
return 1;
case WM_DESTROY:
PostQuitMessage(0);
break;
default:
DefWindowProc(hwnd, uMsg, wparam, lparam);
}
return 0;
}
질문에서 문제를 편집하지 마십시오. * "나는 보여주지 않을 코드에 문제가있었습니다. 이것은 작동 코드입니다."* 작업 코드가 이미 어떻게 보이는지 알 수 있습니다. – IInspectable
아무도 내 문제에 대답하지 않았습니다. 그들은 완전히 다른 여러 가지 오류에 대해 이야기하고있었습니다. – Terran
나는'WM_NCCREATE'에서'0'을 반환하면 (코드가 그렇듯이)'CreateWindow'가'NULL'을 리턴하도록 확신합니다. 아무도 당신의 문제를 해결하지 못했다고 생각하는 이유는 무엇입니까? – IInspectable