Problem calling a function with DialogBox 4th argument

So,hello there, my first post here.

So, i've got a problem, that is, i've packaged my code into a class. Main() looks like this -

int APIENTRY _tWinMain(HINSTANCE hInstance,HINSTANCE hPrevInstance,LPTSTR lpCmdLine, int nCmdShow){

WindowStructure tWindow;

tWindow.Init(&hInstance);
tWindow.InitializeWindow();
return 0;
}

And in InitializeWindow i have -

int WindowStructure::InitializeWindow(){
::DialogBoxA(*hInstance,MAKEINTRESOURCEA(IDD_DIALOG1),NULL,WndProc);

return 1;
}

WndProc is a funtion defined as being contained in the class, that is

class WindowStructure{
public::
INT_PTR CALLBACK WndProc();
};

However, i can't get that to work.
When i build it i get this -

'WindowStructure::WndProc': function call missing argument list; use '&WindowStructure::WndProc' to create a pointer to member

So, i use &WindowStructure::WndProc, and that's what i see:

error C2664: 'DialogBoxParamA' : cannot convert parameter 4 from 'INT_PTR (__stdcall WindowStructure::* )(HWND,UINT,WPARAM,LPARAM)' to 'DLGPROC'

So, i set it to return DLGPROC;

And that's where it all goes to hell, as i don't know what to do. As the WndProc (the message loop) returns INT_PTR - TRUE, so i created a DLGPROC object, and returned it. The same error c2664, only with DLGPROC instead of INT_PTR.

So, what i shall do to make it work?



Last edited on
iirc, DLGPROC returns BOOL, not INT_PTR. Additionally, you never call DefWindowProc from your dialog proc (if you do, you'll screw a lot of stuff up). Instead, you're supposed to return true if you did something with the message and false if you didn't (in which case the default handling kicks in)

It's been a while since I've done any of this, though, so I might be fuzzy on the details. Try searching MSDN for DLGPROC or DialogProc and see what it says about it.
You need to declare your WndProc as static if it's a class member.
I don't really understand what you're talking about, Disch. Could you explain in better detail?

Hammurabi: So, i declared it as a static. And it works. However, it 'disconnects' the function from the class. The result is, i have to declare EVERYTHING as static there. Every single variable, every single object and every single function that's contained in the class i have to declare as static.

Granted, i don't really understand the static as for now, i'm still learning c/c++, but why it forces me to declare everything as static? And is there a way to bypass this? The 'readability' of code is somewhat compromised when i have a large block of variable declarations at the beginning of the WindowStructure.cpp. It just looks bad.
However, it 'disconnects' the function from the class. The result is, i have to declare EVERYTHING as static there.


I don't understand. You certainly don't have to make everything static. You'll have to post your code.
So, here's my code. I cut off practically everything that's of no use -

main.cpp -
//-------------------------------------------------
//standard windows.h nd such includes

#include "WindowStructure.hpp"

int APIENTRY _tWinMain(HINSTANCE hInstance,HINSTANCE hPrevInstance,LPTSTR lpCmdLine, int nCmdShow){


WindowStructure tWindow;

tWindow.Init(&hInstance);
tWindow.InitializeWindow();

return 0;
}


//-------------------------------------------------
//WindowStructure.hpp

class WindowStructure
{
public:
WindowStructure();
~WindowStructure();
int Init(HINSTANCE*);
int InitializeWindow();
static int prepareVariables();

static int openFile(int);
static int openBitmap();
static int refreshPictureControl();
static int convertCToArray();
static int saveMap();
static int getNewScrollInformation();
static int captureMouseClick();


static INT_PTR CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM);
static INT_PTR CALLBACK About(HWND, UINT, WPARAM, LPARAM);


private:

static HINSTANCE *hInstance;

static HINSTANCE hInst;
static HWND windowHandle;
TCHAR szTitle[MAX_LOADSTRING];
TCHAR szWindowClass[MAX_LOADSTRING];

static char filePathName[MAX_PATH+1];

static MapStructure *itsMap;

static bool isPictureOpen;
static bool isHOpen;
static bool isMapOpen;

static int verticalOffset, horizontalOffset; // Picture-in-a-box offset to copy from source to piccontrol
static int maxVerticalOffset, maxHorizontalOffset; // Maximum offset that can be used to copy from source to piccontrol
static int pictureControlWidth, pictureControlHeight; // self-explanatory
static int pictureControlX, pictureControlY; // containst the location of the picture relative to the window
static int mouseClickX,mouseClickY; //self-explanatory.
static int relativeMouseClickX,relativeMouseClickY; // mouse click translated to the relative point in the picture
static int chosenChipsetX,chosenChipsetY; // chosen chipset when clicked in the picture;l\

static HBITMAP originalBitmap;
static HBITMAP collisionBitmap;
static HBITMAP eventBitmap;
static int originalBitmapWidth, originalBitmapHeight; // self-explanatory
static char pictureFilePathName[MAX_PATH + 1]; //self-explanatory

static bool showCheck;
static bool showCollision;
static bool showEvent;

};

//-------------------------------------------------

//WindowStructure.cpp

HINSTANCE* WindowStructure::hInstance = (HINSTANCE*)0;
HINSTANCE WindowStructure::hInst = (HINSTANCE)0;
TCHAR WindowStructure::filePathName[MAX_PATH+1] = {0};
HWND WindowStructure::windowHandle;
TCHAR WindowStructure::pictureFilePathName[MAX_PATH + 1] = {0};
HBITMAP WindowStructure::originalBitmap;
HBITMAP WindowStructure::collisionBitmap;
HBITMAP WindowStructure::eventBitmap;
bool WindowStructure::isPictureOpen = false, WindowStructure::isHOpen = false, WindowStructure::isMapOpen = false;
MapStructure* WindowStructure::itsMap = NULL;
int WindowStructure::verticalOffset = 0, WindowStructure::horizontalOffset = 0;
int WindowStructure::pictureControlWidth = 0, WindowStructure::pictureControlHeight = 0;
int WindowStructure::maxVerticalOffset = 0, WindowStructure::maxHorizontalOffset = 0;
int WindowStructure::pictureControlX = 0, WindowStructure::pictureControlY = 0;
int WindowStructure::mouseClickX = 0, WindowStructure::mouseClickY = 0;
int WindowStructure::relativeMouseClickX = 0,WindowStructure::relativeMouseClickY = 0;
bool WindowStructure::showCheck = false, WindowStructure::showEvent = false, WindowStructure::showCollision = false;
int WindowStructure::chosenChipsetX=0,WindowStructure::chosenChipsetY=0;

//I won't copy all the functions. Only a few chosen. I guess you have the sight on this, Hammurabi.

int WindowStructure::InitializeWindow(){
::DialogBoxA(*hInstance,MAKEINTRESOURCEA(IDD_DIALOG1),NULL,WndProc);
return 1;
}

int WindowStructure::captureMouseClick(){
POINT mouseClickPoint;


if(GetCursorPos(&mouseClickPoint)){
ScreenToClient(windowHandle,&mouseClickPoint);
mouseClickX = mouseClickPoint.x;
mouseClickY = mouseClickPoint.y;

bool isInRangeX = false,isInRangeY = false;

if(mouseClickX > pictureControlX && mouseClickX < pictureControlX + pictureControlWidth){
isInRangeX = true;
relativeMouseClickX = mouseClickX - pictureControlX + horizontalOffset;
}
if(mouseClickY > pictureControlY && mouseClickY < pictureControlY + pictureControlHeight){
isInRangeY = true;
relativeMouseClickY = mouseClickY - pictureControlY + verticalOffset;
}

if(isInRangeX && isInRangeY){
chosenChipsetX = (relativeMouseClickX - relativeMouseClickX%32)/32;
chosenChipsetY = (relativeMouseClickY - relativeMouseClickY%32)/32;

}


}
return 1;
}

//-------------------------------------------------

Here's what's going on when i'm declaring something as non-static. I un-staticked the relativemouseclickY in the captureMouseClick above -
Two errors pops that says : "

error C2597: illegal reference to non-static member 'WindowStructure::relativeMouseClickY'
error C3867: 'WindowStructure::relativeMouseClickY': function call missing argument list; use '&WindowStructure::relativeMouseClickY' to create a pointer to member


So, i don't have the foggiest idea what's going on. I can submit the whole project if requested. Nothing important, really, something i'm writing to learn WinAPI
Last edited on
Toooo much code. Here's an example that shows you don't have to make everything static.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
// main.cpp ----------------------------------------------------------

#include <windows.h>
#include "WindowStructure.hpp"

int APIENTRY
WinMain(
    HINSTANCE hInst,
    HINSTANCE unused,
    LPTSTR    cmd,
    int       show
){
    WindowStructure wnd( hInst );
    return wnd.Run();
}


// WindowStructure.hpp ----------------------------------------------

#include <windows.h>
#include "resources.h"

class WindowStructure
{
public:
    WindowStructure( HINSTANCE );
    int Run();
    static BOOL CALLBACK WndProc( HWND, UINT, WPARAM, LPARAM );
private:
    HINSTANCE hInst;
};


// WindowStructure.cpp ----------------------------------------------

#include "WindowStructure.hpp"

WindowStructure::WindowStructure( HINSTANCE hInst_ )
    : hInst( hInst_ )
{
}

int WindowStructure::Run()
{
    ::DialogBox( hInst, MAKEINTRESOURCEA(IDD_DIALOG1), NULL, WndProc);
    return 0;
}

BOOL CALLBACK
WindowStructure::WndProc( HWND hwnd, UINT msg, WPARAM wp, LPARAM lp )
{
    switch( msg ){
    case WM_INITDIALOG:
        return TRUE;
    case WM_COMMAND:
        switch( LOWORD( wp )){
        case IDCANCEL:
        case IDOK:
            EndDialog( hwnd, wp );
            return TRUE;
        }
    }
    return FALSE;
}

Last edited on
Ok, i figured that one out, thanks to you, Hammurabi.
I've made a static pointer to the object, then i just used the pointer within the static function.
And i think i've learned something new today.
Topic archived. No new replies allowed.