Извиняюсь, при отладке загляделся и не заметил. Исправленный вариант:
Код:
#define UNICODE
#include <windows.h>
#pragma hdrstop
//---------------------------------------------------------------------------
struct loader_t
{
wchar_t** argv;
int argc;
HWND hwnd;
loader_t() : argv(), argc(), hwnd()
{
argv = CommandLineToArgvW(GetCommandLine(), &argc);
}
bool createWindow(HINSTANCE hinst, unsigned timeout)
{
if (1<argc)
{
HWND hwnd = CreateWindowEx(WS_EX_TOPMOST, L"STATIC", 0,
WS_POPUP|WS_BORDER|SS_BITMAP, 0, 0, 0, 0,
CreateWindowEx(0, L"STATIC", 0, 0, 0, 0, 0, 0, 0, 0, hinst, 0),
0, hinst, 0);
SendMessage(hwnd, STM_SETIMAGE, IMAGE_BITMAP, reinterpret_cast<long>(
LoadImage(0, argv[1], IMAGE_BITMAP, 0, 0, LR_LOADFROMFILE)));
RECT rect;
return GetWindowRect(hwnd, &rect) &&
SetWindowPos(hwnd, HWND_TOPMOST, (GetSystemMetrics(SM_CXSCREEN)-rect.right)>>1,
(GetSystemMetrics(SM_CYSCREEN)-rect.bottom)>>1, 0, 0, SWP_NOSIZE|SWP_SHOWWINDOW) &&
UpdateWindow(hwnd) &&
SetTimer(hwnd, 111, timeout, 0);
}
return false;
}
~loader_t()
{
GlobalFree(argv);
}
};
#pragma argsused
WINAPI WinMain(HINSTANCE hInstance, HINSTANCE /*hPrevInstance*/, LPSTR /*lpCmdLine*/, int /*nCmdShow*/)
{
if (loader_t().createWindow(hInstance, 2000))
{
MSG cmsg;
while (GetMessage(&cmsg, 0, 0, 0)==1 &&
cmsg.message!=WM_TIMER && cmsg.wParam!=111)
{
DispatchMessage(&cmsg);
}
return 1;
}
return 0;
}
//---------------------------------------------------------------------------