Don't read it!
I am an initiator of SDK, and I am ready to learn VC. I have experienced the pain of beginners of SDK. Many books on the book are some slightly complex programs. Therefore, I will debug some of the small programs, functionality, and attach the details of the procedure to help me.
/ Below is the program
/ * ------------------------------------------ This program is mainly practiced how to achieve Button Displays the effect of various button controls, the name on the control is the set style of the button.
----------------------------------------- * /
#include
// #define defined below specific values of the menu ID ID_PUSHME1 1 # define ID_PUSHME2 2 # define ID_PUSHME3 3 # define ID_PUSHME4 4 # define ID_PUSHME5 5 # define ID_PUSHME6 6 # define ID_PUSHME7 7 # define ID_PUSHME8 8 # define ID_PUSHME9 9 # define ID_PUSHME10 10 # Define ID_PUSHME11 11 # define id_pushme12 12
// Description of the window LRESULT CALLBACK WNDPROC (HWND, UINT, WPARAM, LPARAM);
/// Main function WinMain (), mainly used to create a main window, and establish a message loop mechanism // allows the system call window function WndProc () // During the Windows programming process, this function is basically the same // program members generally do not do too many changes int WINAPI WinMain (hINSTANCE hInstance, hINSTANCE hPrevInstance, PSTR szCmdLine, int iCmdShow) {static char szAppName [] = "About1"; mSG msg; HWND hwnd; // Register the window class WNDCLASSEX wndclass;
wndclass.cbSize = sizeof (wndclass); wndclass.style = CS_HREDRAW | CS_VREDRAW; wndclass.lpfnWndProc = WndProc; wndclass.cbClsExtra = 0; wndclass.cbWndExtra = 0; wndclass.hInstance = hInstance; wndclass.hIcon = LoadIcon (hInstance, szAppName ); wndclass.hCursor = LoadCursor (NULL, IDC_ARROW); wndclass.hbrBackground = (HBRUSH) GetStockObject (WHITE_BRUSH); wndclass.lpszMenuName = NULL; wndclass.lpszClassName = szAppName; wndclass.hIconSm = LoadIcon (hInstance, szAppName);
RegisterClassex (& WNDCLASS);
/ // Create the window hwnd = CreateWindow (szAppName, "controls to achieve", WS_OVERLAPPEDWINDOW, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, NULL, NULL, hInstance, NULL); / // display and update the window ShowWindow (hwnd, iCmdShow); UpdateWindow (HWND); // // Message Cycle Mechanism While (GetMessage (& MSG, NULL, 0, 0)) {TranslateMessage (& MSG); DispatchMessage (& MSG);} return msg.wparam; represents the value returned from postquitMessage
}
/// The following is a window function. Here is the main programmed place // programmers to set various effects according to various messages, here is also the place to learn SDK mainly to learn / LRESULT CALLBACK WNDPROC (hwnd hwnd, uint iMsg, WPARAM wParam, LPARAM lParam) {static hINSTANCE hInstance; // description of each menu handle static HWND hbtnWnd1, hbtnWnd2, hbtnWnd3, hbtnWnd4, hbtnWnd5, hbtnWnd6, hbtnWnd7, hbtnWnd8, hbtnWnd9, hbtnWnd10, hbtnWnd11, hbtnWnd12;
// The characters used in the program Define Static char text [] = "Set this button here for the EDIT type, indicating that the control is set to the edit box control, you can enter text"; switch (IMSG) {CASE WM_CREATE: HINSTANCE = ((LpCreateStruct) LParam -> Hinstance; HBTnWnd1 = CREATEWINDOW ("Button", // This type of setting button is Button, other types of static control static, // Scroll stroll strollbar, edit box control Edit, list Frame control Listbox
"BS_AUTOCHECKBOX", // Here you set the text BS_AUTOCHECKBOX | WS_CHILD | WS_VISIBLE, / / button style, where there must be a WS_CHILD style, because it is a sub-window, // You can set the button's style and window style parameters 10, 40, // (10, 40) For the upper left corner of the button, the width 30, // button of the // button hWnd, // parent window handle (HMENU) ID_PUSHME1, // Sub-window ID, That is, the button ID hinstance, // instance handle null); // Extra parameter // / / / / The definition of some buttons below is the same as the first button HBTnWnd1 above, // If you only want to define a button, 11 below The content of the button can be completely canceled // separately, pay attention to the position of each button, long width size is completely HBTnWnd2 = CreateWindow ("Button", "BS_Pushbutton", BS_Pushbutton | WS_CHILD | WS_VISIBLE, 180, 40, 160, 30, HWND, (HMENU) ID_PUSHME2, hInstance, NULL); hbtnWnd3 = CreateWindow ( "button", "BS_AUTORADIOBUTTON", BS_AUTORADIOBUTTON | WS_CHILD | WS_VISIBLE, 350, 40, 180, 30, hwnd, (HMENU) ID_PUSHME3, hInstance, NULL);
HBTnWnd4 = CreateWindow ("Button", "BS_CHECKBOX", BS_CHECKBOX | WS_CHILD | WS_Visible, 540, 40, 180, 30, hwnd, (hmenu) ID_PUSHME4, HINSTANCE, NULL);
hbtnWnd5 = CreateWindow ( "button", "BS_AUTO3STATE", BS_AUTO3STATE | WS_CHILD | WS_VISIBLE, 10, 80, 160, 30, hwnd, (HMENU) ID_PUSHME5, hInstance, NULL); hbtnWnd6 = CreateWindow ( "button", "BS_DEFPUSHBUTTON", BS_DEFPUSHBUTTON | WS_CHILD | WS_VISIBLE, 180, 80, 160, 30, hwnd, (HMENU) ID_PUSHME6, hInstance, NULL); hbtnWnd7 = CreateWindow ( "button", "BS_GROUPBOX", BS_GROUPBOX | WS_CHILD | WS_VISIBLE, 350, 80, 180, 30, hWnd, (hmenu) ID_PUSHME7, HINSTANCE, NULL
HBTnWnd8 = CreateWindow ("Button", "BS_LEFTText", BS_LEFTTEXT | WS_CHILD | WS_Visible, 540, 80, 180, 30, hwnd, (hmenu) ID_PUSHME8, HINSTANCE, NULL);
hbtnWnd9 = CreateWindow ( "button", "BS_RADIOBUTTON", BS_RADIOBUTTON | WS_CHILD | WS_VISIBLE, 10, 120, 160, 30, hwnd, (HMENU) ID_PUSHME9, hInstance, NULL); hbtnWnd10 = CreateWindow ( "button", "BS_3STATE", BS_3STATE | WS_CHILD | WS_Visible, 180, 120, 160, 30, hwnd, (hmenu) ID_PUSHME10, Hinstance, NULL;
HBTNWND11 = CREATEWINDOW ("scrollbar", // scroll strike control, click this button and drag the mouse to change the "BS_OWNERDRAW", // Custom Control BS_OWNERDRAW | WS_CHILD | WS_Visible, 350, 120, 180, 30, Hwnd , (HMENU) ID_PUSHME11, Hinstance, NULL;