Hi.
I just now began working on graphic editor. I wanted to add menu but.. it is invisible and I don't know why. My code:
/* resources.h */
#define IDR_MENU1 101
#define ID_QUIT 40001
/* resources.rc */
#include "resources.h"
IDR_MENU1 MENU DISCARDABLE
BEGIN
POPUP "&File"
BEGIN
MENUITEM "QUIT", ID_QUIT
END
END // maybe this is wrong
/* main.cpp */
#define CLASS_NAME "ClassName"
#define TITLE "Window title"
HWND hMainWnd = NULL;
HMENU hMainMenu = NULL;
HINSTANCE hMainInst = NULL;
int iWndWidth;
int iWndHeight;
LRESULT CALLBACK WndProc(HWND hWnd, UINT Msg, WPARAM wParam, LPARAM lParam)
{
PAINTSTRUCT ps;
switch (Msg)
{
case WM_PAINT:
{
BeginPaint(hMainWnd,&ps);
EndPaint(hMainWnd,&ps);
} break;
case WM_CLOSE:
case WM_DESTROY: PostQuitMessage(0); break;
}
return DefWindowProc(hWnd,Msg,wParam,lParam);
}
bool InitMainWnd(int width, int height)
{
WNDCLASS wc;
wc.style = CS_VREDRAW|CS_HREDRAW;
wc.cbClsExtra = 0;
wc.cbWndExtra = 0;
wc.lpfnWndProc = (WNDPROC)WndProc;
wc.lpszClassName = CLASS_NAME;
wc.lpszMenuName = NULL;
wc.hInstance = (HINSTANCE)hMainInst;
wc.hIcon = (HICON)LoadIcon(NULL,IDI_APPLICATION);
wc.hCursor = (HCURSOR)LoadCursor(NULL,IDC_ARROW);
wc.hbrBackground = (HBRUSH)GetStockObject(BLACK_BRUSH);
if (!RegisterClass(&wc))
{
MessageBox(hMainWnd,"RegisterClass(&wc) ERROR",TITLE,MB_OK|MB_ICONERROR);
return false;
}
hMainMenu = LoadMenu((HINSTANCE)hMainInst,MAKEINTRESOURCE(IDR_MENU1));
iWndWidth = width;
iWndHeight = height;
hMainWnd = CreateWindow(CLASS_NAME,TITLE,WS_OVERLAPPEDWINDOW,0,0,iWndWidth, iWndHeight,NULL,hMainMenu,hMainInst,NULL);
if (hMainWnd == false)
{
MessageBox(hMainWnd,"CreateWindow() ERROR",TITLE,MB_OK|MB_ICONERROR);
return false;
}
DoneMainWnd();
return true;
}
void DoneMainWnd()
{
if (hMainMenu != NULL) DestroyMenu(hMainMenu);
UnregisterClass(CLASS_NAME,hMainInst);
}
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE, LPSTR, int)
{
hMainInst = hInstance;
if (InitMainWnd(640,480) == false) return 0;
ShowWindow(hMainWnd,SW_SHOW);
UpdateWindow(hMainWnd);
MSG msg;
ZeroMemory(&msg,sizeof(MSG));
PeekMessage(&msg,NULL,0,0,PM_REMOVE);
while (1)
{
if ((msg.message == WM_QUIT) || (msg.wParam == VK_ESCAPE)) break;
if (PeekMessage(&msg,NULL,0,0,PM_REMOVE))
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
else
{
}
}
return msg.wParam;
}
I am using Dev-C++. Please, help.
[Edited by - RiBi on October 24, 2004 11:26:40 AM]