akurát sa učím programovať v C++ s Win32 API. Používam VS 2010 IDE.
Snažím sa creatnúť menu, ktoré už mám urobené v Maybe.cpp.rc.
Tu je main.cpp
Kód: Vybrať všetko
#include <windows.h>
#include <tchar.h>
#include <string>
#include "resource.h";
typedef std::basic_string<TCHAR> ustring;
LRESULT CALLBACK WndProc(HWND,UINT,WPARAM,LPARAM);
inline int ErrMsg(const ustring&);
int WINAPI WinMain(HINSTANCE hInst,HINSTANCE,LPSTR pStr,int nCmd)
{
ustring classname=_T("SIMPLEWND");
WNDCLASSEX wcx={0};
wcx.cbSize = sizeof(WNDCLASSEX);
wcx.lpfnWndProc = WndProc;
wcx.hInstance = hInst;
//Tu je to IDI_ICON1, chybu mi nevypisuje, ale ani mi ikonu nebere
wcx.hIcon = reinterpret_cast<HICON>(LoadImage(0,IDI_APPLICATION,
IDI_ICON1,0,0,LR_SHARED));
wcx.hCursor = reinterpret_cast<HCURSOR>(LoadImage(0,IDC_ARROW,
IMAGE_CURSOR,0,0,LR_SHARED));
wcx.hbrBackground = reinterpret_cast<HBRUSH>(COLOR_BTNFACE+1);
wcx.lpszClassName = classname.c_str();
//Tu je to menu, chybu nevypisuje ale nebere
wcx.lpszMenuName = “IDR_MENU1“;
if (!RegisterClassEx(&wcx))
{
ErrMsg(_T("Failed to register wnd class"));
return -1;
}
int desktopwidth=GetSystemMetrics(SM_CXSCREEN);
int desktopheight=GetSystemMetrics(SM_CYSCREEN);
HWND hwnd=CreateWindowEx(0,
classname.c_str(),
_T("KAZL"),
WS_OVERLAPPEDWINDOW,
desktopwidth/4, //position:left
desktopheight/4, //position: top
desktopwidth/2, //width
desktopheight/2, //height
0,
0,
hInst,
0);
if (!hwnd)
{
ErrMsg(_T("Failed to create wnd"));
return -1;
}
ShowWindow(hwnd,nCmd);
UpdateWindow(hwnd);
MSG msg;
while (GetMessage(&msg,0,0,0)>0)
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
return static_cast<int>(msg.wParam);
}
//=============================================================================
LRESULT CALLBACK WndProc(HWND hwnd,UINT uMsg,WPARAM wParam,LPARAM lParam)
{
switch (uMsg)
{
case WM_DESTROY:
PostQuitMessage(0);
return 0;
default:
return DefWindowProc(hwnd,uMsg,wParam,lParam);
}
}
//=============================================================================
inline int ErrMsg(const ustring& s)
{
return MessageBox(0,s.c_str(),_T("ERROR"),MB_OK|MB_ICONEXCLAMATION);
}
//=============================================================================
Kód: Vybrať všetko
//{{NO_DEPENDENCIES}}
// Microsoft Visual C++ generated include file.
// Used by Maybe.cpp.rc
//
#define IDR_MENU1 101
#define IDI_ICON1 102
#define ID_S40001 40001
#define ID_N40002 40002
// Next default values for new objects
//
#ifdef APSTUDIO_INVOKED
#ifndef APSTUDIO_READONLY_SYMBOLS
#define _APS_NEXT_RESOURCE_VALUE 103
#define _APS_NEXT_COMMAND_VALUE 40003
#define _APS_NEXT_CONTROL_VALUE 1001
#define _APS_NEXT_SYMED_VALUE 101
#endif
#endif
Ďakujem za odpoveď
//autoeditácia príspevku (09 Nov 2011, 17:31)
to naozaj mi nevie nikto pomôcť ?