Create HTML dialog box With YC ++

Source: Internet
Author: User
Tags webfile

Create HTML dialog box With YC ++

/*************************************** **************************************** **********************************/
In YC ++, you can use Windows functions such as dialogboxindirectparam and dialogboxparam to create a dialog box.
(For example, see yc01/ycset. cpp). You can also use its built-in functions:

Int yxb_dialog (yhookproc wnd_hook, void * puserdata, DWORD dwexstyle,
DWORD dwstyle, lpcstr lpwindowname, int X, int y, int nwidth, int nheight,
Hwnd hwndparent, char * webfile, int weblen );

Create dialog box.

/*************************************** **************************************** **********************************/
This function uses HTML and CSS text to display the interface of the dialog box, JavaScript and Dom to control interface elements, and C/C ++ to implement program logic.
This dialog box not only makes the interface rich and colorful, but also allows the interface to be designed separately from the logic to facilitate debugging,
In addition, the interface design is irrelevant to the platform. For example, on a Windows interface, you can use it on Unix or Linux without modifying any code.
Operating System.
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 hwnd winapi wnd_hook (hwnd, uint iMessage, uint wparam, long lparam, void * puserdata );
Parameters
The handle of the window where hwnd and HTML are 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 enables data communication between webpages and callers. There are four types of system events and countless types of events
When a custom event occurs, its 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.
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 is a pointer (or integer) that the caller sends to the callback function wnd_hook ).
The name of the lpwindowname window.

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

However, several formats of dwstyle are extended here, which can be used together.
Meaning
Ys_noescape prevents the dialog box from exiting with the ESC key.
Ys_modeless makes the dialog box non-modal.
You can right-click the ys_rbut dialog box to exit.
Ys_nowrerr prevents the script error information in the dialog box from being written to the file Y. Err or J. Err.
Ys_thread parses the HTML text in the dialog box. After this style is set, the buttons before the webpage is called out will be lost.
X, Y, nwidth, and nheight define the position and size of the window. Its meaning is the same as that in the Win32 function createmediawex.
Hwndparent parent window handle

/*************************************** **************************************** **********************************/
Webfile, weblen
When weblen = 0, webfile points to a file name, which is HTML text.
When weblen is greater than 0, webfile points to a buffer zone where HTML text is stored and the buffer length is weblen bytes.

Return Value
When the dialog box is a modal dialog box, the return value is always null, so the return value is useless.

When the dialog box is not a modal dialog box, the return value is the window handle of the dialog box.

/*************************************** **************************************** **********************************/
Example:
/*************************************** **************************************** **********************************/
In this example, if you use VC ++ to run the program, you need to download the latest YC ++, because the latest YC ++ provides the Library Link file: yxbapi. Lib
Otherwise, you need to change the program. The latest YC ++ may not be downloaded until May 24.
In this example, You need to upload the following seven files of YC ++ to your directory:

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

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 any file, such as blogtailcpp.
In YC ++, use <file/open or create CPP source program> to call blog1_cpp, and then run <tool/execute> blog1_cpp
In dos, use ycc blog1_cpp to generate blog20.exe, and then run blog20.exe
In VC ++, use Cl blog1_cpp to generate blog20.exe, and then run blog20.exe
/*************************************** **************************************** **********************************/
# Include <windows. h>

# Pragma comment (Lib, "gdi32.lib ")
# Pragma comment (Lib, "user32.lib ")
# Pragma comment (Lib, "yxbapi. lib ")

# Ifndef ycc
# Include "include/ycapi. H"
# Endif

# Define var const int

VaR id_find_ OK = 0;
VaR id_find_setcaps = 1;
VaR id_find_setbinary = 2;
VaR id_find_getcaps = 3;
VaR id_find_getbinary = 4;
VaR id_find_setfindbuf = 5;
VaR id_find_init = 6;

Int winapi winmain (hinstance, hinstance hprevinstance, lpstr lpcmdline, int nshowcmd)
{
Int winapi mainwndproc (hwnd, uint iMessage, uint wparam, long lparam, void * puserdata );
Hwnd = yxb_window (mainwndproc, null, 0, // create a normal window for the API function of YC, it does not need to be registered
Ws_overlappedwindow | ws_caption | ws_sysmenu,
"A", 110,50, 800,600, null, wt_win );

Int winapi find_hook (hwnd, uint iMessage, uint wparam, long lparam, void * puserdata );
Yxb_dialog (find_hook, null, 0,0, null, 250,200, 0, 0, hwnd, "find.htm", 0 );

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

Return 0;
}

Int winapi find_hook (hwnd, uint iMessage, uint wparam, long lparam, void * puserdata)
{
Switch (iMessage)
{
Case id_find_init:
Yxb_runjscript (hwnd, "dialog_init ('Hello! ')");
Break;
Case id_find_getcaps: return 1;
Case id_find_getbinary: Return 0;
Case id_find_setcaps: break;
Case id_find_setbinary: break;
Case id_find_setfindbuf:
Break;
Case id_find_ OK: break;
Case ym_close:
Break;
}
Return 0;
}

//////////////////////////////////////// //////////////////////////////////////// ////////////////////////////////////
Int winapi mainwndproc (hwnd, uint iMessage, uint wparam, long lparam, void * puserdata)
{
Switch (iMessage)
{
Case wm_destroy: postquitmessage (0); Return false;

Case wm_keydown:
If (wparam = vk_escape) destroywindow (hwnd );
Yxb_dialog (find_hook, null, 0,0, null, 250,200, 0, 0, hwnd, "find.htm", 0 );
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.

Rect mrect;
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: find.htm
/*************************************** **************************************** **********************************/

<Body onload = body_onload () onUnload = cancel_onclick () style = "overflow: auto;">

<! --/////////////////////////////////////// //////////////////////////////////////// /// // -->
<Script language = ycscript>

Static char code_buf [8192];

Char * hex_to_char (char * cbuf, int Len)
{
Char * TMP = code_buf;
If (LEN % 2) {cbuf [Len] = '0'; Len ++ ;}
Byte Uu, vv;
For (int kk = 0; KK <Len ;)
{
UU = cbuf [Kk ++];
VV = cbuf [Kk ++];
If (UU> = 'A') Uu-= ('A'-10 );
Else Uu-= '0 ';
If (VV> = 'A') VV-= ('A'-10 );
Else VV-= '0 ';
* TMP ++ = (uu <4) & 0xf0) + (VV & 0x0f );
}
Char * mptr;
Yxb_escape (& mptr, code_buf, Len/2 );
Strcpy (code_buf, mptr );
Free (mptr );
Return code_buf;
}

//////////////////////////////////////// //////////////////////////////////////// ////////////////////
Void set_hex (byte Uu, char * TMP)
{
Byte nn = (UU> 4) & 0x0f;
If (NN <= 9) * TMP = nn + '0 ';
Else * TMP = nn-10 + 'a ';
TMP ++;
Nn = UU & 0x0f;
If (NN <= 9) * TMP = nn + '0 ';
Else * TMP = nn-10 + 'a ';
}

Char * char_to_hex (char * cbuf, int Len)
{
# Define hz_first_byte 0x81
# Define hz_second_byte 0x40
# Define hz_second_x 0x7f
# Define hz_exclude_x 0xff
# Define is_hztwochar (Uu, vv) (UU)> = hz_first_byte &&/
(Uu )! = Hz_exclude_x &&/
(Vv)> = hz_second_byte & (vv )! = Hz_second_x & (vv )! = Hz_exclude_x)

Char * TMP = code_buf;
For (int cnt = 0; CNT <Len; CNT ++)
{
Byte Uu, VV, nn;
UU = * cbuf ++;
Set_hex (Uu, TMP );
TMP + = 2;
VV = * cbuf;
If (is_hztwochar (Uu, vv ))
{
Cbuf ++;
Set_hex (VV, TMP );
TMP + = 2;
}
}
* TMP = 0;
Return code_buf;
}
</SCRIPT>

<! --/////////////////////////////////////// //////////////////////////////////////// /// // -->
<Div id = findwhat style = "font-size: 16; position: absolute; left = 32; Top = 18;">
Search content:
</Div>

<Input id = find checked style = "font-size: 16; position: absolute;">
<Div id = findbin nowrap style = "font-size: 16; position: absolute; Background-color: # BBB;"> </div>

<Input id = caps color = #880000 type = checkbox style = "position: absolute;
Dbackground-color: #2a9;
Dbackground-image: url(z_prompt.jpg );
Dwidth = 26;
Dheight = 26;
">
<Input id = binary type = checkbox style = "position: absolute;">

<Div id = capstxt style = "font-size: 16; position: absolute; cursor = hand;">
Case Sensitive (F1)
</Div>

<Div id = binarytxt style = "font-size: 16; position: absolute; cursor = hand;">
Input binary code (F2)
</Div>

<Button id = OK onclick = OK _onclick () style = "font-size: 16; position: absolute;">
Confirm & nbsp
</Button>

<Button id = Cancel onclick = cancel_onclick () style = "font-size: 16; position: absolute;">
Cancel & nbsp
</Button>

<! --/////////////////////////////////////// //////////////////////////////////////// /// // -->
<Script language = JavaScript>
VaR id_find_ OK = 0;
VaR id_find_setcaps = 1;
VaR id_find_setbinary = 2;
VaR id_find_getcaps = 3;
VaR id_find_getbinary = 4;
VaR id_find_setfindbuf = 5;
VaR id_find_init = 6;

Window. resizeTo (526,232 );
Document. Title = "HTML dialog box ";

Finding. style. width = 448;
Find. style. Height = 26;
Find. style. Left = parseint (findwhat. style. Left)-2;
Find. style. color = "# ffffff ";
Find. style. backgroundcolor = "#505050 ";
Find. style. Top = parseint (findwhat. style. Top) + 22;

Findbin. style. Left = find. style. Left;
Findbin. style. Top = parseint (find. style. Top) + parseint (find. style. Height) + 10;

Caps. style. Top = binary. style. Top = 100;
Caps. style. Left = 30;
Binary. style. Left = 260;

Capstxt. style. Top = binarytxt. style. Top = caps. style. Top + 2;
Capstxt. style. Left = caps. style. Left + 25;
Binarytxt. style. Left = binary. style. Left + 25;

OK. style. width = Cancel. style. width = 100;
OK. style. Height = Cancel. style. Height = 28;
OK. style. Top = Cancel. style. Top = caps. style. Top + 43;
OK. style. Left = 120;
Cancel. style. Left = 300;

//////////////////////////////////////// //////////////////////////////////////// ////////////////////
Function OK _onclick ()
{
Ret_value ();
Hook (id_find_ OK );
Window. Close ();
}

//////////////////////////////////////// //////////////////////////////////////// ////////////////////
Function cancel_onclick ()
{
Ret_value ();
Window. Close ();
}

//////////////////////////////////////// //////////////////////////////////////// ////////////////////
Function set_state ()
{
Capstxt. style. Color = caps. checked? "# D00": "#000 ";
Binarytxt. style. Color = binary. checked? "# D00": "#000 ";
}

//////////////////////////////////////// //////////////////////////////////////// ////////////////////
Capstxt. onmousedown = capstxt_mouse_down;
Function capstxt_mouse_down ()
{
Caps. Checked =! Caps. checked;
Set_state ();
}

//////////////////////////////////////// //////////////////////////////////////// ////////////////////
Binarytxt. onmousedown = binarytxt_mouse_down;
Function binarytxt_mouse_down ()
{
Binary. Checked =! Binary. checked;
Binary_onmouseup ();
}

//////////////////////////////////////// //////////////////////////////////////// ////////////////////
Caps. onmouseup = caps_onmouseup;
Function caps_onmouseup ()
{
Set_state ();
}

//////////////////////////////////////// //////////////////////////////////////// ////////////////////
VaR vk_space = 0x20;
VaR vk_tab = 0x09;
VaR vk_return = 0x0d;
VaR vk_f2 = 0x71;
VaR vk_f1 = 0x70;

//////////////////////////////////////// //////////////////////////////////////// ////////////////////
Document. onkeypress = js_onkeypress;
Function js_onkeypress ()
{
If (Binary. Checked & event. keycode> = vk_space)
{
If (event. keycode> = "A". charcodeat () & event. keycode <= "f". charcodeat () return event. keycode-vk_space;
If (event. keycode> = "A". charcodeat () & event. keycode <= "f". charcodeat ())
| (Event. keycode> = "0". charcodeat () & event. keycode <= "9". charcodeat () return true;
Messagebeep (0 );
Return false;
}
}

//////////////////////////////////////// //////////////////////////////////////// ////////////////////
Document. onkeypressafter = js_onkeypressafter;
Function js_onkeypressafter ()
{
If (event. keycode> = vk_space) wr_bin ();
}

//////////////////////////////////////// //////////////////////////////////////// ////////////////////
Document. onkeydownafter = js_onkeydownafter;
Function js_onkeydownafter ()
{
If (event. keycode <vk_space | event. keycode = 0x2e | event. keycode = 0x2d) wr_bin ();
}

//////////////////////////////////////// //////////////////////////////////////// ////////////////////
Function wr_bin ()
{
If (! Binary. Checked) findbin. innertext = char_to_hex (find. Value, find. value. Length );
Else findbin. innertext = Unescape (hex_to_char (find. Value, find. value. Length ));
}

//////////////////////////////////////// //////////////////////////////////////// ////////////////////
Document. onkeydown = doc_onkeydown;
Function doc_onkeydown ()
{
If (event. keycode = vk_return) OK _onclick ();
If (event. keycode = vk_f1 &&! Event. shiftkey) capstxt_mouse_down ();
If (event. keycode = vk_f2 &&! Event. shiftkey) binarytxt_mouse_down ();
If (event. keycode = vk_tab) return false;
}

//////////////////////////////////////// //////////////////////////////////////// ////////////////////
Document. Body. onmouseup = body_onmouseup;
Function body_onmouseup ()
{
Find. Focus ();
}

//////////////////////////////////////// //////////////////////////////////////// ////////////////////
Binary. onmouseup = binary_onmouseup;
Function binary_onmouseup ()
{
Mptr = find. value;
If (Binary. Checked) find. value = char_to_hex (mptr, mptr. Length );
Else find. value = Unescape (hex_to_char (mptr, mptr. Length ));
Findbin. innertext = mptr;

Set_state ();
}

//////////////////////////////////////// //////////////////////////////////////// ////////////////////
Function ret_value ()
{
Hook (id_find_setcaps, caps. Checked );
Hook (id_find_setbinary, binary. Checked );
Editptr = find. value;
If (Binary. Checked) editptr = Unescape (hex_to_char (editptr, editptr. Length ));
Hook (id_find_setfindbuf, escape (editptr ));
}

//////////////////////////////////////// //////////////////////////////////////// ////////////////////
Function body_onload ()
{
Caps. Checked = hook (id_find_getcaps );
Binary. Checked = hook (id_find_getbinary );
Set_state ();
Find. Focus ();
If (Hook (id_find_init) window. Close ();
Wr_bin ();
}

//////////////////////////////////////// //////////////////////////////////////// ////////////////////
Function dialog_init (S0)
{
Mptr = S0;
Find. value = binary. checked? Char_to_hex (mptr, mptr. Length): mptr;
}

</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.