I believe this is the part that builds the items on the menu bar. I am actually a little confused as to why the tutorial mentions to define the items in a header file with numbers then create this resource file so it would help if someone could explain that too. Maybe it will help if I add the other two files.
resource.h file
Code:
#define IDR_MENU 101
#define IDI_ICON 201
#define ID_FILE_EXIT 9001
#define ID_STUFF_GO 9002
Window.cpp file
Code:
#include <Windows.h>
#include "resource.h"
const char window[] = "myWindow";
LRESULT CALLBACK WndProc(HWND winHandle, UINT msg, WPARAM wParam, LPARAM lParam){
switch (msg){
case WM_LBUTTONDOWN:
MessageBox(winHandle, "Surpise", "Secret Window", MB_OK | MB_ICONINFORMATION);
break;
case WM_CLOSE:
DestroyWindow(winHandle);
break;
case WM_DESTROY:
PostQuitMessage(0);
break;
default:
return DefWindowProc(winHandle, msg, wParam, lParam);
}
return 0;
}
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow){
WNDCLASSEX wnd;
HWND winHandle;
MSG Msg;
wnd.cbSize = sizeof(WNDCLASSEX);
wnd.style = 0;
wnd.lpfnWndProc = WndProc;
wnd.cbClsExtra = 0;
wnd.cbWndExtra = 0;
wnd.hInstance = hInstance;
wnd.hIcon = LoadIcon(NULL, IDI_SHIELD);
wnd.hCursor = LoadCursor(NULL, IDC_HAND);
//wnd.hbrBackground = (HBRUSH)(COLOR_WINDOW + 1);
wnd.hbrBackground = (HBRUSH)(COLOR_BTNSHADOW + 1);
wnd.lpszMenuName = NULL;
wnd.lpszClassName = window;
wnd.hIconSm = LoadIcon(NULL, IDI_QUESTION);
wnd.lpszMenuName = MAKEINTRESOURCE(IDR_MENU);
wnd.hIcon = LoadIcon(GetModuleHandle(NULL), MAKEINTRESOURCE(IDI_ICON));
wnd.hIconSm = (HICON)LoadImage(GetModuleHandle(NULL), MAKEINTRESOURCE(IDI_ICON), IMAGE_ICON, 16, 16, 0);
if (!RegisterClassEx(&wnd)){
MessageBox(NULL, "Window Registration Failed!", "Error!", MB_ICONEXCLAMATION | MB_OK);
return 0;
}
winHandle = CreateWindowEx(
WS_EX_CLIENTEDGE,
window,
"WindBag",
WS_OVERLAPPEDWINDOW,
CW_USEDEFAULT, CW_USEDEFAULT, 720, 360,
NULL, NULL, hInstance, NULL
);
if (winHandle == NULL){
MessageBox(NULL, "Window Creation Failed!", "Error!", MB_ICONEXCLAMATION | MB_OK);
return 0;
}
ShowWindow(winHandle, nCmdShow);
UpdateWindow(winHandle);
while (GetMessage(&Msg, NULL, 0, 0) > 0){
TranslateMessage(&Msg);
DispatchMessage(&Msg);
}
return Msg.wParam;
}