Use the SDK dialog to change the background color and display the text file in the clipboard

xiaoxiao2021-03-05  29

Learn to summarize what you have learned every day and record it is a good habit! Hey ~ It seems that you have to cheer, don't write because you are too lazy! Jiang River is a stream collection! To achieve his own little dream, it is still diligent! There is not much time, and it is going to see PASS in half a semester. I feel fast now! Write to yourself: Believe in yourself, unremitting efforts, there is nothing impossible. Below is a dialogue applet generated by SDK does not generate a window, and some basic functions implemented directly using dialog boxes include changing background colors and displaying text files in the clipboard as follows:

#include #include "resource.h" ColorRef TempColor [3] = {RGB (120, 45, 128), RGB (0, 135, 189), RGB (200, 120, 123)}; static int color = 0; // Define Color / / Define Dialog Processing Functions Bool Callback Dialogfun (HWND, UINT, WPARAM, LPARAM);

Int WinApi Winmain (Hinstance Hinstance, Hinstance Hprevinstance, LPSTR LPCMDLINE, INT NCMDSHOW) {msg msg;

IF (100 == DialogBox (Hinstance, "MyDialog", NULL, (DLGPROC) Dialogfun) {PostQuitMessage (WM_QUIT);} While (GetMessage (& MSG, (HWND) NULL, 0, 0) {TranslateMessage (& MSG); DispatchMessage (& MSG);} Return Msg.wParam; Unreferenced_Parameter (LPCMDLINE);

}

Bool Callback Dialogfun (HWnd Dlghwnd, Uint Message, WPARAM WPARAM, LPARAM LPARAM) {

Switch (Message) {

Rect Rect; Case WM_PAINT:

PAINTSTRUCT ps; HDC hdc; HBRUSH brush, oldbrush; hdc = BeginPaint (dlghwnd, & ps); brush = CreateSolidBrush (tempcolor [color]); // Create a brush GetClientRect (dlghwnd, & rect); // get the main window area oldbrush = (Hbrush) SelectObject (HDC, Brush); Rectangle (HDC, Rect.Lect, Rect.top, Rect.right, Rect.Bottom); SelectObject (HDC, Oldbrush); Endpaint (DLGHWND, & PS); Return False;

Case WM_INITDIALOG: // ShowWindow (NULL, SW_SHOWNORMAL); RETURN FALSE; CASE WM_COMMAND: SWITCH (WPARAM) {CASE IDOK: EndDialog (DLGHWND, 100); // Definition 100 to determine exit dialog

return TRUE; case ID_CHANGECOLOR: color = 1; InvalidateRect (dlghwnd, NULL, FALSE); return TRUE; case ID_CHANGECOLOR2: color = 2; InvalidateRect (dlghwnd, NULL, FALSE); return TRUE; case ID_CHANGECOLOR3: color = 0; InvalidateRect ( dlghwnd, NULL, FALSE); return TRUE; case ID_PASTE: // HWND pasteHwnd; if (OpenClipboard (NULL)) // open clipboard {if (IsClipboardFormatAvailable (CF_TEXT)) {HANDLE hClip; char * pBuffer; hClip = GetClipboardData ( CF_TEXT); pBuffer = (char *) GlobalLock (hClip); GlobalUnlock (hClip); SetDlgItemText (dlghwnd, IDC_EDIT_PASTE, pBuffer);} else {MessageBox (dlghwnd, "your clipboard is not a text file", "there no text ", MB_OK);} closeclipboard (); // Close clipboard}} default: returnaf false;}}

转载请注明原文地址:https://www.9cbs.com/read-34235.html

New Post(0)