1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137
|
/*
* Copyright 1995 Martin von Loewis
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser 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
*/
#include <windows.h>
#include <commdlg.h>
typedef struct
{
HANDLE hInstance;
HWND hMainWnd;
HMENU hMainMenu;
} GLOBALS;
GLOBALS Globals;
BOOL FileOpen(HWND hWnd)
{
char filename[80] = "test.c";
OPENFILENAME ofn = { sizeof(OPENFILENAME),
hWnd, NULL, "C code\0*.c\0", NULL, 0, 0, filename, 80,
NULL, 0, NULL, NULL, OFN_CREATEPROMPT |
OFN_SHOWHELP, 0, 0, NULL, 0, NULL };
return GetOpenFileName(&ofn);
}
LRESULT CALLBACK DlgProc(HWND hWnd,UINT msg,WPARAM wParam,LPARAM lParam)
{
switch(msg)
{
case WM_INITDIALOG:
break;
case WM_COMMAND:
switch (wParam)
{
case 100:
EndDialog(hWnd, 100);
return TRUE;
}
}
return FALSE;
}
LRESULT CALLBACK WndProc (HWND wnd, UINT msg, WPARAM w, LPARAM l)
{
switch (msg){
case WM_COMMAND:
switch(w){
case 100:
DialogBox(Globals.hInstance,
"DIADEMO", wnd,
(DLGPROC)DlgProc);
return 0;
case 101:
{
HDC hdc, hMemDC;
HBITMAP hBitmap, hPrevBitmap;
BITMAP bmp;
hBitmap = LoadBitmapA (Globals.hInstance, "BITDEMO");
hdc = GetDC (wnd);
hMemDC = CreateCompatibleDC (hdc);
hPrevBitmap = SelectObject (hMemDC, hBitmap);
GetObjectA (hBitmap, sizeof(BITMAP), &bmp);
BitBlt (hdc, 0, 0, bmp.bmWidth, bmp.bmHeight,
hMemDC, 0, 0, SRCCOPY);
SelectObject (hMemDC, hPrevBitmap);
DeleteDC (hMemDC);
ReleaseDC (wnd, hdc);
return 0;
}
case 102:
FileOpen(wnd);
return 0;
default:
return DefWindowProc (wnd, msg, w, l);
}
case WM_DESTROY:
PostQuitMessage (0);
break;
default:
return DefWindowProc (wnd, msg, w, l);
}
return 0l;
}
int PASCAL WinMain (HINSTANCE inst, HINSTANCE prev, LPSTR cmdline, int show)
{
MSG msg;
WNDCLASS class;
char className[] = "class"; /* To make sure className >= 0x10000 */
char winName[] = "Test app";
Globals.hInstance = inst;
if (!prev){
class.style = CS_HREDRAW | CS_VREDRAW;
class.lpfnWndProc = WndProc;
class.cbClsExtra = 0;
class.cbWndExtra = 0;
class.hInstance = inst;
class.hIcon = LoadIcon (0, IDI_APPLICATION);
class.hCursor = LoadCursor (0, IDC_ARROW);
class.hbrBackground = GetStockObject (WHITE_BRUSH);
class.lpszMenuName = 0;
class.lpszClassName = className;
}
if (!RegisterClass (&class))
return FALSE;
Globals.hMainWnd = CreateWindow (className, winName, WS_OVERLAPPEDWINDOW,
CW_USEDEFAULT, 0, CW_USEDEFAULT, 0, 0,
LoadMenu(inst,"MAIN"), inst, 0);
ShowWindow (Globals.hMainWnd, show);
UpdateWindow (Globals.hMainWnd);
while (GetMessage (&msg, 0, 0, 0)){
TranslateMessage (&msg);
DispatchMessage (&msg);
}
return 0;
}
|