Re: how create a control?
my problem was be using console instead the GUID project.
now i need connect the label with message loop:
Code:
SetWindowLongPtr(hwnd, GWL_WNDPROC, (LONG_PTR)WndProc);
WndProc - is the message loop procedure.
error message:
"invalid use of member function (did you forget the '()' ?)"
so tell me: what i'm doing wrong?
Re: how create a control?
Where is the message loop exactly? You need to first understand the event based model. There's tons wrong with this, although I can't help you with this based on my current understanding of your knowledge in C++. You're trying to advance too quickly; you can't become a C++ wizard within a short time. This is a language that takes time to digest, and if you don't understand message loops yet, how are you expecting yourself to write a label class? :confused:
Quote:
my problem was be using console instead the GUID project.
This is not the problem at all, I can create a GUI with a console project no problem.
It's good to be optimistic, and ambitious, but there are limitations to what you can expect from a programmer still learning the foundations of the language.. I suggest you start with more basic projects first. Post your implementation of a calculator for instance, and we'll see how you do. If you think a basic one is too easy, then try one which calculates in a stack based method using RPN notation, and if that's too easy, try creating one that converts from infix to RPN notation, and calculates the result with the 4 basic operations in math. If you're choosing the last one, I'll almost guarantee that you're shooting for the stars there; it won't be easy with the level you're at based on what I've seen, but the point is that you need to start someplace more appropriate.
Cheers
Re: how create a control?
Quote:
Originally Posted by
AceInfinity
Where is the message loop exactly? There's tons wrong with this, although I can't help you with this based on my current understanding of your knowledge in C++. You're trying to advance too quickly; you can't become a C++ wizard within a short time. This is a language that takes time to digest, and if you don't understand message loops yet, how are you expecting yourself to write a label class? :confused:
This is not the problem at all, I can create a GUI with a console project no problem.
It's good to be optimistic, and ambitious, but there are limitations to what you can expect from a programmer still learning the foundations of the language..
Cheers
heres my entire class:
Code:
#include <windows.h>
#include <iostream>
#include <string>
#include <process.h>
using namespace std;
HWND hwnd;
HHOOK _hook;
WNDPROC previous_boring_subclassed_edit_proc;
//heres the window procedure
LRESULT CALLBACK WndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
{
WNDPROC oldproc =(WNDPROC)GetWindowLongPtr(GetParent(hwnd),GWLP_USERDATA);
UINT i=(UINT)GetWindowLongPtr(GetParent(hwnd),GWLP_USERDATA);
switch(msg)
{
case WM_NCCREATE:
{
CREATESTRUCT *createstruct = (CREATESTRUCT*)lParam;
SetWindowLong(hwnd, GWL_USERDATA, (long)createstruct->lpCreateParams);
}
break;
case WM_CREATE:
SetWindowText(hwnd,"hi");
break;
case WM_MOUSEMOVE:
SetWindowText(hwnd,"hello");
break;
case WM_CLOSE:
DestroyWindow(hwnd);
break;
case WM_DESTROY:
PostQuitMessage(0);
break;
default:
return CallWindowProc(previous_boring_subclassed_edit_proc, hwnd, msg, wParam, lParam);
}
return 0;
}
class label
{
private:
public:
label(){};
label(HWND value)
{
hwnd = CreateWindowEx(
WS_EX_LEFT| WS_EX_LTRREADING | WS_EX_RIGHTSCROLLBAR,
"STATIC",
"",
SS_LEFT|WS_CHILD|WS_VISIBLE,
0, 0, 100, 100,
value,
NULL,
GetModuleHandle(NULL),
NULL);
ShowWindow(hwnd,SW_SHOW);
UpdateWindow(hwnd);
previous_boring_subclassed_edit_proc = (WNDPROC)GetWindowLong(hwnd, GWL_WNDPROC);//get the default procedure
SetWindowLong(hwnd, GWL_WNDPROC, (LONG_PTR)WndProc);//set your custom procedure :)
}
void setparent(HWND value)
{
hwnd = CreateWindowEx(
WS_EX_LEFT| WS_EX_LTRREADING | WS_EX_RIGHTSCROLLBAR,
"STATIC",
"",
SS_LEFT|WS_CHILD|WS_VISIBLE,
0, 0, 100, 100,
value,
NULL,
GetModuleHandle(NULL),
NULL);
ShowWindow(hwnd,SW_SHOW);
UpdateWindow(hwnd);
previous_boring_subclassed_edit_proc = (WNDPROC)GetWindowLong(hwnd, GWL_WNDPROC);//get the default procedure
SetWindowLong(hwnd, GWL_WNDPROC, (LONG_PTR)WndProc);//set your custom procedure :)
}
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);
}
};
heres the main.cpp:
Code:
#include <windows.h>
#include "Label.h"
using namespace std;
label test;
/* Declare Windows procedure */
LRESULT CALLBACK WindowProcedure (HWND, UINT, WPARAM, LPARAM);
/* Make the class name into a global variable */
char szClassName[] = "CodeBlocksWindowsApp";
//creating the window
int WINAPI WinMain (HINSTANCE hThisInstance, HINSTANCE, LPSTR lpszArgument, int nCmdShow)
{
HWND hwnd; /* This is the handle for our window */
MSG messages; /* Here messages to the application are saved */
WNDCLASSEX wincl; /* Data structure for the windowclass */
/* The Window structure */
wincl.hInstance = hThisInstance;
wincl.lpszClassName = szClassName;
wincl.lpfnWndProc = WindowProcedure; /* This function is called by windows */
wincl.style = CS_DBLCLKS; /* Catch double-clicks */
wincl.cbSize = sizeof (WNDCLASSEX);
/* Use default icon and mouse-pointer */
wincl.hIcon = LoadIcon (NULL, IDI_APPLICATION);
wincl.hIconSm = LoadIcon (NULL, IDI_APPLICATION);
wincl.hCursor = LoadCursor (NULL, IDC_ARROW);
wincl.lpszMenuName = NULL; /* No menu */
wincl.cbClsExtra = 0; /* No extra bytes after the window class */
wincl.cbWndExtra = 0; /* structure or the window instance */
/* Use Windows's default colour as the background of the window */
wincl.hbrBackground = (HBRUSH) COLOR_BACKGROUND;
/* Register the window class, and if it fails quit the program */
if (!RegisterClassEx (&wincl))
return 0;
/* The class is registered, let's create the program*/
hwnd = CreateWindowEx (
0, /* Extended possibilites for variation */
szClassName, /* Classname */
"Code::Blocks Template Windows App", /* Title Text */
WS_OVERLAPPEDWINDOW, /* default window */
CW_USEDEFAULT, /* Windows decides the position */
CW_USEDEFAULT, /* where the window ends up on the screen */
544, /* The programs width */
375, /* and height in pixels */
HWND_DESKTOP, /* The window is a child-window to desktop */
NULL, /* No menu */
hThisInstance, /* Program Instance handler */
NULL /* No Window Creation data */
);
/* Make the window visible on the screen */
ShowWindow (hwnd, nCmdShow);
UpdateWindow(hwnd);
label label1(hwnd);
//label1.SetText("oi");
/* Run the message loop. It will run until GetMessage() returns 0 */
while (GetMessage (&messages, NULL, 0, 0))
{
/* Translate virtual-key messages into character messages */
TranslateMessage(&messages);
/* Send message to WindowProcedure */
DispatchMessage(&messages);
}
/* The program return-value is 0 - The value that PostQuitMessage() gave */
return messages.wParam;
}
/* This function is called by the Windows function DispatchMessage() */
LRESULT CALLBACK WindowProcedure (HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
{
switch (message) /* handle the messages */
{
case WM_CREATE:
test.setparent(hwnd);
test.SetText("hello");
break;
case WM_DESTROY:
PostQuitMessage (0); /* send a WM_QUIT to the message queue */
break;
default: /* for messages that we don't deal with */
return DefWindowProc (hwnd, message, wParam, lParam);
}
return 0;
}
seems that i must connet my window procedure(the control procedure) to the form\window procedure for i get the messages correctly.
the createwindowex() creates the STATIC control, now i must connect it to window procedure.. but i don't know how :(
i tryied use the SetWindowLog()(like VB6), but isn't working :(