You're not?
I did a seperate project that has a blank window and a button.
Code:
#include <windows.h>
#include <map>
#include <iostream>
#include <string>
typedef LRESULT (MessageCallbackPtr)(WPARAM, LPARAM);
std::map<int, MessageCallbackPtr*> mCallback;
const char g_szClassName[] = "myWindowClass";
LRESULT MyClickHandler(WPARAM wParam, LPARAM lParam)
{
MessageBox(NULL, "Got it", "Click!", MB_OK);
}
// Step 4: the Window Procedure
LRESULT CALLBACK WndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
{
switch(msg)
{
case WM_CLOSE:
DestroyWindow(hwnd);
break;
case WM_DESTROY:
PostQuitMessage(0);
break;
case WM_COMMAND:
{
std::iterator<int, MessageCallbackPtr *> iFunction;
iFunction = mCallback.find(msg);
if ( iFunction != mCallback.end() )
return iFunction->second(wParam, lParam);
}
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, hWndButton;
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(NULL, IDI_APPLICATION);
wc.hCursor = LoadCursor(NULL, IDC_ARROW);
wc.hbrBackground = (HBRUSH)(COLOR_WINDOW+1);
wc.lpszMenuName = NULL;
wc.lpszClassName = g_szClassName;
wc.hIconSm = LoadIcon(NULL, IDI_APPLICATION);
if(!RegisterClassEx(&wc)) {
return 0;
}
// Step 2: Creating the Window
hwnd = CreateWindowEx(WS_EX_CLIENTEDGE, g_szClassName,
"Win32 Practice",WS_OVERLAPPEDWINDOW,
CW_USEDEFAULT, CW_USEDEFAULT, 800, 600,
NULL, NULL, hInstance, NULL);
if(hwnd == NULL) {
return 0;
}
hWndButton = CreateWindowEx(NULL, "button", "Click Me",
WS_CHILD | WS_VISIBLE | BS_PUSHBUTTON, 50, 50, 100, 24, hwnd,
(HMENU)(100), hInstance, NULL);
if (hWndButton == NULL)
return false;
mCallback[WM_LBUTTONDOWN] = &MyClickHandler;
ShowWindow(hwnd, nCmdShow);
UpdateWindow(hwnd);
// Step 3: The Message Loop
while(GetMessage(&Msg, NULL, 0, 0) > 0)
{
TranslateMessage(&Msg);
DispatchMessage(&Msg);
}
return (int) Msg.wParam;
}
Errors:
Code:
Compiling...
winmain.cpp
c:\Documents and Settings\Phil\My Documents\Visual Studio Projects\Win32 Practice\winmain.cpp(32) : error C2679: binary '=' : no operator found which takes a right-hand operand of type 'std::_Tree<_Traits>::iterator' (or there is no acceptable conversion)
with
[
_Traits=std::_Tmap_traits<int,__w64 long (__cdecl *),std::less<int>,std::allocator<std::pair<const int,__w64 long (__cdecl *)>>,false>
]
c:\Documents and Settings\Phil\My Documents\Visual Studio Projects\Win32 Practice\winmain.cpp(33) : error C2678: binary '!=' : no operator found which takes a left-hand operand of type 'std::iterator<_Category,_Ty>' (or there is no acceptable conversion)
with
[
_Category=int,
_Ty=MessageCallbackPtr (__cdecl *)
]
c:\Documents and Settings\Phil\My Documents\Visual Studio Projects\Win32 Practice\winmain.cpp(34) : error C2819: type 'std::iterator<_Category,_Ty>' does not have an overloaded member 'operator ->'
with
[
_Category=int,
_Ty=MessageCallbackPtr (__cdecl *)
]
did you intend to use '.' instead?
c:\Documents and Settings\Phil\My Documents\Visual Studio Projects\Win32 Practice\winmain.cpp(34) : error C2227: left of '->second' must point to class/struct/union
type is 'std::iterator<_Category,_Ty>'
with
[
_Category=int,
_Ty=MessageCallbackPtr (__cdecl *)
]
did you intend to use '.' instead?
Build log was saved at "file://c:\Documents and Settings\Phil\My Documents\Visual Studio Projects\Win32 Practice\Debug\BuildLog.htm"
Win32 Practice - 4 error(s), 0 warning(s)