Well first of all, hi, and thanks to all of you guys, cause this may be the first time I start a thread, but not the first time that one of you solve my problems. Anyway.
I'm following an internet tutorial about API development, ( http://www.winprog.org/tutorial/menus.html )
But rigth now im kind of stuck with this icon menu stuff.
this is my code:
main.cpp
#include <windows.h>
#include "resource.h"
#define ID_FILE_EXIT 9001
#define ID_STUFF_GO 9002
#define ID_RESTAR 2000
const char g_szClassName[] = "myWindowClass";
// Step 4: the Window Procedure
LRESULT CALLBACK WndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
{
switch(msg)
{
case WM_CREATE:
{
HMENU hMenu, hSubMenu;
HICON hIcon, hIconSm;
hMenu = CreateMenu();
hSubMenu = CreatePopupMenu();
AppendMenu(hMenu, MF_STRING | MF_POPUP, (UINT)hSubMenu, "&File"); //menus
AppendMenu(hSubMenu, MF_STRING, ID_FILE_EXIT, "E&xit");
hSubMenu = CreatePopupMenu();
AppendMenu(hMenu, MF_STRING | MF_POPUP, (UINT)hSubMenu, "Resta");
AppendMenu(hSubMenu, MF_STRING, ID_RESTAR, "Restar"); // menus
hSubMenu = CreatePopupMenu();
AppendMenu(hSubMenu, MF_STRING, ID_STUFF_GO, "&Go");
AppendMenu(hMenu, MF_STRING | MF_POPUP, (UINT)hSubMenu, "&Stuff"); //menus
SetMenu(hwnd, hMenu);
[B] hIcon = (HICON) LoadImage(NULL, "menu_two.ico", IMAGE_ICON, 32, 32, LR_LOADFROMFILE);
if(hIcon)
SendMessage(hwnd, WM_SETICON, ICON_BIG, (LPARAM)hIcon);
else
MessageBox(hwnd, "Could not load large icon!", "Error", MB_OK | MB_ICONERROR);
hIconSm = (HICON) LoadImage(NULL, "menu_two.ico", IMAGE_ICON, 16, 16, LR_LOADFROMFILE);
if(hIconSm)
SendMessage(hwnd, WM_SETICON, ICON_SMALL, (LPARAM)hIconSm);
else
MessageBox(hwnd, "Could not load small icon!", "Error", MB_OK | MB_ICONERROR[/B]);
}
break;
//codigo nuevo
case WM_LBUTTONDOWN:
{
char Nombredeprograma[MAX_PATH];
HINSTANCE hInstance = GetModuleHandle(NULL);
GetModuleFileName(hInstance, Nombredeprograma, MAX_PATH);
MessageBox(hwnd, Nombredeprograma, "This program is:", MB_OK | MB_ICONINFORMATION);
}
case WM_CLOSE:
DestroyWindow(hwnd);
break;
case WM_DESTROY:
PostQuitMessage(0);
break;
default:
return DefWindowProc(hwnd, msg, wParam, lParam);
}
return 0;
}
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance,
LPSTR lpCmdLine, int nCmdShow)
{
WNDCLASSEX wc;
HWND hwnd;
MSG Msg;
//Step 1: Registering the Window Class
wc.cbSize = sizeof(WNDCLASSEX);
wc.style = 0;
wc.lpfnWndProc = WndProc;
wc.cbClsExtra = 0;
wc.cbWndExtra = 0;
wc.hInstance = hInstance;
wc.hIcon = LoadIcon(GetModuleHandle(NULL), MAKEINTRESOURCE(Icono_principal));
wc.hCursor = LoadCursor(NULL, IDC_ARROW);
wc.hbrBackground = (HBRUSH)(COLOR_WINDOW+1);
wc.lpszMenuName = MAKEINTRESOURCE(IDR_MYMENU);
wc.lpszClassName = g_szClassName;
wc.hIconSm = (HICON)LoadImage(GetModuleHandle(NULL), MAKEINTRESOURCE(Icono_principal), IMAGE_ICON, 16, 16, 0);
if(!RegisterClassEx(&wc))
{
MessageBox(NULL, "Window Registration Failed!", "Error!",
MB_ICONEXCLAMATION | MB_OK);
return 0;
}
// Step 2: Creating the Window
hwnd = CreateWindowEx(
WS_EX_CLIENTEDGE,
g_szClassName,
"The title of my window",
WS_OVERLAPPEDWINDOW,
CW_USEDEFAULT, CW_USEDEFAULT, 500, 200,
NULL, NULL, hInstance, NULL);
if(hwnd == NULL)
{
MessageBox(NULL, "Window Creation Failed!", "Error!",
MB_ICONEXCLAMATION | MB_OK);
return 0;
}
ShowWindow(hwnd, nCmdShow);
UpdateWindow(hwnd);
// Step 3: The Message Loop
while(GetMessage(&Msg, NULL, 0, 0) > 0)
{
TranslateMessage(&Msg);
DispatchMessage(&Msg);
}
return Msg.wParam;
}
resource.h
#define IDR_MYMENU 101
#define Icono_principal 201
#define ID_FILE_EXIT 9001
#define ID_STUFF_GO 9002
#define RESTAR 2000
#include "resource.h"
IDR_MYMENU MENU
{
POPUP "&SUMA" {
MENUITEM "E&xit", ID_FILE_EXIT
}
POPUP "&MULTIPLICACION" {
MENUITEM "&Go", ID_STUFF_GO
MENUITEM "G&o somewhere else", 0, GRAYED
}
POPUP "&RESTA" {
MENUITEM "Re&star", RESTAR
}
}
Icono_principal ICON "Icono-calcu.ico"
The thing its that i cant load the icon, it compiles, but pops up the error message.
Theres some things I've changed for my personal usage, and i don't know if that's what "brings down" the program.
P.D. I'm not using this "menu_two.ico" i'm trying to use my own one ( called resta-icono.ico ) but i put that one for reference ( non of them loads )
Last but not least... sorry for the bad English, as you may note, i'm not american, i'm from mexico, so merely that's why it's hard to learn about this, every guide or tut it's in english jeje.
But i'll keep trying.
( I'm using wxDev-C++ )