April 26, 2024, 01:21:23 PM

News:

Own IWBasic 2.x ? -----> Get your free upgrade to 3.x now.........


@notifycode

Started by aurelCB, December 08, 2011, 12:04:41 AM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

aurelCB

Is there api replacment for this message commmand?

LarryMc

No, because it is not a command; it is a constant.

Quote@NOTIFYCODE contains the data from the high order bits of @WPARAM

when a control sends its parent a WM_COMMAND/ WM_NOTIFY message the @lparam and @wparam constants contain the control id, the message and additional data that is control specific.

It's covered in the forums at the tail end of my custom control tutorial Section 5a

LarryMc
LarryMc
Larry McCaughn :)
Author of IWB+, Custom Button Designer library, Custom Chart Designer library, Snippet Manager, IWGrid control library, LM_Image control library

aurelCB

Thanks Larry...
Hmm this is little bit tricky when we comes to native api.
I found something on windows-wiki site but looks very confusing
It looks that @notifycode is a result of function which return notification
message from created control.
pseudo code:
Function NotifyMsg(hwnd,controlID)
wmsg=SendMessage hwnd,WM_NOTIFY,controlID,0
FnReturn=wmsg
End Function

Oh my this looks like nightmare.
I will look into Freebasic examples even FB coding is nightmare by himself ::)

LarryMc

It's not complicated.
@notifycode is a IWBasic constant.

internally,when a control sends a WM_NOTIFY message to its parent it is in the form:

sendmessage(parent.hwnd,WM_NOTIFY,wparam,lparam)

IWBasic renames WM_NOTIFY to @IDCONTROL

wparam contains two pieces of information
the ID of the control is in the lower 16 bits and the actual notification message is in the highest 16 bits
IWBasic puts the ID in @CONTROLID and the message in @NOTIFYCODE

the lparam will contain specific data relative to the control and can be of ANYTYPE.

Maybe if you tell us what you are trying to do we could help you.

LarryMc
LarryMc
Larry McCaughn :)
Author of IWB+, Custom Button Designer library, Custom Chart Designer library, Snippet Manager, IWGrid control library, LM_Image control library

aurelCB

Heh...
Sorry i forget to add code.
Infact code is very simple and present window creation by api.
And here is what i do and looks that is not important to add WM_NOTIFY then BN_CLICKED and
respond good on xp manifested exe.
/* WINDOW CREATED WITH WINAPI FUNCTIONS  */

$INCLUDE "windows.inc"


' REDECLARING SOME FUNCTIONS WITH SECOND PARAM AS POINTER, NOT STRING
DECLARE "user32.dll",LoadIcon ALIAS "LoadIconA"(hinstance:INT, id:pointer),uint
DECLARE "user32.dll",LoadCursor ALIAS "LoadCursorA"(hinstance:INT, id:pointer),uint


' DECLARE THE VARIABLES
STRING pCommandLine
STARTUPINFO info
DEF hwnd AS INT ' windows handle
DEF btn_1 as INT 'button handle
DEF bID as INT
bID=100
DEF wincl AS WNDCLASSEX ' type for windowclass
DEF messages AS MSG
DEF ClassName as STRING ' class name
DEF pClassName as POINTER ' pointer to class name
ClassName="MyWindow"
pClassName=ClassName
Const WM_NOTIFY = 0x004E
CONST WM_COMMAND = 0x111
CONST BN_CLICKED = 0

' INIT THE <WINMAIN> STUFF
EXTERN _hinstance as UINT
pCommandLine = _GetCommandLine()
_GetStartupInfo(info)

' INIT THE WNDCLASSEX
wincl.lpszClassName=pClassName /* class name */
wincl.hInstance = _hinstance
wincl.lpfnWndProc = &WinProc /* windows procedure */
wincl.style = CS_DBLCLKS /* Catch double-clicks */
wincl.cbSize = LEN(WNDCLASSEX)
wincl.lpszMenuName = 0 /* no menú */
wincl.cbClsExtra = 0 /* No extra bytes after the window class */
wincl.cbWndExtra = 0 /* structure or the window instance */
wincl.hbrBackground = COLOR_BACKGROUND
wincl.hIcon=LoadIcon(0, IDI_APPLICATION)
wincl.hIconSm = LoadIcon(0, IDI_APPLICATION)
wincl.hCursor = LoadCursor(0, IDC_ARROW)


' REGISTER THE CLASS
IF _RegisterClassEx (wincl)=0 THEN
DebugText("Can't register the class")
END
ELSE
DebugText("Registering the class: OK")
ENDIF


' CREATE THE WINDOW
hwnd = _CreateWindowEx (0, ClassName , "Window Caption", WS_OVERLAPPEDWINDOW, 100, 100, 300, 200, HWND_DESKTOP, 0, _hinstance, 0)
' SHOW THE WINDOW
_ShowWindow (hwnd, info.dwFlags)
btn_1 = _CreateWindowEx (0, "BUTTON","Button1",0x50000000, 95, 47, 89, 27,hwnd,bID,0 ,0)





' MAIN LOOP
WHILE (_GetMessage (messages, 0, 0, 0))
/* Translate virtual-key messages into character messages */
_TranslateMessage(messages)
/* Send message to WindowProcedure */
_DispatchMessage(messages)
ENDWHILE
END


' WINDOW PROCEDURE
SUB WinProc(hWnd:INT,wMsg:INT,wParam:INT,lParam:INT),INT
SELECT wMsg
CASE WM_COMMAND
SELECT @wparam
CASE BN_CLICKED
IF bID = 100
MESSAGEBOX 0,"Button Clicked!","OK",64
ENDIF

ENDSELECT

CASE @IDDESTROY
_PostQuitMessage (0)
' any unhandled message goes here
DEFAULT
RETURN _DefWindowProc(hWnd, wMsg, wParam, lParam)
ENDSELECT
RETURN 0
ENDSUB


' FUNCTION TO OUTPUTS A STRING TO THE DEBUG VIEW ONLY IF WE ARE IN DEBUG MODE
SUB DebugText(string text)
$IFDEF DEBUG
DEBUGPRINT text
$ENDIF
ENDSUB

LarryMc

The last paragraph of section 5a of my custom control tutorial says:

QuoteNot all controls send notification messages.  Click one of the buttons.  The notification message ID is 0.  That is because the sending of the message is enough by itself without any additional clarification (notification) information as to the type of event that occurred.

your following code shows the message for the following reasons:

CASE WM_COMMAND
SELECT @wparam '<== always zero because value is normally set with IWB message handler which you aren't using
CASE BN_CLICKED  '<==this constant is 0 so it matches your select
IF bID = 100  '<== since this variable is set at the global level it iss always true
MESSAGEBOX 0,"Button Clicked!","OK",64
ENDIF
ENDSELECT


so with that code you could add 100 buttons without changing the above code and clicking any button would activated the messebox.

I'll post some working code in a little while.

LarryMc
LarryMc
Larry McCaughn :)
Author of IWB+, Custom Button Designer library, Custom Chart Designer library, Snippet Manager, IWGrid control library, LM_Image control library

LarryMc

Ok, this is the structure you should be using;
I added a second button for demo purposes.

/* WINDOW CREATED WITH WINAPI FUNCTIONS  */

$INCLUDE "windows.inc"

' REDECLARING SOME FUNCTIONS WITH SECOND PARAM AS POINTER, NOT STRING
DECLARE "user32.dll",LoadIcon ALIAS "LoadIconA"(hinstance:INT, id:pointer),uint
DECLARE "user32.dll",LoadCursor ALIAS "LoadCursorA"(hinstance:INT, id:pointer),uint


' DECLARE THE VARIABLES
STRING pCommandLine
STARTUPINFO info
DEF hwnd AS INT ' windows handle
DEF btn_1 as INT 'button handle
DEF btn_2 as INT 'button handle
DEF bID as INT
bID=100
bID2=101
DEF wincl AS WNDCLASSEX ' type for windowclass
DEF messages AS MSG
DEF ClassName as STRING ' class name
DEF pClassName as POINTER ' pointer to class name
ClassName="MyWindow"
pClassName=ClassName
Const WM_NOTIFY = 0x004E
CONST WM_COMMAND = 0x111
CONST BN_CLICKED = 0

' INIT THE <WINMAIN> STUFF
EXTERN _hinstance as UINT
pCommandLine = _GetCommandLine()
_GetStartupInfo(info)

' INIT THE WNDCLASSEX
wincl.lpszClassName=pClassName /* class name */
wincl.hInstance = _hinstance
wincl.lpfnWndProc = &WinProc /* windows procedure */
wincl.style = CS_DBLCLKS /* Catch double-clicks */
wincl.cbSize = LEN(WNDCLASSEX)
wincl.lpszMenuName = 0 /* no menú */
wincl.cbClsExtra = 0 /* No extra bytes after the window class */
wincl.cbWndExtra = 0 /* structure or the window instance */
wincl.hbrBackground = COLOR_BACKGROUND
wincl.hIcon=LoadIcon(0, IDI_APPLICATION)
wincl.hIconSm = LoadIcon(0, IDI_APPLICATION)
wincl.hCursor = LoadCursor(0, IDC_ARROW)


' REGISTER THE CLASS
IF _RegisterClassEx (wincl)=0 THEN
DebugText("Can't register the class")
END
ELSE
DebugText("Registering the class: OK")
ENDIF


' CREATE THE WINDOW
hwnd = _CreateWindowEx (0, ClassName , "Window Caption", WS_OVERLAPPEDWINDOW, 100, 100, 300, 200, HWND_DESKTOP, 0, _hinstance, 0)
' SHOW THE WINDOW
_ShowWindow (hwnd, info.dwFlags)
btn_1 = _CreateWindowEx (0, "BUTTON","Button1",0x50000000, 95, 32, 89, 27,hwnd,bID,0 ,0)
btn_2 = _CreateWindowEx (0, "BUTTON","Button2",0x50000000, 95, 62, 89, 27,hwnd,bID2,0 ,0)





' MAIN LOOP
WHILE (_GetMessage (messages, 0, 0, 0))
/* Translate virtual-key messages into character messages */
_TranslateMessage(messages)
/* Send message to WindowProcedure */
_DispatchMessage(messages)
ENDWHILE
END


' WINDOW PROCEDURE
SUB WinProc(hWnd:INT,wMsg:INT,wParam:INT,lParam:INT),INT
SELECT wMsg
CASE WM_COMMAND
SELECT (wparam & 0xffff) '<-- to get control ID
Case 100
select (wparam >> 16) '<-- to get the message
CASE BN_CLICKED
MESSAGEBOX 0,"Button 1 Clicked!","OK",64

endselect
Case 101
select (wparam >> 16) '<-- to get the message
CASE BN_CLICKED
MESSAGEBOX 0,"Button 2 Clicked!","OK",64

endselect
ENDSELECT

CASE @IDDESTROY
_PostQuitMessage (0)
' any unhandled message goes here
DEFAULT
RETURN _DefWindowProc(hWnd, wMsg, wParam, lParam)
ENDSELECT
RETURN 0
ENDSUB


' FUNCTION TO OUTPUTS A STRING TO THE DEBUG VIEW ONLY IF WE ARE IN DEBUG MODE
SUB DebugText(string text)
$IFDEF DEBUG
DEBUGPRINT text
$ENDIF
ENDSUB


LarryMc
LarryMc
Larry McCaughn :)
Author of IWB+, Custom Button Designer library, Custom Chart Designer library, Snippet Manager, IWGrid control library, LM_Image control library

aurelCB

Yes Larry you right ;)
I simply don't know how to add selecting LoWord and HiWord of wParam.
SELECT (wparam & 0xffff) '<-- to get control ID - LoWord
Case 100
select (wparam >> 16) - HiWord