Split the ribs, only programs with the most basic Win32 architecture. Restore the true colors of programs under Win32 SDK!

Source: Internet
Author: User

Rewrite the self-developed generic. c

//---------------------------------------------------------------------
// File: Generic. c
// By gencheng
// Compile the connection: see generic. Mak
//---------------------------------------------------------------------

# Include <windows. h> // This header file is required for every Windows program.
# Include "resource. H" // contains resource IDS

Hinstance _ hinst; // instance handle
Hwnd _ hwnd;

Char _ szappname [] = "generic ";
Char _ sztitle [] = "base Win32 SDK application ";

//---------------------------------------------------------------------
// About-dialog box function
//---------------------------------------------------------------------
Lresult callback about (hwnd hdlg, uint message,
Wparam, lparam)
{
Unreferenced_parameter (lparam );

Switch (Message ){
Case wm_initdialog:
Return (true );

Case wm_command:
If (loword (wparam) = idok
| Loword (wparam) = idcancel ){
Enddialog (hdlg, true );
Return (true );
}
Break;
}
Return (false );
}

//---------------------------------------------------------------------
// Wndproc-Window Function
//---------------------------------------------------------------------
Lresult callback wndproc (hwnd, uint message, wparam, lparam)
{
Int wmid, wmevent;

Switch (Message ){
Case wm_command:

Wmid = loword (wparam );
Wmevent = hiword (wparam );

Switch (wmid ){
Case idm_about:
Dialogbox (_ hinst,
"Aboutbox ",
Hwnd,
(Dlgproc) about
);
Break;

Case idm_exit:
Destroywindow (hwnd );
Break;

Default:
Return (defwindowproc (hwnd, message, wparam, lparam ));
}
Break;
Case wm_lbuttondown:
MessageBox (hwnd, "Left click! "," Message ", mb_iconinformation );
Break;
Case wm_rbuttondown:
MessageBox (hwnd, "right-click! "," Message ", mb_iconinformation );
Break;

Case wm_destroy:
Postquitmessage (0 );
Break;
Default:
Return (defwindowproc (hwnd, message, wparam, lparam ));
}
Return (0 );
}

//---------------------------------------------------------------------
// Winmain-program entry point
//---------------------------------------------------------------------
Int callback winmain (hinstance, hinstance hprevinstance,
Lpstr lpcmdline, int ncmdshow)
{
MSG;
Wndclass WC;

Unreferenced_parameter (lpcmdline); // avoid warnings during compilation

WC. Style = cs_hredraw | cs_vredraw;
WC. lpfnwndproc = (wndproc) wndproc;
WC. cbclsextra = 0;
WC. cbwndextra = 0;
WC. hinstance = hinstance;
WC. hicon = loadicon (hinstance, "jjhouricon ");
WC. hcursor = loadcursor (null, idc_arrow );
WC. hbrbackground = getstockobject (white_brush); // the background color of the window.
WC. lpszmenuname = "genericmenu"; // The form defined by. RC
WC. lpszclassname = _ szappname;

Registerclass (& WC );

_ Hinst = hinstance; // It is stored as a global variable for ease of use.
_ Hwnd = createwindow (// createwindow ()
_ Szappname,
_ Sztitle,
Ws_overlappedwindow,
Cw_usedefault,
Cw_usedefault,
Cw_usedefault,
Cw_usedefault,
Null,
Null,
Hinstance,
Null
);

If (! _ Hwnd)
Return (false );

Showwindow (_ hwnd, ncmdshow );
Updatewindow (_ hwnd );

/* -- The following is the main message loop --*/
While (getmessage (& MSG, null, 0, 0 )){
Translatemessage (& MSG );
Dispatchmessage (& MSG );
}

Return (msg. wparam );
}

// ------------------------ End of file ------------------------------

I personally feel that the source program I modified is more concise than that of Hou Jie. It is basically built with Win32 SDK.

To sum up, you must use the following Win32 API to create a window:

Registerclass is the type of the registration window in the program window.

Createwindow creates a window based on the window type.

The showwindow is displayed on the screen.

Updatewindow indicates that the window is self-updated.

Getmessage obtains a message from the message queue.

Translatemessage translates some keyboard messages.

Dispatchmessage sends the message to the window message processing program.

Postquitmessage inserts an Exit message in the message queue.

Defwindowproc executes the specified message processing.

These functions are described in the msdn file, and are declared in different header files in VC. The vast majority of them are declared in winuser. h.

 

 

 

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.