// Testw. cpp: defines the entry point of the application.
//
# Include "stdafx. H"
# Include "testw. H"
# Include <windows. h>
# Include <commctrl. h>
# Define max_loadstring 100
// Global variables:
Hwnd hwndlist = NULL;
Hinstance g_hinst; // current instance
Hwnd g_hwndmenubar; // menu bar handle
// The Forward Declaration of the functions contained in this Code module:
Atom myregisterclass (hinstance, lptstr );
Bool initinstance (hinstance, INT );
Lresult callback wndproc (hwnd, uint, wparam, lparam );
Int_ptr callback about (hwnd, uint, wparam, lparam );
Int winapi winmain (hinstance,
Hinstance hprevinstance,
Lptstr lpcmdline,
Int ncmdshow)
{
MSG;
// Execute application initialization:
If (! Initinstance (hinstance, ncmdshow ))
{
Return false;
}
Haccel hacceltable;
Hacceltable = loadaccelerators (hinstance, makeintresource (idc_testw ));
// Main message loop:
While (getmessage (& MSG, null, 0, 0 ))
{
If (! Translateaccelerator (msg. hwnd, hacceltable, & MSG ))
{
Translatemessage (& MSG );
Dispatchmessage (& MSG );
}
}
Return (INT) msg. wparam;
}
//
// Function: myregisterclass ()
//
// Purpose: register the window class.
//
// Note:
//
Atom myregisterclass (hinstance, lptstr szwindowclass)
{
Wndclass WC;
WC. Style = cs_hredraw | cs_vredraw;
WC. lpfnwndproc = wndproc;
WC. cbclsextra = 0;
WC. cbwndextra = 0;
WC. hinstance = hinstance;
WC. hicon = loadicon (hinstance, makeintresource (idi_testw ));
WC. hcursor = 0;
WC. hbrbackground = (hbrush) getstockobject (white_brush );
WC. lpszmenuname = 0;
WC. lpszclassname = szwindowclass;
Return registerclass (& WC );
}
//
// Function: initinstance (hinstance, INT)
//
// Purpose: Save the instance handle and create the Main Window
//
// Note:
//
// In this function, we save the instance handle in the global variable and
// Create and display the main program window.
//
Bool initinstance (hinstance, int ncmdshow)
{
Hwnd;
Tchar sztitle [max_loadstring]; // Title Bar text
Tchar szwindowclass [max_loadstring]; // main window class name
G_hinst = hinstance; // store the instance handle in a global variable
// During application initialization, shinitextracontrols should be called once to initialize
// All device-specific controls, such as capedit and sippref.
Shinitextracontrols ();
Loadstring (hinstance, ids_app_title, sztitle, max_loadstring );
Loadstring (hinstance, idc_testw, szwindowclass, max_loadstring );
// If it is already running, focus on the window and exit
Hwnd = findwindow (szwindowclass, sztitle );
If (hwnd)
{
// Child window with focus at the beginning
// "| 0x00000001" is used to place all affiliated windows at the front end and
// Activate these windows.
Setforegroundwindow (hwnd) (ulong) hwnd | 0x00000001 ));
Return 0;
}
If (! Myregisterclass (hinstance, szwindowclass ))
{
Return false;
}
Hwnd = createwindow (szwindowclass, sztitle, ws_visible,
Cw_usedefault, null, null, hinstance, null );
If (! Hwnd)
{
Return false;
}
// When you use cw_usedefault to create the main window, the height of the menu bar is not taken into account (if
// Menu bar ). Therefore, we need to resize the window after creating it.
// If the menu bar exists
If (g_hwndmenubar)
{
Rect RC;
Rect rcmenubar;
Getwindowrect (hwnd, & rc );
Getwindowrect (g_hwndmenubar, & rcmenubar );
RC. Bottom-= (rcmenubar. Bottom-rcmenubar. Top );
Movewindow (hwnd, RC. Left, RC. Top, RC. right-rc.left, RC. bottom-rc.top, false );
}
Showwindow (hwnd, ncmdshow );
Updatewindow (hwnd );
Return true;
}
//
// Function: wndproc (hwnd, uint, wparam, lparam)
//
// Purpose: to process messages in the main window.
//
// Wm_command-process application menu
// Wm_paint-draws the Main Window
// Wm_destroy-Send the Exit message and return
//
//
Lresult callback wndproc (hwnd, uint message, wparam, lparam)
{
Int wmid, wmevent;
Paintstruct pS;
HDC;
Static shactivateinfo s_sai;
//////////////////////////////////////// //////////////////////////////////
Lvcolumn colinfo = {0 };
//////////////////////////////////////// //////////////////////////////////
Switch (Message)
{
Case wm_command:
Wmid = loword (wparam );
Wmevent = hiword (wparam );
// Select the analysis menu:
Switch (wmid)
{
Case idm_help_about:
Dialogbox (g_hinst, (lpctstr) idd_aboutbox, hwnd, about );
Break;
Case idm_ OK:
Sendmessage (hwnd, wm_close, 0, 0 );
Break;
Default:
Return defwindowproc (hwnd, message, wparam, lparam );
}
Break;
Case wm_create:
{
Shmenubarinfo MBI;
Memset (& MBI, 0, sizeof (shmenubarinfo ));
MBI. cbsize = sizeof (shmenubarinfo );
MBI. hwndparent = hwnd;
MBI. ntoolbarid = idr_menu;
MBI. hinstres = g_hinst;
If (! Shcreatemenubar (& MBI ))
{
G_hwndmenubar = NULL;
}
Else
{
G_hwndmenubar = MBI. hwndmb;
}
// Initialize the shell activation information structure
Memset (& s_sai, 0, sizeof (s_sai ));
S_sai.cbsize = sizeof (s_sai );
// Create a column header
Rect rcmenubar;
Getwindowrect (g_hwndmenubar, & rcmenubar );
Rect;
Getclientrect (hwnd, & rect );
Rect. Bottom-= (rcmenubar. Bottom-rcmenubar. Top );
Hwndlist = createwindow (wc_listview,
Wc_listview,
Ws_child | ws_visible | ws_clipsiblings | ws_clipchildren |
Lvs_report | lvs_autoarrange | lvs_showselalways | lvs_#imagelists | lvs_singlesel,
0,
0,
Rect. Right,
Rect. Bottom-1,
Hwnd,
Null,
G_hinst,
Null
);
Listview_setbkcolor (hwndlist, RGB (0, 0 ));
Sendmessage (hwndlist, lvm_settextcolor, 0, RGB (255,255,255); // set the text background
Sendmessage (hwndlist, lvm_settextbkcolor, 0, clr_none); // make the background color of the text transparent
// Sendmessage (hwndlist, lvm_setbkcolor, 0, clr_none); // sets the image background to transparent.
Setfocus (hwndlist );
Setbkcolor (getdc (hwndlist), RGB (100,0, 0 ));
Tchar rgtsz [3] [10] = {_ T ("column header 1"), _ T ("column header 2 "), _ T ("column header 3 ")};
For (INT I = 0; I <3; I ++)
{
Colinfo. Mask = lvcf_text | lvcf_width | lvcf_fmt | lvcf_subitem;
Colinfo. isubitem = I; // specifies the column number.
// Colinfo. iorder = 0; // The number of columns displayed.
Colinfo. FMT = lvcfmt_left;
Colinfo. Cx = (rect. right-rect.left)/3;
Colinfo. psztext = rgtsz [I];
Colinfo. cchtextmax = 50;
Listview_insertcolumn (hwndlist, I, & colinfo );
Sendmessage (hwndlist, lvm_setextendedlistviewstyle, lvs_ex_fullrowselect, lvs_ex_fullrowselect); // you can specify whether to select a forward row.
// Sendmessage (hwndlist, lvm_insertcolumn, wparam (I), lparam (& colinfo ));
}
// Listview_setextendedlistviewstyle (hwndlist, lvs_ex_checkboxes); // Add a check box to each row
// Add data
Lvitem lvcolinfo = {0 };
Tchar lvrgtsz [3] [20] = {_ T ("content 1"), _ T ("content 2"), _ T ("content 3 ")};
Tchar data [4] [10] = {_ T ("inner 1"), _ T ("inner 2"), _ T ("inner 3 "), _ T ("inner 4 ")};
For (INT I = 0; I <4; I ++)
{
Lvcolinfo. iItem = I;
Lvcolinfo. Mask = lvif_text;
Lvcolinfo. isubitem = 0;
Lvcolinfo. psztext = lvrgtsz [I];
Lvcolinfo. cchtextmax = 50;
Sendmessage (hwndlist, lvm_insertitem, 0, lparam (& lvcolinfo ));
For (Int J = 1; j <4; j ++)
{
Lvitem lvitemdata = {0 };
// Lvitemdata. iItem = I;
// Lvitemdata. Mask = lvif_text;
// Lvitemdata. isubitem = J;
// Lvitemdata. psztext = data [J];
// Lvitemdata. cchtextmax = 50;
// Sendmessage (hwndlist, lvm_setitemtext, wparam (I), lparam (& lvitemdata ));
Listview_setitemtext (hwndlist, I, j, data [J]);
}
// Sendmessage (hwndlist, lvm_insertitem, 0, lparam (& lvcolinfo ));
// Listview_insertitem (hwndlist, & lvcolinfo );
}
// Listview_deleteitem (hwndlist, 1); // delete a row
// Listview_deletecolumn (hwndlist, 1); // delete a column
// Listview_deleteallitems (hwndlist); // delete all rows
}
Break;
Case wm_paint:
{
HDC = beginpaint (hwnd, & PS );
// Todo: add any drawing code here...
Endpaint (hwnd, & PS );
}
Break;
Case wm_destroy:
Commandbar_destroy (g_hwndmenubar );
Postquitmessage (0 );
Break;
Case wm_activate:
// Notify the shell of our activation message
Shhandlewmactivate (hwnd, wparam, lparam, & s_sai, false );
Break;
Case wm_settingchange:
Shhandlewmsettingchange (hwnd, wparam, lparam, & s_sai );
Break;
Default:
Return defwindowproc (hwnd, message, wparam, lparam );
}
Return 0;
}
// Message processing program in the "about" box.
Int_ptr callback about (hwnd hdlg, uint message, wparam, lparam)
{
Switch (Message)
{
Case wm_initdialog:
{
// Create a "finish" button and adjust its size.
Shinitdlginfo Shidi;
Shidi. dwmask = shidim_flags;
Shidi. dwflags = shidif_donebutton | shidif_sipdown | shidif_sizedlgfullscreen | shidif_emptymenu;
Shidi. hdlg = hdlg;
Shinitdialog (& Shidi );
}
Return (int_ptr) true;
Case wm_command:
If (loword (wparam) = idok)
{
Enddialog (hdlg, loword (wparam ));
Return true;
}
Break;
Case wm_close:
Enddialog (hdlg, message );
Return true;
# Ifdef _ device_resolution_aware
Case wm_size:
{
Dra: relayoutdialog (
G_hinst,
Hdlg,
Dra: getdisplaymode ()! = DRA: portrait? Makeintresource (idd_aboutbox_wide): makeintresource (idd_aboutbox ));
}
Break;
# Endif
}
Return (int_ptr) false;
}