Zdravim,
mám tu jeden problém s oknem, které jsem vytvořil, mám tam menu nabídku, ale ta na nic nereaguje...normálně se i rozbalí, ale nereaguje.
Když tam mám třeba "File" a pod ním "Exit" a kliknu na "Exit", tak se nic nestane, přestože by se okno mělo zavřít.
Předem díky za pomoc :)
xxx.rc soubor:
// Microsoft Visual C++ generated resource script.
//
#include "resource.h"
#define APSTUDIO_READONLY_SYMBOLS
/////////////////////////////////////////////////////////////////////////////
//
// Generated from the TEXTINCLUDE 2 resource.
//
#include "afxres.h"
/////////////////////////////////////////////////////////////////////////////
#undef APSTUDIO_READONLY_SYMBOLS
/////////////////////////////////////////////////////////////////////////////
// Czech (Czech Republic) resources
#if !defined(AFX_RESOURCE_DLL) || defined(AFX_TARG_CSY)
LANGUAGE LANG_CZECH, SUBLANG_DEFAULT
#ifdef APSTUDIO_INVOKED
/////////////////////////////////////////////////////////////////////////////
//
// TEXTINCLUDE
//
1 TEXTINCLUDE
BEGIN
"resource.h�"
END
2 TEXTINCLUDE
BEGIN
"#include ""afxres.h""\r\n"
"�"
END
3 TEXTINCLUDE
BEGIN
"\r\n"
"�"
END
#endif // APSTUDIO_INVOKED
/////////////////////////////////////////////////////////////////////////////
//
// Menu
//
MAINMENU MENU
BEGIN
POPUP "&File"
BEGIN
MENUITEM "Exit" IDM_EXIT
END
END
/////////////////////////////////////////////////////////////////////////////
//
// Icon
//
// Icon with lowest ID value placed first to ensure application icon
// remains consistent on all systems.
IDI_ICON1 ICON "icon1.ico"
IDI_ICON2 ICON "icon2.ico"
#endif // Czech (Czech Republic) resources
/////////////////////////////////////////////////////////////////////////////
#ifndef APSTUDIO_INVOKED
/////////////////////////////////////////////////////////////////////////////
//
// Generated from the TEXTINCLUDE 3 resource.
//
/////////////////////////////////////////////////////////////////////////////
#endif // not APSTUDIO_INVOKED
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
resource.h:
//{{NO_DEPENDENCIES}}
// Microsoft Visual C++ generated include file.
// Used by Win32 Launcher.rc
//
#define MAINMENU 101
#define IDI_ICON1 102
#define IDI_ICON2 103
#define IDM_EXIT 4001
// Next default values for new objects
//
#ifdef APSTUDIO_INVOKED
#ifndef APSTUDIO_READONLY_SYMBOLS
#define _APS_NEXT_RESOURCE_VALUE 104
#define _APS_NEXT_COMMAND_VALUE 40002
#define _APS_NEXT_CONTROL_VALUE 1001
#define _APS_NEXT_SYMED_VALUE 101
#endif
#endif
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Zdroják:
#include <windows.h>
#include "resource.h"
LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM);
/*----------------------------------------------------------------------------------------------*/
///
/// Hlavní funkce okna
///
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, PSTR szCmdLine, int iCmdShow)
{
TCHAR CLASS_NAME[] = TEXT("Titulek");
WNDCLASSEX wc = { };
wc.cbSize = sizeof(wc);
wc.style = CS_HREDRAW | CS_VREDRAW;
wc.lpfnWndProc = WndProc;
wc.lpszClassName = CLASS_NAME;
wc.cbClsExtra = 0;
wc.cbWndExtra = 0;
wc.hInstance = hInstance;
wc.hIcon = LoadIcon(hInstance, MAKEINTRESOURCE("icon1.ico"));
wc.hIconSm = LoadIcon(hInstance, MAKEINTRESOURCE("icon2.ico"));
wc.hCursor = (HCURSOR)LoadCursor(NULL, IDC_ARROW);
wc.hbrBackground = (HBRUSH)(COLOR_WINDOW+1);
wc.lpszMenuName = MAKEINTRESOURCE(MAINMENU);
/*----------------------------------------------------------------------------------------------*/
///
/// Vzhled okna
///
RegisterClassEx(&wc);
HWND hwnd = CreateWindowEx
(
NULL,
CLASS_NAME, //(přebírá) název třídy okna
CLASS_NAME,
WS_OVERLAPPED | WS_SYSMENU,
640, //pozice okna v ose x
300, //pozice okna v ose y
640, //Velikost okna v ose x
480, //velikost okna v ose y
NULL,
NULL,
hInstance,
NULL);
/*----------------------------------------------------------------------------------------------*/
///
/// Funkce vykreslení okna
///
ShowWindow(hwnd, iCmdShow);
UpdateWindow(hwnd);
MSG msg;
while(GetMessage(&msg, NULL, 0, 0))
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
return msg.wParam;
}
/*----------------------------------------------------------------------------------------------*/
///
/// Funkčnost okna
///
LRESULT CALLBACK WndProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
{
/*----------------------------------------------------------------------------------------------*/
PAINTSTRUCT ps;
HDC hdc;
TCHAR greeting[] = TEXT("Hello, World!"); // Deklarace a inicializace textu
TCHAR Prom[] = TEXT("Ahoj"); // Deklarace a inicializace textu
/*----------------------------------------------------------------------------------------------*/
switch(uMsg)
{
case WM_DESTROY:
{PostQuitMessage(0);}
return 0;
/*---------------------------------------------------------------------------------------------------------------------------*/
/*----------------------------------------------------------------------------------------------*/// Vnitřek fce switch
case WM_PAINT:
hdc = BeginPaint(hwnd, &ps);
TextOut /////////////////////// Text Hello, World!
(
hdc,
5, //////// Pozice textu osa x
20, //////// Pozice textu osa y
greeting,
strlen (greeting)
);
TextOut /////////////////////// Text Ahoj
(
hdc,
5, //////// Pozice textu osa x
5, //////// Pozice textu osa y
Prom,
strlen (Prom)
);
EndPaint(hwnd, &ps);
return 0;
/*----------------------------------------------------------------------------------------------*/
case WM_CLOSE:
{
if(MessageBox(hwnd, TEXT("Are You sure, You want to Exit?"), TEXT("Exit"), MB_YESNO | MB_ICONQUESTION) == IDYES)
DestroyWindow(hwnd);
}
return 0;
/*----------------------------------------------------------------------------------------------*/
case IDM_EXIT:
{
DestroyWindow(hwnd); //////// CHYBA ZDE ///////////
}
return 0;
/*---------------------------------------------------------------------------------------------------------------------------*//// Konec Vnitřku fce switch
/*---------------------------------------------------------------------------------------------------------------------------*/
} //Switch Brace
/*---------------------------------------------------------------------------------------------------------------------------*/
/*---------------------------------------------------------------------------------------------------------------------------*/
return DefWindowProc(hwnd, uMsg, wParam, lParam);
}