-
December 30th, 2013, 03:01 PM
#61
Re: [win32] - creating controls using class's
Originally Posted by Paul McKenzie
Hopefully you're not expecting someone to figure out where lines 4, 45, 77, and 78 are.
Please tell us where these lines are in the code you posted.
Regards,
Paul McKenzie
sorry...
4: #define event(eventname, ... ) std::function<void(__VA_ARGS__ )> eventname
(with includes files)
45: inst->Move(xPos,yPos);//why these line make my program, give me an error for get support?
(inside the window procedure)
77: event(Create,(int x, int y));
78: event(Move,(int x, int y));
(in public variables)
Last edited by Cambalinho; December 30th, 2013 at 03:04 PM.
-
December 30th, 2013, 03:04 PM
#62
Re: [win32] - creating controls using class's
Originally Posted by Cambalinho
label *inst = (label*)GetProp(GetParent(hwnd), labelclassprop);
You failed to check the return value of GetProp. If that property is not found, the return value is NULL. If that function returned a NULL, then inst is NULL.
http://msdn.microsoft.com/en-us/libr...=vs.85%29.aspx
If "inst" is not NULL, then debug into the Move() function. Can you do that? If you can, where does the debugger take you? Does it actually go into a function, or does the debugger take you to some weird address that makes no sense? If it is the latter, this means that inst->Move points to garbage.
Regards,
Paul McKenzie
-
December 30th, 2013, 03:08 PM
#63
Re: [win32] - creating controls using class's
Where's the declaration/definition of move()?
All advice is offered in good faith only. All my code is tested (unless stated explicitly otherwise) with the latest version of Microsoft Visual Studio (using the supported features of the latest standard) and is offered as examples only - not as production quality. I cannot offer advice regarding any other c/c++ compiler/IDE or incompatibilities with VS. You are ultimately responsible for the effects of your programs and the integrity of the machines they run on. Anything I post, code snippets, advice, etc is licensed as Public Domain https://creativecommons.org/publicdomain/zero/1.0/ and can be used without reference or acknowledgement. Also note that I only provide advice and guidance via the forums - and not via private messages!
C++23 Compiler: Microsoft VS2022 (17.6.5)
-
December 30th, 2013, 03:09 PM
#64
Re: [win32] - creating controls using class's
Originally Posted by Paul McKenzie
You failed to check the return value of GetProp. If that property is not found, the return value is NULL. If that function returned a NULL, then inst is NULL.
http://msdn.microsoft.com/en-us/libr...=vs.85%29.aspx
If "inst" is not NULL, then debug into the Move() function. Can you do that? If you can, where does the debugger take you? Does it actually go into a function, or does the debugger take you to some weird address that makes no sense? If it is the latter, this means that inst->Move points to garbage.
Regards,
Paul McKenzie
but these works fine:
Code:
case WM_LBUTTONUP:
SetFocus(inst->hwnd);
inst->SetText("Left mouse button up");
break;
case WM_MOUSEMOVE:
inst->SetText("mouse move");
break;
case WM_KEYUP:
inst->SetText(to_string(wParam));
break;
if i take that line off(inst->Move(xPos,yPos); ) the code works fine
-
December 30th, 2013, 03:10 PM
#65
Re: [win32] - creating controls using class's
Originally Posted by 2kaud
Where's the declaration/definition of move()?
after the 'public:', inside of the class
-
December 30th, 2013, 03:14 PM
#66
Re: [win32] - creating controls using class's
event(Move,(int x, int y));
????????? As a definition of the class function Move()
All advice is offered in good faith only. All my code is tested (unless stated explicitly otherwise) with the latest version of Microsoft Visual Studio (using the supported features of the latest standard) and is offered as examples only - not as production quality. I cannot offer advice regarding any other c/c++ compiler/IDE or incompatibilities with VS. You are ultimately responsible for the effects of your programs and the integrity of the machines they run on. Anything I post, code snippets, advice, etc is licensed as Public Domain https://creativecommons.org/publicdomain/zero/1.0/ and can be used without reference or acknowledgement. Also note that I only provide advice and guidance via the forums - and not via private messages!
C++23 Compiler: Microsoft VS2022 (17.6.5)
-
December 30th, 2013, 03:18 PM
#67
Re: [win32] - creating controls using class's
Originally Posted by 2kaud
????????? As a definition of the class function Move()
sorry:
#define event(eventname, ... ) std::function<void(__VA_ARGS__ )> eventname
-
December 30th, 2013, 04:41 PM
#68
Re: [win32] - creating controls using class's
sorry... was my mistake.
how can i use my 'events' if i don't give them what to do... sorry.. was realy my mistake... sorry.
(i did a test with a small code)
heres the code correted:
Code:
#include <windows.h>
#include <string>
#include <functional>
#define event(eventname, ... ) std::function<void(__VA_ARGS__ )> eventname
using namespace std;
const char *labelpropname = "Cambalinho";
const char *labelclassprop = "classaddr";
struct Position
{
int X;
int Y;
};
struct Size
{
int Width;
int Height;
};
class label
{
private:
HWND hwnd;
static LRESULT CALLBACK WndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
{
WNDPROC oldproc = (WNDPROC)GetProp(GetParent(hwnd), labelpropname);
label *inst = (label*)GetProp(GetParent(hwnd), labelclassprop);
if (oldproc == NULL || inst == NULL)
MessageBox(NULL, "null", "null", MB_OK);
switch(msg)
{
case WM_CREATE:
{
static int xPos = (int)(short) LOWORD(lParam);
static int yPos = (int)(short) HIWORD(lParam);
SetWindowText(GetParent(hwnd),"i'm alive my friend");
inst->Create(xPos,yPos);
}
case WM_MOVE:
{
static int xPos = (int)(short) LOWORD(lParam);
static int yPos = (int)(short) HIWORD(lParam);
inst->Move(xPos,yPos);//why these line make my progra, give me an error for get support? :(
}
break;
case WM_NCHITTEST:
return DefWindowProc(hwnd, msg, wParam, lParam);
case WM_LBUTTONUP:
SetFocus(inst->hwnd);
inst->SetText("Left mouse button up");
break;
case WM_MOUSEMOVE:
inst->SetText("mouse move");
break;
case WM_KEYUP:
inst->SetText(to_string(wParam));
break;
default:
break;
}
return oldproc ? CallWindowProc(oldproc, hwnd, msg, wParam, lParam) : DefWindowProc(hwnd, msg, wParam, lParam);
}
public:
//is these 2 lines ok?
//see the #define on top
event(Create,(int x, int y));
event(Move,(int x, int y));
~label()
{
DestroyWindow(hwnd);
hwnd = 0;
}
label(HWND parent)
{
Move=[](int x, int y)
{
;
};
Create=[](int x, int y)
{
;
};
WNDCLASS wc;
HINSTANCE mod = (HINSTANCE)GetModuleHandle(NULL);
ZeroMemory(&wc, sizeof(WNDCLASS));
GetClassInfo(mod, "STATIC", &wc);
wc.hInstance = mod;
wc.lpszClassName = "CSTATIC";
// store the old WNDPROC of the EDIT window class
SetProp(parent, labelpropname, (HANDLE)wc.lpfnWndProc);
SetProp(parent, labelclassprop, (HANDLE)this);
// replace it with local WNDPROC
wc.lpfnWndProc = WndProc;
// register the new window class, "ShEdit"
if (!RegisterClass(&wc))
MessageBox(NULL, "error in register", "error", MB_OK);
hwnd = CreateWindowEx(
WS_EX_LEFT| WS_EX_LTRREADING | WS_EX_RIGHTSCROLLBAR,
"CSTATIC",
"hello",
SS_LEFT|WS_CHILD|WS_VISIBLE,
0, 0, 100, 100,
parent,
NULL,
mod,
NULL);
if (hwnd == NULL)
MessageBox(NULL, "error in create", "error", MB_OK);
}
COORD GetSize()
{
RECT LabelSize;
GetWindowRect(hwnd,&LabelSize);
COORD crdSize = {LabelSize.right-LabelSize.left,LabelSize.bottom-LabelSize.top};
return crdSize;
}
void SetText(string text)
{
char* chrText = (char*)text.c_str();
SetWindowText(hwnd, chrText);
}
string GetText()
{
char *lbltext;
GetWindowText(hwnd,lbltext,255);
string strtext=lbltext;
return strtext;
}
};
now i see that before create the control, i must change it's events and then change the parent(create the control) for works correctly
thanks for all to all
(if i didn't said)
happy a new year to all
-
December 30th, 2013, 05:01 PM
#69
Re: [win32] - creating controls using class's
Originally Posted by Cambalinho
but...
The point being is that you should always check return codes. It doesn't matter if you are confident that it will work -- you always check return values if the function says what is returned on failure (or success).
The other reason is that we are looking at your code -- there is no way we can tell if the call worked or not. An explicit check for the return value not only helps you, it helps others looking at your code.
Regards,
Paul McKenzie
-
December 30th, 2013, 05:05 PM
#70
Re: [win32] - creating controls using class's
Code:
char *lbltext;
GetWindowText(hwnd,lbltext,255);
NO!! You have not created the buffer for GetWindowText - merely defined lbltext as a pointer to somewhere unknown! Use
Code:
void SetText(string text)
{
char* chrText = (char*)text.c_str();
SetWindowText(hwnd, chrText);
}
This would be better as
Code:
void SetText(const string& text)
{
SetWindowText(hwnd, text.c_str());
}
Last edited by 2kaud; December 30th, 2013 at 05:09 PM.
All advice is offered in good faith only. All my code is tested (unless stated explicitly otherwise) with the latest version of Microsoft Visual Studio (using the supported features of the latest standard) and is offered as examples only - not as production quality. I cannot offer advice regarding any other c/c++ compiler/IDE or incompatibilities with VS. You are ultimately responsible for the effects of your programs and the integrity of the machines they run on. Anything I post, code snippets, advice, etc is licensed as Public Domain https://creativecommons.org/publicdomain/zero/1.0/ and can be used without reference or acknowledgement. Also note that I only provide advice and guidance via the forums - and not via private messages!
C++23 Compiler: Microsoft VS2022 (17.6.5)
-
December 30th, 2013, 05:06 PM
#71
Re: [win32] - creating controls using class's
Originally Posted by Paul McKenzie
The point being is that you should always check return codes. It doesn't matter if you are confident that it will work -- you always check return values if the function says what is returned on failure (or success).
The other reason is that we are looking at your code -- there is no way we can tell if the call worked or not. An explicit check for the return value not only helps you, it helps others looking at your code.
Regards,
Paul McKenzie
thanks for all my friend.
i will continue with these thread open, until complete these class. thanks for all
-
December 30th, 2013, 05:08 PM
#72
Re: [win32] - creating controls using class's
Originally Posted by 2kaud
Code:
char *lbltext;
GetWindowText(hwnd,lbltext,255);
NO!! You have not created the buffer for GetWindowText - merely defined lbltext as a pointer to somewhere unknown! Use
thanks for correct me... thanks
why i can't use the 2 constant's variables inside the class?
const char *labelpropname = "Cambalinho";
const char *labelclassprop = "classaddr";
-
December 30th, 2013, 05:17 PM
#73
Re: [win32] - creating controls using class's
Originally Posted by Cambalinho
why i can't use the 2 constant's variables inside the class?
const char *labelpropname = "Cambalinho";
const char *labelclassprop = "classaddr";
Because only const static integral data members can be initialized inside a class or struct - basially char, bool and int (and the short/long variations). See http://msdn.microsoft.com/en-us/library/cc953fe1.aspx
All advice is offered in good faith only. All my code is tested (unless stated explicitly otherwise) with the latest version of Microsoft Visual Studio (using the supported features of the latest standard) and is offered as examples only - not as production quality. I cannot offer advice regarding any other c/c++ compiler/IDE or incompatibilities with VS. You are ultimately responsible for the effects of your programs and the integrity of the machines they run on. Anything I post, code snippets, advice, etc is licensed as Public Domain https://creativecommons.org/publicdomain/zero/1.0/ and can be used without reference or acknowledgement. Also note that I only provide advice and guidance via the forums - and not via private messages!
C++23 Compiler: Microsoft VS2022 (17.6.5)
-
December 30th, 2013, 05:23 PM
#74
Re: [win32] - creating controls using class's
Originally Posted by 2kaud
thanks for all
-
December 31st, 2013, 10:21 AM
#75
Re: [win32] - creating controls using class's
see these lines:
Code:
label label1(hwnd);
label1.MouseDown=[](int Button, bool alt, bool shift,int x, int y)
{
if(alt==true && Button==VK_LBUTTON) label1.SetText("mouse left down");//error message
};
what means these error:
"'label1' is not captured|"
???
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|