YC ++ Create HTML Toolbar

Source: Internet
Author: User

YC ++ Create HTML Toolbar

In YC ++, you can use Win32 functions such as createjavaswex (ws_ex_toolwindow, toolbarclassname,...) to create
Toolbar (for example, see yc01/examples/ycp. cpp). You can also use its API functions:

Hwnd yxb_window (yhookproc wnd_hook, void * puserdata, DWORD dwexstyle, DWORD dwstyle, lpcstr lpwindowname,
Int X, int y, int nwidth, int nheight, hwnd hwndparent, int wintype );

Create a toolbar.

/*************************************** **************************************** **********************************/
This function represents the toolbar interface using HTML text and CSS styles, controls the toolbar elements using JavaScript scripts and Dom, and implements Program Logic using C/C ++.
This toolbar not only makes the interface gorgeous, but also separates the interface from the logic for easy debugging. In addition, the source code of the interface is irrelevant to the platform.
For example, you can use the tool bar in windows without modifying the source code in other operating systems such as UNIX and Linux.
The following describes the parameters of the function and lists the sample code.

/*************************************** **************************************** **********************************/
Parameters
/*************************************** **************************************** **********************************/
Wnd_hook
Callback function pointer. when an event occurs related to a window (created using this function), it is called.
The format is: int winapi wnd_hook (hwnd, uint iMessage, uint wparam, long lparam, void * puserdata );
Parameters
The handle of the window in which hwnd HTML is located.
IMessage message type.
Wparam and lparam. Messages may contain data, which can be expressed by wparam and lparam.
Puserdata user data. The window is passed to the system when the user creates the window, and the system returns the window to the user through the callback function.
Avoid using global variables.

//////////////////////////////////////// //////////////////////////////////////// //////////////////////////
The callback function wnd_hook enables data communication between webpages and callers. Currently, there are four types of system events and countless types of custom events.
When this happens, the callback function is automatically called. For example:
Int winapi html_hook (hwnd, uint iMessage, uint wparam, long lparam, void * puserdata)
{
Switch (iMessage)
{
Case ym_onload: break; // After the webpage is parsed and the onload function is executed.
Case ym_close: break; // the moment before the page is closed.
// Wparam = 0 indicates that the window has not been scaled by the JavaScript function resizeTo.
Case ym_paint: // when a webpage is refreshed and displayed in its window.
Yimg * pimg;
Pimg = (yimg *) wparam; // image pointer of the webpage
Rect * pclientrect;
Pclientrect = (rect *) lparam; // the area where the webpage is refreshed
Return true; // the return value is true, indicating that the caller has handled the event.
Case ym_keydown: // when a key is pressed. See yctool. h.
Int ctrl_flag, shift_flag, vkvalue;
Ctrl_flag = wparam & ctrl_mask; // press Ctrl
Shift_flag = wparam & shift_mask; // press shift
Vkvalue = wparam & key_mask; // key value
Return true; // the return value is true, indicating that the caller has handled the event.
Case (any integer message> = 0 & <0x7f000000 ):
When YC extension JavaScript function is called on the webpage
When you hook (iMessage,...), the callback function is called,
The message iMessage is customized by the user.
Return (any integer );
Case (any integer message <=-1 ):
Special provisions
Returns a string pointer when the message is negative.
Return string pointer;
}
Return false;
}

/*************************************** **************************************** **********************************/
Puserdata
It is a pointer (or integer) that the caller sends to the callback function wnd_hook ).

/*************************************** **************************************** **********************************/
Lpwindowname
Window name.

/*************************************** **************************************** **********************************/
Dwexstyle, dwstyle
They define the window format. Its meaning is the same as that in the Win32 function createmediawex.

/*************************************** **************************************** **********************************/
X, Y, nwidth, nheight
They define the location and size of the window. Its meaning is the same as that in the Win32 function createmediawex.

/*************************************** **************************************** **********************************/
Hwndparent parent window handle

/*************************************** **************************************** **********************************/
The window type to be created by wintype. Here we should set it to: wt_html

/*************************************** **************************************** **********************************/
The return value indicates the handle of the created window. If the return value is null, the window is not created successfully.

/*************************************** **************************************** **********************************/
After creating a toolbar window, you must also send a toolbar webpage to the window.

/*************************************** **************************************** **********************************/
Example:
/*************************************** **************************************** **********************************/
In this example, You need to upload the following seven files of YC ++ to the directory where your source program is located:

Yc01/yxbapi. dll C/C ++ compiler, browser kernel Library
Yc01/yxbimg. dll image, animation decoding library
Yc01/yxbext. dll browser kernel interaction code library
Yc01/YC. Ah C/C ++ compiler header package
Yc01/YC. cmp c/C ++ compiler error message

Yc01/yctool.bmp toolbar Image File

Yc01/include/ycapi. h header files required to run this example using other compilers
Yc01/include/yxbapi. lib use other compilers to run the required library files, such as vc6.0

/*************************************** **************************************** **********************************/
/*************************************** **************************************** **********************************/
/*************************************** **************************************** **********************************/
Upload the following code to a file named by name, such as blog3a. cpp.
In YC ++, use <file/open or create CPP source program> to call blog3a. cpp, and then use <tool/execute> to run blog3a. cpp
In dos, use ycc blog3a. cpp to generate blog3a.exe, and then run blog3a.exe
In VC ++, use Cl blog3a. cpp to generate blog3a.exe, and then run blog3a.exe

/*************************************** **************************************** **********************************/
/*************************************** **************************************** **********************************/
# Ifndef ycc
# Include <windows. h>
# Pragma comment (Lib, "gdi32.lib ")
# Pragma comment (Lib, "user32.lib ")
# Pragma comment (Lib, "yxbapi. lib ")
# Include "ycapi. H"
# Endif

# Define var const int

VaR address_high = 27;
VaR tool_high = 24;

VaR id_toolbarexist = 0;
VaR id_toolbmp = 1;
VaR id_go = 2;
VaR id_edit = 3;
VaR id_backward = 4;
VaR id_menu_backward = 5;
VaR id_forward = 6;
VaR id_menu_forward = 7;
VaR id_stop = 8;
VaR id_refresh = 9;
VaR id_home = 10;

Int winapi winmain (hinstance, hinstance hprevinstance, lpstr lpcmdline, int nshowcmd)
{
//////// Create the main window. it is created using the YC ++ API function and does not need to be registered. you can also use the Win32 function to create the main window ////////////////////////
Int winapi mainwndproc (hwnd, uint iMessage, uint wparam, long lparam, void * puserdata );
Hwnd = yxb_window (mainwndproc, null, 0,
Ws_overlappedwindow | ws_caption | ws_sysmenu,
"A", 110,50, 800,600, null, wt_win );

MSG;
While (getmessage (& MSG, null, 0, 0 ))
{
Translatemessage (& MSG );
Dispatchmessage (& MSG );
}

Return 0;
}

//////////////////////////////////////// //////////////////////////////////////// ////////////////////////
Int winapi address_hook (hwnd, uint iMessage, uint wparam, long lparam, void * puserdata)
{
Hwnd m_htoolwnd = * (hwnd *) puserdata;
Switch (iMessage)
{
Case ym_keydown:
Postmessage (getparent (hwnd), wm_keydown, wparam, lparam );
Break;
Case ym_onload:
Setfocus (m_htoolwnd); // input the focus to the toolbar
Yxb_runjscript (m_htoolwnd, "set_edit_value ('How do you do? ') "); // The edit box is initialized.
Break;
Case id_edit: break;
Case id_go: MessageBox (hwnd, "go", "YC ++", mb_iconhand | mb_ OK); break;
Case id_menu_backward: MessageBox (hwnd, "menu_backward", "YC ++", mb_iconhand | mb_ OK); break;
Case id_menu_forward: MessageBox (hwnd, "menu_forward", "YC ++", mb_iconhand | mb_ OK); break;
Case id_backward: MessageBox (hwnd, "backward", "YC ++", mb_iconhand | mb_ OK); break;
Case id_forward: MessageBox (hwnd, "forward", "YC ++", mb_iconhand | mb_ OK); break;
Case id_stop: MessageBox (hwnd, "stop", "YC ++", mb_iconhand | mb_ OK); break;
Case id_refresh: MessageBox (hwnd, "refresh", "YC ++", mb_iconhand | mb_ OK); break;
Case id_home: MessageBox (hwnd, "home", "YC ++", mb_iconhand | mb_ OK); break;
}
Return false;
}

//////////////////////////////////////// //////////////////////////////////////// ////////////////////////////////////
Int winapi mainwndproc (hwnd, uint iMessage, uint wparam, long lparam, void * puserdata)
{
Rect mrect;
Switch (iMessage)
{
Case wm_create:
/////// Create the HTML toolbar //////////////////////////// //////////////////////////////////
Int winapi address_hook (hwnd, uint iMessage, uint wparam, long lparam, void * puserdata );
Static hwnd m_htoolwnd; // toolbar window
M_htoolwnd = yxb_window (address_hook, & m_htoolwnd, 0, ys_nowrerr, null, 0, 0, 0, hwnd, wt_html );

//////////// Send a webpage to the toolbar window ///////////////////// //////////////////////////////////////// ///////
Web_page apage;
Memset (& apage, 0, sizeof (apage ));
Apage. click_page = 3;
Apage. href = "tool.htm ";
Sendmessage (m_htoolwnd, wm_command, web_a, (INT) (web_page *) & apage );
Return false;

Case wm_size:
Getclientrect (hwnd, & mrect );
Movewindow (m_htoolwnd, mrect. Left, mrect. Top, mrect. Right, address_high + tool_high + 4, true); // if it is false, the right part of the rebar cannot be refreshed.
Return false;

Case wm_destroy: postquitmessage (0); Return false;

Case wm_keydown:
If (wparam = vk_escape) destroywindow (hwnd );
Return false;

Case wm_paint: // whenever the customer area of the window has an area to be re-painted, Windows sends the wm_paint message to the window.
Paintstruct pS;
Beginpaint (hwnd, & PS );
Yimg;
Memset (& yimg, 0, sizeof yimg );
Yimg. HDC = ps. HDC; // you can use this setting to operate the window client area as an image.

Getclientrect (hwnd, & mrect );

//// Use the YC built-in function yxb_imagefill to draw the following four monochrome rectangles in the image yimg ////////////////////// ///////////
Yxb_imagefill (& yimg, mrect. Left, mrect. Top, mrect. right-mRect.left,
Mrect. bottom-mRect.top, RGB (130,150,160 ));
Yxb_imagefill (& yimg, 100,100,200,150, RGB (100,0, 0 ));
Yxb_imagefill (& yimg, 150,150,200,150, RGB (0,100, 0 ));
Yxb_imagefill (& yimg, 200,200,200,150, RGB (0, 0, 100 ));

Endpaint (hwnd, & PS );
Return false;
}
Return defwindowproc (hwnd, iMessage, wparam, lparam );
}

/*************************************** **************************************** **********************************/
/*************************************** **************************************** **********************************/
/*************************************** **************************************** **********************************/
Upload the following HTML text to the specified file: tool.htm
/*************************************** **************************************** **********************************/
<Body onload = body_onload () onresize = body_onresize () topmargin = 0 leftmargin = 0 style = "overflow: hidden;">

<Form ID = toolp style = "position: absolute; font-family: tahoma; font-size: 16; width = 10000">
<Input id = backward
Type = toolbar // indicates the HTML attributes of the button and YC ++ extension.
Onchange = tool_onchange (); // indicates a button event.
Alink = blue
Value = "backward" // indicates the text of the button
Content = "Drop icosize (16, 16) paint (10, 0) Move (10, 1) Disabled (0, 0) edgepaint = 0 edgemove = 1" // indicates the button position
Src = "yctool.bmp"> <! -- CO = indicates the image of the button -->
<Input id = forward
Type = Toolbar
Onchange = tool_onchange ();
Title = "Qianjin"
Content = "Drop icosize (16, 16) paint (11, 0) Move (11, 1) Disabled (0, 1) edgepaint = 0 edgemove = 1"
Src = "yctool.bmp">
<Input id = stop
Type = Toolbar
Onchange = tool_onchange ();
Title = "stop"
Content = "icosize (16, 16) paint (12, 0) Move (12, 1) edgepaint = 0 edgemove = 1"
Src = "yctool.bmp">
<Input id = Refresh
Type = Toolbar
Onchange = tool_onchange ();
Title = "refresh"
Content = "icosize (16, 16) paint (13, 0) Move (13, 1) edgepaint = 0 edgemove = 1"
Src = "yctool.bmp">
<Input id = home
Type = Toolbar
Onchange = tool_onchange ();
Title = "Homepage"
Content = "icosize () paint () Move () edgepaint = 0 edgemove = 1"
Src = "yctool.bmp">

</Form>

<Div nowrap id = ADDR style = "position: absolute; font-family: Arial; font-size: 18;"> address (<u> d </u>) </div>

<Input id = Edit Selected
Oncontrol = "Hook (id_edit, event. CTRL )"
Style = "position: absolute; font-family: tahoma; font-size: 16;">

<Input id = go type = Toolbar
Onchange = "Hook (id_go );"
Value = "go"
Content = "icosize (16,16) paint (19,0) Move (19,1) Xpress (14,0) Disabled (13,0) edgepaint = 0 edgemove = 1"
Src = "yctool.bmp"
Style = "position: absolute; font-family: tahoma; font-size: 16; Height = 25;">

<Script language = JavaScript>
VaR address_high = 27;
VaR tool_high = 24;

VaR id_toolbarexist = 0;
VaR id_toolbmp = 1;
VaR id_go = 2;
VaR id_edit = 3;
VaR id_backward = 4;
VaR id_menu_backward = 5;
VaR id_forward = 6;
VaR id_menu_forward = 7;
VaR id_stop = 8;
VaR id_refresh = 9;
VaR id_home = 10;

Document. Body. size = tool_high; // <body> when the marked attribute size> 0, the page is used in the toolbar.

Function dialog_init (AA, BB)
{
Backward. Disabled = AA;
Forward. Disabled = BB;
}

Function body_onload ()
{
Hook (id_toolbmp, go. IMG );
Edit. Focus ();
Body_onresize ();
}

Function body_onresize ()
{
Addr_pos = tool_high + 1;

Toolp. style. Left = 2;
Toolp. style. Top = 2;
For (II = 0; II <toolp. elements. length; II ++) toolp. elements [II]. style. Height = TOOL_HIGH-2;

Edit. style. Top = addr_pos + 1;
Edit. style. Left = ADDR. Width + 3;
Edit. style. width = Document. Body. clientwidth-go. Width-Edit. style. Left-8;
Edit. style. Height = address_high;

ADDR. style. Left = 2;
ADDR. style. Top = addr_pos + (edit. style. Height-ADDR. Height)/2 + 1;

Go. style. Top = addr_pos + (edit. style. Height-go. Height)/2 + 1;
Go. style. Left = edit. style. Left + edit. style. Width + 3;
}

Function set_edit_value (SS)
{
Edit. value = SS;
}

Function get_edit_value ()
{
Return edit. value;
}

Function set_edit_length (NN)
{
Edit. Lines = nn;
}

Function tool_onchange ()
{
VaR NN, selp = event. srcelement;
Switch (selp)
{
Case backward:
If (event. CTRL = 1) nn = id_backward;
Else nn = id_menu_backward;
Break;
Case forward:
If (event. CTRL = 1) nn = id_forward;
Else nn = id_menu_forward;
Break;
Case stop:
Nn = id_stop;
Break;
Case Refresh:
Nn = id_refresh;
Break;
Case home:
Nn = id_home;
Break;
}
Hook (NN, selp. clientleft + (selp. clienttop <16), selp. clientwidth + (selp. clientheight <16 ));
}
</SCRIPT>

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.