Windows artboard program based on Win32

Source: Internet
Author: User

The function is designed as follows:

1.Graphics Menu can choose Graphics, support rectangle, Circle, line, select the corresponding graphics, then the corresponding menu item is preceded by a check mark;

the following options are included in the 2.Options menu   A.color, set the color, check this box to pop up as shown in the dialog


When you enter the dialog box, the default value is the current color, and when you click OK, the current foreground and fill colors are plotted with the selected color    B.width Set the width of the line, select this to bring up the following dialog box


into In the dialog box, the default value is the width value that is currently used, and when you click the OK button, the current width value is plotted as a set value, with a width value range of 1-10 (note: Each time you open this dialog box, the value of the width currently in use is displayed)

C. Filland opaque, set the fill, fill indicates fill, opaque is transparent, the two items are two selected, and when selected, the corresponding item is preceded by a check mark

3. Draw the operation, click the left mouse button, left button press, move the mouse, then the left key coordinate point and the current mouse coordinate point between two points to draw the corresponding selected graphics.

4.Operation Menu

  a.reverse menu item (shortcut CTRL + R), performing a 180-degree flip of the graphic in the horizontal direction

b.reset menu item (shortcut CTRL + S) to restore a graphic from a rollover state to a normal state

5. The right-click shortcut menu is the same as A/b in 4

Program source code:

Exam.cpp:Defines the entry point for the application.//#include "stdafx.h" #include "resource.h" #include <windows.h > #include <stdlib.h> #include <string.h> #include <commdlg.h> #include <commctrl.h> #define Max_loadstring 100//Global variables:hinstance hinst;//current Instancetchar sztitle[max_loadstring];//the title bar T Exttchar szwindowclass[max_loadstring];//the title bar Textchoosecolor Chc;bool Isdraw=false;bool IsReverse=false;int g_icount=0; RECT Rect1;int graphics=0; COLORREF Clref[16]={0x00ff0000};bool isfill=false;intiwidth=0;struct datastore//Graphics data storage structure {RECT rect1;//start, end int graphics;//shape COLORREF pcolor;//brush color bool isfill;//brush style int iwidth;//brush width//int bcolor;//paint brush Color};struct DATASTORE datastore[1000];//foward declarations of functions included in this Code Module:atommyregisterclass (hinstance hinstance ); Boolinitinstance (HINSTANCE, int.); LRESULT Callbackwndproc (HWND, UINT, WPARAM, LPARAM); LRESULT callbackabout (HWND, UINT, WPARAM, LPARAM); LRESULT Callbackwidth (HWND, UINT, WPARAM, LPARAM); int apientry WinMain (hinstance hinstance, hinstance Hprevin Stance, LPSTR lpcmdline, int ncmdshow) {//Todo:place code here. MSG msg; Haccel hacceltable;//Initialize Global stringsloadstring (hinstance, Ids_app_title, SzTitle, max_loadstring); LoadString (HInstance, Idc_exam, Szwindowclass, max_loadstring); MyRegisterClass (HINSTANCE);//Perform application Initialization:if (! InitInstance (HINSTANCE, nCmdShow)) {return FALSE;} hacceltable = Loadaccelerators (hinstance, (LPCTSTR) idc_exam);//Main Message Loop:while (GetMessage (&msg, NULL, 0, 0 ) {if (! TranslateAccelerator (Msg.hwnd, hacceltable, &msg)) {TranslateMessage (&msg);D ispatchmessage (&msg);}} return Msg.wparam;} Function:myregisterclass ()////purpose:registers the window class.////comments:////this function and its US Age was only necessary if you want this code//to be compatible with Win32 SystEMS prior to the ' registerclassex '//function is added to Windows 95.  It's important to call this function//so the application would get ' well formed ' small icons associated//with It.//atom MyRegisterClass (hinstance hinstance) {wndclassex wcex;wcex.cbsize = sizeof (wndclassex); wcex.style= CS_ Hredraw | Cs_vredraw;wcex.lpfnwndproc= (WNDPROC) wndproc;wcex.cbclsextra= 0;wcex.cbwndextra= 0;wcex.hinstance= hInstance; Wcex.hicon= LoadIcon (hinstance, (LPCTSTR) idi_exam); wcex.hcursor= loadcursor (NULL, Idc_arrow); Wcex.hbrBackground= ( Hbrush) (color_window+1); Wcex.lpszmenuname= (LPCSTR) idc_exam;wcex.lpszclassname= szwindowclass;wcex.hiconsm= LoadIcon (Wcex.hinstance, (LPCTSTR) idi_small); return RegisterClassEx (&wcex);} Function:initinstance (HANDLE, int)////Purpose:saves instance HANDLE and creates main window////comments:/// /In this function, we save the instance handle in a global variable and//create and display the main progr Am Window.//bool IniTinstance (hinstance hinstance, int ncmdshow) {HWND hwnd; HInst = hinstance; Store instance handle in our global variable hWnd = CreateWindow (Szwindowclass, SzTitle, Ws_overlappedwindow, CW   _usedefault, 0, cw_usedefault, 0, NULL, NULL, HINSTANCE, NULL);   if (!hwnd) {return FALSE;   } ShowWindow (HWnd, ncmdshow);   UpdateWindow (HWND); return TRUE;} Function:wndproc (HWND, unsigned, WORD, LONG)////purpose:processes messages for the main window.////wm_command  -Process the application menu//wm_paint-paint the main window//wm_destroy-post a quit message and Return////lresult CALLBACK WndProc (HWND hwnd, UINT message, WPARAM WPARAM, LPARAM LPARAM) {int wmid, wmevent; Paintstruct PS; HDC hdc; Hbrush Hbrush; Hpen Hpen; HMENU HMENU; TCHAR szhello[max_loadstring]; LoadString (HInst, Ids_hello, Szhello, max_loadstring); WORD x,y;x = LoWord (LParam);//Gets the position of the mouse. Y = HiWord (LParam); Hmenu=getmenu (hWnd); switch (message) {case wm_create:// Select Color Common dialog box Chc.lstructsize = sizeof (CHOOsecolor);//Structure size Chc.hwndowner = hwnd;//parent Window Handle chc.rgbresult = 0;//Set default color chc.lpcustcolors = clref;//Pointer to user-defined array of colors CHC. Flags = 0;//Flag Chc.lcustdata = 0;chc.lpfnhook = null;//hook function pointer. Same As dialog box handler function Chc.lptemplatename = Null;break;case wm_ Command:wmid = LoWord (WParam); Wmevent = HiWord (WParam); Parse the menu Selections:switch (wmid) {case Idm_rectangle:checkmenuitem (hmenu,idm_rectangle,mf_checked); Checkmenuitem (hmenu,idm_circle,mf_unchecked); Checkmenuitem (hmenu,idm_line,mf_unchecked); Graphics=2;break;case Idm_circle:checkmenuitem (hmenu,idm_circle,mf_checked); Checkmenuitem (hmenu,idm_rectangle,mf_unchecked); Checkmenuitem (hmenu,idm_line,mf_unchecked); Graphics=1;break;case Idm_line:checkmenuitem (hmenu,idm_line,mf_checked); Checkmenuitem (hmenu,idm_rectangle,mf_unchecked); Checkmenuitem (hmenu,idm_circle,mf_unchecked); Graphics=0;break;case Idm_color:choosecolor (&AMP;CHC); Break;case Idm_width:dialogbox (HInst, (LPCTSTR) IDD_WIDTH, HWnd, (Dlgproc) Width); Break;case Idm_fill:checkmenuitem (Hmenu,idm_fill,mf_checked); Checkmenuitem (hmenu,idm_opaque,mf_unchecked); Isfill=true;break;case Idm_opaque:checkmenuitem (HMenu,IDM_OPAQUE, mf_checked); Checkmenuitem (hmenu,idm_fill,mf_unchecked); Isfill=false;break;case Idm_reverse:isreverse=true;invalidaterect (   hwnd,null,true); break;case idm_reset:isreverse=false;invalidaterect (hwnd,null,true); Break;case IDM_ABOUT:   DialogBox (HInst, (LPCTSTR) Idd_aboutbox, HWnd, (Dlgproc) about);   Break;case Idm_exit:destroywindow (HWND); Break;default:return DefWindowProc (hWnd, message, WParam, LParam);} Break;case Wm_lbuttondown:isdraw=true;rect1.left = X;rect1.top = Y;//movetoex (hdc,rect1.left = X,rect1.top = Y,NULL); Break;case Wm_lbuttonup:datastore[g_icount].rect1 = Rect1;//datastore[g_icount].ptend = PtEnd;DataStore[g_iCount]. Graphics = Graphics;datastore[g_icount].pcolor = Chc.rgbresult;datastore[g_icount]. Isfill = Isfill;datastore[g_icount].iwidth = Iwidth;//datastore[g_icount].bcolor = bselection;g_icount++;isdraw= False;break;case WM_MOUSEMOVE:rect1.right= X;rect1.bottom = Y;if (isdraw==true) {invalidaterect (hwnd,null,true);//redraw information is emitted. UpdateWindow (hWnd);} Break;case wm_rbuttondown:point Point;point.x=loword (lParam);p Oint.y=hiword (LParam); ClientToScreen (Hwnd,&point); TrackPopupMenu (GetSubMenu (hmenu,3), tpm_leftalign,point.x,point.y,0,hwnd,null); Break;case WM_PAINT:hDC = BeginPaint (HWnd, &ps); RECT RT; GetClientRect (HWnd, &AMP;RT); Setmapmode (Hdc,mm_anisotropic);  Setviewportorgex (HDC, (rt.left+rt.right)/2, (Rt.bottom+rt.right)/2,null); Setviewportorgex (Hdc,0,0,null); int i;for (i = 0; I <g_iCount; i++) {if (isreverse==true) {Setviewportextex (hdc,1,-1,0); Setviewportorgex (Hdc,0,rt.bottom-rt.top, NULL);} Else{setviewportextex (hdc,1,1,0); Setviewportorgex (hdc,0,0,null);} Hpen=createpen (Ps_solid,datastore[i].iwidth,datastore[i].pcolor); if (Datastore[i]. Isfill==true) {Hbrush=createsolidbrush (datastore[i].pcolor);} Else{hbrush= (Hbrush) getstockobject (Null_brush);} SelectObject (Hdc,hbrush); SelectObject (Hdc,hpen); if (Datastore[i]. graphics==0) {Movetoex (hdc,datAstore[i].rect1.left,datastore[i].rect1.top,null); LineTo (Hdc,datastore[i].rect1.right,datastore[i].rect1.bottom);} if (Datastore[i]. Graphics==1) {Ellipse (Hdc,datastore[i].rect1.left,datastore[i].rect1.top,datastore[i].rect1.right,datastore[i]. Rect1.bottom);} if (Datastore[i]. graphics==2) {Rectangle (hdc,datastore[i].rect1.left,datastore[i].rect1.top,datastore[i].rect1.right,datastore[i ].rect1.bottom);} DeleteObject (Hpen);D eleteobject (hbrush);} Hpen=createpen (Ps_solid,iwidth,chc.rgbresult); if (isfill==true) {Hbrush=createsolidbrush (chc.rgbResult);} Else{hbrush= (Hbrush) getstockobject (Null_brush);} SelectObject (Hdc,hbrush); SelectObject (Hdc,hpen);//Todo:add any drawing code here...//drawtext (HDC, Szhello, strlen (Szhello), &rt, Dt_center if (isdraw==true) {if (graphics==0) {movetoex (hdc,rect1.left,rect1.top,null); LineTo (Hdc,rect1.right,rect1.bottom);} if (graphics==1) {Ellipse (hdc,rect1.left,rect1.top,rect1.right,rect1.bottom);} if (graphics==2) {Rectangle (hdc,rect1.left,rect1.top,rect1.right,rect1.bottom);}} DeleteObject (Hpen);D eleteobject (Hbrush); EndPaint (hwnd, &AMP;PS); Break;case wm_destroy:postquitmessage (0); Break;default:return DefWindowProc (hwnd, message,   WParam, LParam); } return 0;} Mesage handler for about box. LRESULT CALLBACK About (HWND hdlg, UINT message, WPARAM WPARAM, LPARAM LPARAM) {switch (message) {case Wm_initdialog:return T Rue;case wm_command:if (LoWord (wParam) = = IDOK | | LoWord (wParam) = = IDCANCEL) {EndDialog (hdlg, LoWord (WParam)); return TRUE;}    break;} return FALSE;} LRESULT CALLBACK Width (HWND hdlg, UINT message, WPARAM WPARAM, LPARAM LPARAM) {Hwndhwndslider=getdlgitem (hdlg, Idc_slider ); switch (message) {case Wm_initdialog:sendmessage (Hwndslider, tbm_setticfreq, 1, 0); SendMessage (Hwndslider, Tbm_setrange, 1, Makelong (1,10)); return true;case Wm_showwindow:sendmessagew (HWNDSLIDER,TBM _setpos, 1,iwidth);//Set slider control Break;case wm_command:if (LoWord (wParam) = = IDOK) {iwidth= Sendmessagew (Hwndslider, TBM _getpos, 0, 0); EndDialog (Hdlg, LoWord (WParam)); return TRUE;} if (LowORD (wParam) = = IDCANCEL) {EndDialog (hdlg, LoWord (WParam)); return TRUE;}    break;} return FALSE;}

  

Windows artboard program based on Win32

Related Article

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.