Pozdrav svima, ovo je moj prvi post na ovom forumu.
Moj problem:
koristim MVS Express edition (C++) 2010, znači nema resource editor-a a i ne koristim MFC. Sastavio sam minimalnu aplikaciju za koju vas molim ako imate vremena da probate da li funkcioniše kod vas:
main.cpp
Kôd:
#include <Windows.h>
#include <xstring>
#include "resources.h"
LRESULT CALLBACK WndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam);
void ReportLastError();
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow)
{
HWND hwnd;
HINSTANCE hinstance;
std::wstring strClassName = L"TestClass";
std::wstring strAppCaption = L"TestApp";
WNDCLASSEX wndClass;
ZeroMemory(&wndClass, sizeof(WNDCLASSEX));
hinstance = GetModuleHandle(NULL);
wndClass.cbSize = sizeof(WNDCLASSEX);
wndClass.hInstance = hinstance;
wndClass.lpfnWndProc = (WNDPROC)WndProc;
wndClass.hCursor = LoadCursor(NULL, IDC_ARROW);
wndClass.lpszClassName = strClassName.c_str();
wndClass.hIcon = reinterpret_cast<HICON>(LoadImage(
hinstance, MAKEINTRESOURCE(ID_APP_ICON), IMAGE_ICON, GetSystemMetrics(SM_CXICON), GetSystemMetrics(SM_CYICON), 0));
if(0 == wndClass.hIcon)
{
ReportLastError();
}
wndClass.hIconSm = reinterpret_cast<HICON>(LoadImage(
hinstance, MAKEINTRESOURCE(ID_APP_ICON), IMAGE_ICON, GetSystemMetrics(SM_CXSMICON), GetSystemMetrics(SM_CYSMICON), 0));
if(0 == wndClass.hIconSm)
{
ReportLastError();
}
wndClass.hbrBackground = GetSysColorBrush(COLOR_3DFACE);
if(!RegisterClassEx(&wndClass))
{
ReportLastError();
}
DWORD dwStyle = WS_SYSMENU | WS_BORDER | WS_CAPTION | WS_CLIPSIBLINGS | WS_VISIBLE | WS_MINIMIZEBOX;
RECT clientSize;
clientSize.top = 0;
clientSize.left = 0;
clientSize.right = 100;
clientSize.bottom = 100;
AdjustWindowRect(&clientSize, dwStyle, FALSE);
int realWidth = clientSize.right - clientSize.left;
int realHeight = clientSize.bottom - clientSize.top;
int windowLeft = (GetSystemMetrics(SM_CXSCREEN) - realWidth) / 2;
int windowTop = (GetSystemMetrics(SM_CYSCREEN) - realHeight) / 2;
hwnd = CreateWindowEx(
NULL, strClassName.c_str(), strAppCaption.c_str(), dwStyle,
windowLeft, windowTop, realWidth, realHeight,
NULL, NULL, hinstance, 0);
if(NULL == hwnd)
{
ReportLastError();
return 0;
}
ShowWindow(hwnd, SW_SHOW);
UpdateWindow(hwnd);
MSG msg = {0};
while(GetMessage(&msg, NULL, 0, 0))
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
return (int)msg.wParam;
}
LRESULT CALLBACK WndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
{
switch(msg)
{
case WM_DESTROY:
{
PostQuitMessage(0);
return 0;
}break;
};
return DefWindowProc(hwnd, msg, wParam, lParam);
}
void ReportLastError()
{
DWORD errCode = GetLastError();
wchar_t* szErr;
DWORD res = FormatMessage(
FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS,
NULL, errCode, 0, (LPWSTR)&szErr, 0, NULL);
if(0 == res)
{
return;
}
wchar_t* mbCaption = TEXT("Error!");
MessageBox(0, szErr, mbCaption, MB_ICONEXCLAMATION | MB_OK);
LocalFree(szErr);
}
reources.h
Kôd:
#ifndef resources_HEADER_DEFINED
#define resources_HEADER_DEFINED
#define ID_APP_ICON (100)
#endif
resources.rc
Kôd:
#include "resources.h"
ID_APP_ICON ICON DISCARDABLE "appicon.ico"
dobijem prikaz ikone u taskbaru i u prozorima ali je nema u levom uglu aplikacije (kod "caption"-a) stoji "default" ikona. Ikonu sam pravio sa
IconFX programom,
ikona je True color 32bit i ima 3 "images" 48x48, 32x32 i 16x16.
Ne znam koji se qra* događa, oprostite na jeziku ali se batrgam sa ovim već neko vreme, čupam kosu sa glave a ne mogu da nađem u čemu je problem.
Hvala unapred.