Win32 API - problém

Programovacie jazyky, rady, poradňa...
CepepeH
Novice
Novice
Príspevky: 5
Registrovaný: 08 nov 2011, 17:42

Win32 API - problém

Príspevok od používateľa CepepeH »

Ahojte hojkáči,
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);
}
//=============================================================================

a tu je resource.h

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
Čo robím zle resp. ak robím zle všetko, ako creatnuť do C++ aplikácie menu a ikonu?

Ďakujem za odpoveď :D

//autoeditácia príspevku (09 Nov 2011, 17:31)
to naozaj mi nevie nikto pomôcť ? :(
BX
Addict
Addict
Používateľov profilový obrázok
Príspevky: 4572
Registrovaný: 10 jan 2008, 15:30

Re: Win32 API - problém

Príspevok od používateľa BX »

Keby si aspoň napísal, čo presne by si mal robiť zle, alebo o čo ti vlastne ide...
Ako sa to robí máš ale dobre popísané tu http://programujte.com/clanek/200602140 ... -resource/
CepepeH
Novice
Novice
Príspevky: 5
Registrovaný: 08 nov 2011, 17:42

Re: Win32 API - problém

Príspevok od používateľa CepepeH »

ved ja som robil podla toho, ale nejak mi to nejde.
P.S. v kode to mas, sry ze som to nenapisal aj hore, takze este raz, ja som to riesil takto:

Kód: Vybrať všetko

//Tu je to IDI_ICON1, chybu mi nevypisuje, ale ani mi ikonu PRI DEBUGU nebere
wcx.hIcon         = reinterpret_cast<HICON>(LoadImage(0,IDI_APPLICATION,
                                            IDI_ICON1,0,0,LR_SHARED));
a

Kód: Vybrať všetko

//Tu je to menu, chybu nevypisuje ale nebere
wcx.lpszMenuName = “IDR_MENU1“;
V resource.h to mám automaticky vygenerované VS - kom takto

Kód: Vybrať všetko

#define IDR_MENU1                       101
#define IDI_ICON1                       102
Otázka znie: Prečo mi to nebere? (ani mi to žiadnu chybu ani upozornenie nevypisuje aby som sa mal od čoho odraziť)

//autoeditácia príspevku (09 Nov 2011, 17:48)
este by som mozno dodal strukturu suborov
//obrazky vkladaj do prilohy
Napísať odpoveď