?? mywindows.c
字號:
// $Id: mywindows.c,v 1.8 2000/11/28 06:41:32 ymwei Exp $//// mywindows.c: implementation file of libmywins library.//// Copyright (c) 2000, WEI Yongming// Copyright (C) 2000, BluePoint Software.//// Current maintainer: WEI Yongming.//// Create date: 2000.xx.xx/*** This library is free software; you can redistribute it and/or** modify it under the terms of the GNU Library General Public** License as published by the Free Software Foundation; either** version 2 of the License, or (at your option) any later version.**** This library is distributed in the hope that it will be useful,** but WITHOUT ANY WARRANTY; without even the implied warranty of** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU** Library General Public License for more details.**** You should have received a copy of the GNU Library General Public** License along with this library; if not, write to the Free** Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,** MA 02111-1307, USA*///// Modify records://// Who When Where For What Status//-----------------------------------------------------------------------------//// TODO://#include <stdio.h>#include <stdlib.h>#include <stdarg.h>#include <string.h>#include <pthread.h>#include <semaphore.h>#include <sys/stat.h>#include <sys/types.h>#include <unistd.h>#include <errno.h>#include "common.h"#include "minigui.h"#include "gdi.h"#include "window.h"#include "control.h"#include "mywindows.h"#ifndef lintstatic char fileid[]="$Id: mywindows.c,v 1.8 2000/11/28 06:41:32 ymwei Exp $";#endifvoid errorWindow(HWND hwnd, char* str, char* title){ char* a; if (!strstr (str, "%s")) { a = alloca (strlen (str) + 5); strcpy(a, str); strcat(a, ": %s"); str = a; } myMessageBox (hwnd, MB_OK | MB_ICONSTOP, title?title:"Error", str, strerror (errno));}int myMessageBox (HWND hwnd, DWORD dwStyle, char* title, char* text, ...){ char * buf = NULL; int size = 0; int i = 0; va_list args; int rc; va_start(args, text); do { size += 1000; if (buf) free(buf); buf = malloc(size); i = vsnprintf(buf, size, text, args); } while (i == size); va_end(args); rc = MessageBox (hwnd, buf, title, dwStyle); if (buf) free (buf); return rc;}DLGTEMPLATE DlgButtons ={ WS_BORDER | WS_CAPTION, WS_EX_NONE, (640 - 418)/2, (480 - 170)/2, 418, 170, NULL, 0, 0, 5, NULL, 0};#define IDC_BASE 100#define IDC_ONE 101#define IDC_TWO 102#define IDC_THREE 103CTRLDATA CtrlButtons [] ={ { "static", WS_VISIBLE | SS_ICON, 10, 10, 40, 40, IDC_STATIC, "LOGO", 0 }, { "static", WS_VISIBLE | SS_LEFT, 50, 10, 340, 90, IDC_STATIC, NULL, 0 }, { "button", WS_VISIBLE | BS_DEFPUSHBUTTON | WS_TABSTOP | WS_GROUP, 100, 110, 80, 24, IDC_ONE, NULL, 0 }, { "button", WS_VISIBLE | BS_PUSHBUTTON | WS_TABSTOP, 200, 110, 80, 24, IDC_TWO, NULL, 0 }, { "button", WS_VISIBLE | BS_PUSHBUTTON | WS_TABSTOP, 300, 110, 80, 24, IDC_THREE, NULL, 0 }};static int ButtonsBoxProc (HWND hDlg, int message, WPARAM wParam, LPARAM lParam){ switch (message) { case MSG_INITDIALOG: return 1; break; case MSG_COMMAND: if (wParam == IDC_ONE || wParam == IDC_TWO || wParam == IDC_THREE) EndDialog (hDlg, wParam); break; } return DefaultDialogProc (hDlg, message, wParam, lParam);}int myWinMessage (HWND hwnd, char* title, char* button1, char* text, ...){ char * buf = NULL; int size = 0; int i = 0; va_list args; int rc; va_start(args, text); do { size += 1000; if (buf) free(buf); buf = malloc(size); i = vsnprintf(buf, size, text, args); } while (i == size); va_end(args); DlgButtons.caption = title; DlgButtons.controls = CtrlButtons; DlgButtons.controlnr = 3; CtrlButtons [1].caption = buf; CtrlButtons [2].caption = button1; CtrlButtons [2].x = 300; CtrlButtons [0].dwAddData = GetLargeSystemIcon (IDI_APPLICATION); rc = DialogBoxIndirectParam (&DlgButtons, hwnd, ButtonsBoxProc, 0L); if (buf) free (buf); return rc - IDC_BASE;}int myWinChoice (HWND hwnd, char* title, char* button1, char* button2, char* text, ...){ char * buf = NULL; int size = 0; int i = 0; va_list args; int rc; va_start(args, text); do { size += 1000; if (buf) free(buf); buf = malloc(size); i = vsnprintf(buf, size, text, args); } while (i == size); va_end(args); DlgButtons.caption = title; DlgButtons.controls = CtrlButtons; DlgButtons.controlnr = 4; CtrlButtons [1].caption = buf; CtrlButtons [2].caption = button1; CtrlButtons [3].caption = button2; CtrlButtons [2].x = 200; CtrlButtons [3].x = 300; CtrlButtons [0].dwAddData = GetLargeSystemIcon (IDI_APPLICATION); rc = DialogBoxIndirectParam (&DlgButtons, hwnd, ButtonsBoxProc, 0L); if (buf) free (buf); return rc - IDC_BASE;}int myWinTernary (HWND hwnd, char* title, char* button1, char* button2, char* button3, char* text, ...){ char * buf = NULL; int size = 0; int i = 0; va_list args; int rc; va_start(args, text); do { size += 1000; if (buf) free(buf); buf = malloc(size); i = vsnprintf(buf, size, text, args); } while (i == size); va_end(args); DlgButtons.caption = title; DlgButtons.controls = CtrlButtons; DlgButtons.controlnr = 5; CtrlButtons [1].caption = buf; CtrlButtons [2].caption = button1; CtrlButtons [3].caption = button2; CtrlButtons [4].caption = button3; CtrlButtons [2].x = 100; CtrlButtons [3].x = 200; CtrlButtons [4].x = 300; CtrlButtons [0].dwAddData = GetLargeSystemIcon (IDI_APPLICATION); rc = DialogBoxIndirectParam (&DlgButtons, hwnd, ButtonsBoxProc, 0L); if (buf) free (buf); return rc - IDC_BASE;}static int StatusWinProc (HWND hWnd, int message, WPARAM wParam, LPARAM lParam){ switch (message) { case MSG_PAINT: { HDC hdc; char* text; RECT rc; hdc = BeginPaint (hWnd); text = (char*) GetWindowAdditionalData (hWnd); if (text) { GetClientRect (hWnd, &rc); SetBkColor (hdc, COLOR_lightgray); TextOut (hdc, 5, (rc.bottom - GetSysCharHeight())>>1, text); } EndPaint (hWnd, hdc); } return 0; } return DefaultMainWinProc(hWnd, message, wParam, lParam);}HWND createStatusWin (HWND hParentWnd, int width, int height, char* title, char* text, ...){ HWND hwnd; char* buf = NULL; int size = 0; int i = 0; va_list args; MAINWINCREATE CreateInfo; va_start (args, text); do { size += 1000; if (buf) free(buf); buf = malloc(size); i = vsnprintf(buf, size, text, args); } while (i == size); va_end(args); width = ClientWidthToWindowWidth (WS_CAPTION | WS_BORDER, width); height= ClientHeightToWindowHeight (WS_CAPTION | WS_BORDER, height, FALSE); CreateInfo.dwStyle = WS_CAPTION | WS_BORDER | WS_VISIBLE; CreateInfo.dwExStyle = WS_EX_NONE; CreateInfo.spCaption = title; CreateInfo.hMenu = 0; CreateInfo.hCursor = GetSystemCursor (IDC_WAIT); CreateInfo.hIcon = 0; CreateInfo.MainWindowProc = StatusWinProc; CreateInfo.lx = (GetGDCapability (HDC_SCREEN, GDCAP_MAXX) - width) >> 1; CreateInfo.ty = (GetGDCapability (HDC_SCREEN, GDCAP_MAXY) - height) >> 1; CreateInfo.rx = CreateInfo.lx + width; CreateInfo.by = CreateInfo.ty + height; CreateInfo.iBkColor = COLOR_lightgray; CreateInfo.dwAddData = (DWORD) buf; CreateInfo.hHosting = hParentWnd; hwnd = CreateMainWindow (&CreateInfo); if (hwnd == HWND_INVALID) return hwnd; UpdateWindow (hwnd, TRUE); return hwnd;}void destroyStatusWin (HWND hwnd){ char* buff; buff = (char*)GetWindowAdditionalData (hwnd); DestroyMainWindow (hwnd); MainWindowThreadCleanup (hwnd); free (buff);}HWND createProgressWin (HWND hParentWnd, char * title, char * label, int id, int range){ HWND hwnd; MAINWINCREATE CreateInfo; int ww, wh; HWND hStatic, hProgBar; ww = ClientWidthToWindowWidth (WS_CAPTION | WS_BORDER, 400); wh = ClientHeightToWindowHeight (WS_CAPTION | WS_BORDER, (range > 0) ? 70 : 35, FALSE); CreateInfo.dwStyle = WS_CAPTION | WS_BORDER | WS_VISIBLE; CreateInfo.dwExStyle = WS_EX_NONE; CreateInfo.spCaption = title; CreateInfo.hMenu = 0; CreateInfo.hCursor = GetSystemCursor(IDC_WAIT); CreateInfo.hIcon = 0; CreateInfo.MainWindowProc = DefaultMainWinProc; CreateInfo.lx = (GetGDCapability (HDC_SCREEN, GDCAP_MAXX) - ww) >> 1; CreateInfo.ty = (GetGDCapability (HDC_SCREEN, GDCAP_MAXY) - wh) >> 1; CreateInfo.rx = CreateInfo.lx + ww; CreateInfo.by = CreateInfo.ty + wh; CreateInfo.iBkColor = COLOR_lightgray; CreateInfo.dwAddData = 0L; CreateInfo.hHosting = hParentWnd; hwnd = CreateMainWindow (&CreateInfo); if (hwnd == HWND_INVALID) return hwnd; hStatic = CreateWindowEx ("static", label, WS_VISIBLE | SS_SIMPLE, WS_EX_USEPARENTCURSOR, IDC_STATIC, 10, 10, 380, 16, hwnd, 0); if (range > 0) { hProgBar = CreateWindowEx ("progressbar", NULL, WS_VISIBLE, WS_EX_USEPARENTCURSOR, id, 10, 30, 380, 30, hwnd, 0); SendDlgItemMessage (hwnd, id, PBM_SETRANGE, 0, range); } else hProgBar = HWND_INVALID; UpdateWindow (hwnd, TRUE); SendMessage (hStatic, MSG_PAINT, 0, 0L); if (hProgBar != HWND_INVALID) SendMessage (hProgBar, MSG_PAINT, 0, 0L); return hwnd;}void destroyProgressWin (HWND hwnd){ DestroyAllControls (hwnd); DestroyMainWindow (hwnd); ThrowAwayMessages (hwnd); MainWindowThreadCleanup (hwnd);}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -