Before calling CreateWindowEx(..) there isn't any error. And CreateWindowEx isn't return NULL. And interestingly window is show up after calling ShowWindow.
In code as you can see there is 2 messageboxes which writes error codes. First one writes 126, other one writes 0.
(Error 126 Means: ERROR_MOD_NOT_FOUND 126 (0x7E) The specified module could not be found.)
After window created, window isn't working properly as you can see in the images, if my pointer in the area where window were created it is in loading position and such things and when I move the mouse cursor into the window, it doesn't display the arrow but the resize cursor.
Sorry about my English and thanks for helps.
Codes: WinDeneme.cpp
// WinDeneme.cpp : Defines the entry point for the application.
//
#include "stdafx.h"
const wchar_t *AppName = L"Example";
unsigned int ClassID=0;
wchar_t Error[100];
LRESULT CALLBACK Proc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam);
int APIENTRY _tWinMain(_In_ HINSTANCE hInstance,
_In_opt_ HINSTANCE hPrevInstance,
_In_ LPTSTR lpCmdLine,
_In_ int nCmdShow)
{
wchar_t *ClassName = (wchar_t*)malloc(sizeof(wchar_t) * 100);
swprintf(ClassName,100,L"%s_%d",AppName,ClassID);
ClassID++;
WNDCLASS *Class = (WNDCLASS*)calloc(1,sizeof(WNDCLASS));
Class->lpszClassName = ClassName;
Class->hInstance = hInstance;
Class->lpfnWndProc = (WNDPROC)Proc;
RegisterClass(Class);
HWND Win = CreateWindowEx(
0, // Optional window styles.
ClassName, // Window class
AppName, // Window text
WS_OVERLAPPEDWINDOW, // Window style
// Size and position
CW_USEDEFAULT, CW_USEDEFAULT, 200, 200,
NULL, // Parent window
NULL, // Menu
hInstance, // Instance handle
NULL // Additional application data
);
swprintf(Error,100,L"%d",GetLastError());
MessageBox(0,Error,L"Error",MB_OK); // 126
ShowWindow(Win,nCmdShow);
swprintf(Error,100,L"%d",GetLastError());
MessageBox(0,Error,L"Error",MB_OK); // 0
MSG msg = { };
while (GetMessage(&msg, NULL, 0, 0))
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
return EXIT_SUCCESS;
}
LRESULT CALLBACK Proc(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);
}
stdafx.h
#include <windows.h>
#include <stdlib.h>
#include <stdio.h>
#include <memory.h>
#include <tchar.h>
Images (I used my camera because cursors dont show up in print screen):
Pointer is in loading position
Pointer is in resizing position
**Edit: I solved pointer issue with adding
Class->hCursor = LoadCursor(NULL, IDC_ARROW);
But I still get Error 126 in VS2012 Express.
GetLastError()
is only meaningful when an actual error occurs, unless documented otherwise.
In the case of CreateWindow/Ex()
, if it returns a non-NULL handle, then no error occurred, and the value of GetLastError()
is undefined (it will still contain an error code from an earlier API function call).
You have to call GetLastError()
immediately after an API function exits and before any other API function is called, and only when the API function fails with an error unless the API function is specifically documented to return a valid GetLastError()
value in other situations (for example, when CreateMutex()
returns a non-NULL handle, GetLastError()
returns ERROR_ALREADY_EXISTS
if the mutex already existed, otherwise it returns 0).
Most API functions do not reset GetLastError()
before performing their work, thus preserving earlier error codes. Only API functions that use GetLastError()
to report extended info on success will reset GetLastError()
if no error occurs.