I have created menu in application by add> resourse>menu> New...
I am getting error as Fail to create menu bar,Please tell where this code goes wrong. Code as follows
#include
<windows.h>#include
<aygshell.h>#include
"resource.h"#include
"commctrl.h"LRESULT CALLBACK MainWndProc(HWND, UINT, WPARAM, LPARAM);
HINSTANCE ghInstance;
LRESULT CALLBACK MainWndProc(HWND hwnd, UINT wMsg, WPARAM wParam, LPARAM lParam)
{
HDC hdc ;
PAINTSTRUCT ps ;
RECT rect ;
SHMENUBARINFO smbi;
// static const TCHAR szTitle[]=TEXT(¡°Hello¡±); static const TCHAR szTitle[] = TEXT("Hello"); switch (wMsg){
case WM_CREATE:memset(&smbi,0,
sizeof(SHMENUBARINFO));smbi.cbSize=
sizeof(SHMENUBARINFO);smbi.hwndParent=hwnd;
//smbi.dwFlags=SHCMBF_EMPTYBAR;smbi.nToolBarId=IDR_MENU1;
smbi.hInstRes=
/*(HINSTANCE)((LPCREATESTRUCT)lParam)->*/ghInstance;smbi.nBmpId=0;
smbi.cBmpImages=0;
//smbi.hwndMB=0; // to Createmenubar if(SHCreateMenuBar(&smbi)==FALSE){
MessageBox(hwnd,TEXT(
"Fail To Create Menu Bar"),TEXT("Error"),MB_OK);DestroyWindow(hwnd);
}
return 0 ; case WM_PAINT:hdc = BeginPaint (hwnd, &ps) ;
GetClientRect(hwnd, &rect) ;
SetBkColor(hdc,RGB(0,255,0));
DrawText(hdc,szTitle, -1, &rect,DT_SINGLELINE | DT_CENTER | DT_VCENTER) ;
EndPaint(hwnd,&ps) ;
return 0 ; case WM_DESTROY:PostQuitMessage (0) ;
return 0 ;}
return DefWindowProc (hwnd, wMsg, wParam, lParam) ;}
int
WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance,LPTSTR szCmdLine, int iCmdShow){
HWND hwnd ;
MSG msg ;
WNDCLASS wndclass ;
ghInstance = hInstance;
wndclass.style = CS_HREDRAW | CS_VREDRAW ;
wndclass.lpfnWndProc = MainWndProc;
wndclass.cbClsExtra = 0 ;
wndclass.cbWndExtra = 0 ;
wndclass.hInstance = hInstance ;
wndclass.hIcon =NULL ;
wndclass.hCursor = LoadCursor (NULL, IDC_ARROW) ;
wndclass.hbrBackground = (HBRUSH) GetStockObject (WHITE_BRUSH) ;
wndclass.lpszMenuName = NULL ;
wndclass.lpszClassName = TEXT(
"Hello"); if (!RegisterClass (&wndclass)){
// MessageBox (NULL, TEXT (¡°This program requires Windows NT!¡±),szAppName, MB_ICONERROR); return 0 ;}
hwnd=CreateWindow(TEXT(
"hELLO"),TEXT("hello"),WS_VISIBLE|WS_CAPTION/*|WS_SYSMENU*/,CW_USEDEFAULT,CW_USEDEFAULT,CW_USEDEFAULT,CW_USEDEFAULT,NULL,NULL,hInstance,NULL);ShowWindow (hwnd, iCmdShow) ;
UpdateWindow (hwnd) ;
ghInstance=ghInstance;
/*// To hide windowiCmdShow=SW_HIDE;
ShowWindow (hwnd, iCmdShow) ;
*/
while(GetMessage(&msg,NULL,0,0)){
TranslateMessage(&msg);
DispatchMessage(&msg);
}
return msg.wParam;}