#include <stdio.h>#include <stdlib.h>#include <math.h>#include <malloc.h>#include <memory.h>#include "lcstring.h"#include "lin-city.h"#include "common.h"#include "generic.h"#include "mouse.h"#include "lchelp.h"#include "module_buttons.h"Go to the source code of this file.
Functions | |
| ATOM | MyRegisterClass (CONST WNDCLASS *) |
| BOOL | InitApplication (HINSTANCE) |
| BOOL | InitInstance (HINSTANCE, int) |
| LRESULT CALLBACK | WndProc (HWND, UINT, WPARAM, LPARAM) |
| LRESULT CALLBACK | About (HWND, UINT, WPARAM, LPARAM) |
| BOOL | CenterWindow (HWND, HWND) |
| void | InitializeBackingStore (HWND) |
| BOOL | CopyBackingStoreToScreen (HDC, HWND, LPPAINTSTRUCT) |
| void | CreateDDB (HWND hWnd) |
| void | CreateDIB (void) |
| void | InitializePalette (void) |
| void | DoSquareMouse (HDC hdc) |
| void | ResizeBackingStore (HWND hWnd) |
| void | ResizeDDB (HWND hWnd) |
| int WINAPI | WinMain (HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow) |
| void | CheckClientSize (int width, int height, int with_menus) |
| void | ProcessNextEvent (void) |
| void | ProcessPendingEvents (void) |
| void | EnableWindowsMenuItems (void) |
| void | DisableWindowsMenuItems (void) |
| void | HandleMouse () |
| char | GetKeystroke () |
| void | AddPaletteEntry (int col, int red, int grn, int blu) |
| void | UpdatePalette (void) |
Variables | |
| char | szClassNameWithMenu [] = APPNAME " (with menu)" |
| char | szClassNameWithoutMenu [] = APPNAME " (without menu)" |
| char | szAppName [] = APPNAME |
| char | szTitle [] = APPNAME |
| HBRUSH | hbrBackground = 0 |
| int | pending_mouse_event = 0 |
| int | pending_mouse_x = 0 |
| int | pending_mouse_y = 0 |
| int | pending_resize_event = 0 |
| int | pending_resize_w = 0 |
| int | pending_resize_h = 0 |
|
||||||||||||||||||||
|
|
|
||||||||||||||||||||
|
Definition at line 1338 of file winmain.c. 01339 {
01340
01341 red = (red * 255) / 62;
01342 if (red > 255)
01343 red = 255;
01344
01345 grn = (grn * 255) / 62;
01346 if (grn > 255)
01347 grn = 255;
01348
01349 blu = (blu * 255) / 62;
01350 if (blu > 255)
01351 blu = 255;
01352
01353 display.colorrefPal[col] = RGB (red, grn, blu);
01354
01355 if (display.brushPal[col]) {
01356 DeleteObject (display.brushPal[col]);
01357 display.brushPal[col] = 0;
01358 }
01359
01360 if (display.hasPalette) {
01361 display.pLogPal->palPalEntry[col].peRed = red;
01362 display.pLogPal->palPalEntry[col].peGreen = grn;
01363 display.pLogPal->palPalEntry[col].peBlue = blu;
01364 display.pLogPal->palPalEntry[col].peFlags = PC_NOCOLLAPSE;
01365 }
01366
01367 if (display.useDIB) {
01368 display.pbminfo->bmiColors[col].rgbRed = red;
01369 display.pbminfo->bmiColors[col].rgbGreen = grn;
01370 display.pbminfo->bmiColors[col].rgbBlue = blu;
01371 display.pbminfo->bmiColors[col].rgbReserved = 0;
01372 }
01373 }
|
|
||||||||||||
|
|
|
||||||||||||||||
|
Definition at line 246 of file winmain.c. 00247 {
00248 display.screenW = GetSystemMetrics (SM_CXSCREEN);
00249 display.screenH = GetSystemMetrics (SM_CYSCREEN);
00250 }
|
|
||||||||||||||||
|
Definition at line 975 of file winmain.c. 00976 {
00977 HPALETTE hPalOld, hPalOldMem;
00978
00979 // Is this necessary???
00980 if (display.hasPalette) {
00981 hPalOldMem = SelectPalette (display.hdcMem, (HPALETTE) display.hPal, FALSE);
00982 RealizePalette (display.hdcMem);
00983 hPalOld = SelectPalette (hdc, (HPALETTE) display.hPal, FALSE);
00984 RealizePalette (hdc);
00985 }
00986
00987 // Copy DIB into DDB
00988 if (display.useDIB) {
00989 if (SetDIBits (display.hdcMem, display.hBitmap, 0,
00990 display.pbminfo->bmiHeader.biHeight, (LPSTR) display.pBits,
00991 display.pbminfo, DIB_RGB_COLORS) == 0)
00992 {
00993 MessageBox (display.hWnd, "Failed in SetDIBits!", "Error", MB_OK);
00994 exit (-1);
00995 }
00996 }
00997
00998 // Blast DDB onto screen
00999 if (!BitBlt (hdc, ps->rcPaint.left, ps->rcPaint.top,
01000 (int) ps->rcPaint.right - ps->rcPaint.left,
01001 (int) ps->rcPaint.bottom - ps->rcPaint.top,
01002 display.hdcMem, ps->rcPaint.left,
01003 ps->rcPaint.top, SRCCOPY))
01004 {
01005 MessageBox (NULL, "BitBlt failed!", "Failure!", MB_OK);
01006 }
01007
01008
01009 // Draw square mouse
01010 if (cs_square_mouse_visible) {
01011 DoSquareMouse (hdc);
01012 }
01013
01014 if (display.hasPalette) {
01015 display.hPal = SelectPalette (display.hdcMem, hPalOldMem, FALSE);
01016 display.hPal = SelectPalette (hdc, hPalOld, FALSE);
01017 }
01018 return TRUE;
01019 }
|
|
|
Definition at line 891 of file winmain.c. 00892 {
00893 HDC hdc;
00894 HBITMAP hBitmapOri;
00895 HPALETTE hPalOld;
00896 RECT rect;
00897 HBRUSH hbr, hbrOld;
00898
00899 hdc = GetDC (hWnd);
00900 if (display.hasPalette) {
00901 hPalOld = SelectPalette (hdc, (HPALETTE) display.hPal, FALSE);
00902 if (RealizePalette (hdc)) {
00903 UpdateColors (hdc);
00904 }
00905 }
00906
00907 // Before an application can use a memory device
00908 // context for drawing operations, it must select
00909 // a bitmap of the correct width and height into
00910 // the device context. Once a bitmap has been selected,
00911 // the device context can be used to prepare images
00912 // that will be copied to the screen or printed.
00913 display.hdcMem = CreateCompatibleDC (hdc);
00914 if (display.hasPalette) {
00915 display.hPaletteMemOri = SelectPalette (display.hdcMem, (HPALETTE) display.hPal, FALSE);
00916 RealizePalette (display.hdcMem);
00917 }
00918 display.hBitmap = CreateCompatibleBitmap (hdc, display.winW, display.winH);
00919 hBitmapOri = (HBITMAP) SelectObject (display.hdcMem, display.hBitmap);
00920
00921 // Write that nasty brown color into the backing store
00922 rect.left = 0;
00923 rect.top = 0;
00924 rect.right = display.winW;
00925 rect.bottom = display.winH;
00926 hbr = hbrBackground;
00927 hbrOld = (HBRUSH) SelectObject (hdc, hbr); // Select brush
00928 FillRect (display.hdcMem, &rect, (HBRUSH) hbr); // Draw rectangle
00929 hbr = (HBRUSH) SelectObject (display.hdcMem, hbrOld); // Unselect brush
00930
00931 #if defined (commentout)
00932 // GCS: For now, just keep the old bitmap around.
00933 // I'll use it to swap out the full-sized color bitmap
00934 // when I do a SetDIBits/GetDIBits.
00935 display.hBitmapOri = hBitmapOri;
00936 #endif /* */
00937
00938 #if defined (commentout)
00939 // GCS: Instead of reselecting the default bitmap back into the hdc,
00940 // I'm gonna delete it. Any problems with this??
00941 DeleteObject (hBitmapOri);
00942 #endif /* */
00943
00944 ReleaseDC (hWnd, hdc);
00945 }
|
|
|
Definition at line 843 of file winmain.c. 00844 {
00845 // Let's create a 256 color DIB, just for testing!
00846 ULONG sizBMI;
00847 INT iNumClr = 256;
00848 INT iLoop;
00849
00850 // Get memory for 256 color BITMAPINFO
00851 sizBMI = sizeof (BITMAPINFOHEADER) + sizeof (RGBQUAD) * iNumClr;
00852 if ((display.pbminfo = (PBITMAPINFO) GlobalAlloc (GMEM_FIXED | GMEM_ZEROINIT, sizBMI)) == NULL) {
00853 MessageBox (display.hWnd, "Failed in Memory Allocation for bminfo!", "Error", MB_OK);
00854 exit (-1);
00855 }
00856
00857 // Fill in bitmap info
00858 display.pbminfo->bmiHeader.biSize = 0x28; // GDI needs this to work
00859 display.pbminfo->bmiHeader.biWidth = display.winW;
00860 display.pbminfo->bmiHeader.biHeight = display.winH;
00861 display.pbminfo->bmiHeader.biPlanes = 1;
00862 display.pbminfo->bmiHeader.biBitCount = 8;
00863 display.pbminfo->bmiHeader.biCompression = BI_RGB;
00864 // this choice for biSizeImage reflects one byte per pixel
00865 display.pbminfo->bmiHeader.biSizeImage = display.winW * display.winH;
00866 display.pbminfo->bmiHeader.biXPelsPerMeter = 0;
00867 display.pbminfo->bmiHeader.biYPelsPerMeter = 0;
00868 display.pbminfo->bmiHeader.biClrUsed = 0;
00869 display.pbminfo->bmiHeader.biClrImportant = 0;
00870
00871 // Fill in colormap w/ black
00872 for (iLoop = 0; iNumClr; iLoop++) {
00873 display.pbminfo->bmiColors[iLoop].rgbRed = 0;
00874 display.pbminfo->bmiColors[iLoop].rgbGreen = 0;
00875 display.pbminfo->bmiColors[iLoop].rgbBlue = 0;
00876 display.pbminfo->bmiColors[iLoop].rgbReserved = 0;
00877 }
00878
00879 // CreateDIBSection() will allocate the pBits.
00880 display.hDIB = CreateDIBSection (display.hdcMem, display.pbminfo,
00881 DIB_RGB_COLORS,
00882 (void **) (&display.pBits), NULL, 0);
00883 }
|
|
|
Definition at line 472 of file winmain.c. 00473 {
00474 #if defined (USE_WIN32_MENU)
00475 HMENU hMenu = GetMenu (display.hWnd);
00476 EnableMenuItem (hMenu, IDM_OPEN, MF_BYCOMMAND | MF_GRAYED);
00477 EnableMenuItem (hMenu, IDM_SAVE, MF_BYCOMMAND | MF_GRAYED);
00478 EnableMenuItem (hMenu, IDM_HELPCONTENTS, MF_BYCOMMAND | MF_GRAYED);
00479 #endif
00480 }
|
|
|
Definition at line 1026 of file winmain.c. 01027 {
01028 RECT rect;
01029 int size;
01030 HBRUSH hbr, hbrOld;
01031
01032 size = (main_groups[selected_module_group].size) * 16;
01033
01034 // Select Brush
01035 hbr = GetPaletteBrush (white (31));
01036 hbrOld = (HBRUSH) SelectObject (hdc, hbr);
01037
01038 // Top rectangle
01039 rect.left = AdjustX (omx - 2);
01040 rect.top = AdjustY (omy - 2);
01041 rect.right = AdjustX (omx + size + 1);
01042 rect.bottom = AdjustY (omy - 1);
01043 FillRect (hdc, &rect, hbr);
01044
01045
01046 // Left rectangle
01047 rect.left = AdjustX (omx - 2);
01048 rect.top = AdjustY (omy);
01049 rect.right = AdjustX (omx - 1);
01050 rect.bottom = AdjustY (omy + size - 1);
01051 FillRect (hdc, &rect, hbr);
01052
01053 // Right rectangle
01054 rect.left = AdjustX (omx + size);
01055 rect.top = AdjustY (omy);
01056 rect.right = AdjustX (omx + size + 1);
01057 rect.bottom = AdjustY (omy + size - 1);
01058 FillRect (hdc, &rect, hbr);
01059
01060 // Bottom rectangle
01061 rect.left = AdjustX (omx - 2);
01062 rect.top = AdjustY (omy + size);
01063 rect.right = AdjustX (omx + size + 1);
01064 rect.bottom = AdjustY (omy + size + 1);
01065 FillRect (hdc, &rect, hbr);
01066
01067 // Unselect brush
01068 hbr = (HBRUSH) SelectObject (display.hdcMem, hbrOld);
01069 }
|
|
|
Definition at line 460 of file winmain.c. 00461 {
00462 #if defined (USE_WIN32_MENU)
00463 HMENU hMenu = GetMenu (display.hWnd);
00464 EnableMenuItem (hMenu, IDM_OPEN, MF_BYCOMMAND | MF_ENABLED);
00465 EnableMenuItem (hMenu, IDM_SAVE, MF_BYCOMMAND | MF_ENABLED);
00466 EnableMenuItem (hMenu, IDM_HELPCONTENTS, MF_BYCOMMAND | MF_ENABLED);
00467 #endif
00468 }
|
|
|
Definition at line 528 of file winmain.c. 00529 {
00530 char key;
00531 /* GCS 02/02/2003 I found out that sometimes the mouse events were
00532 getting lost here. */
00533 HandleMouse ();
00534 // ProcessPendingEvents ();
00535 key = x_key_value;
00536 x_key_value = 0;
00537 return key;
00538 }
|
|
|
Definition at line 488 of file winmain.c. 00489 {
00490 MSG msg;
00491 /* Process queued events, ignoring mouse moves. */
00492 while (PeekMessage (&msg, NULL, 0, 0, PM_REMOVE)) {
00493 if (!TranslateAccelerator (msg.hwnd, (HACCEL) display.hAccelTable,
00494 &msg)) {
00495 pending_mouse_x = cs_mouse_x;
00496 pending_mouse_y = cs_mouse_y;
00497 pending_mouse_event = 0;
00498 pending_resize_event = 0;
00499 TranslateMessage (&msg);
00500 DispatchMessage (&msg);
00501 if (pending_mouse_event)
00502 cs_mouse_handler (pending_mouse_event,
00503 pending_mouse_x - cs_mouse_x,
00504 pending_mouse_y - cs_mouse_y);
00505 if (pending_resize_event) {
00506 /* Force resize, because I can't tell difference between
00507 size change and restoring a minimized window. Ideally,
00508 this would simply redraw. */
00509 display.winW = 0;
00510 resize_geometry (pending_resize_w, pending_resize_h);
00511 }
00512 }
00513 }
00514
00515 /* Now move the mouse if necessary. */
00516 if (pending_mouse_x != cs_mouse_x
00517 || pending_mouse_y != cs_mouse_y)
00518 cs_mouse_handler (0, pending_mouse_x - cs_mouse_x,
00519 pending_mouse_y - cs_mouse_y);
00520 }
|
|
|
Definition at line 164 of file winmain.c. 00165 {
00166 WNDCLASS wcWithMenu;
00167 WNDCLASS wcWithoutMenu;
00168 // If Lin City is already running, focus existing process.
00169 // Win32 always sets hPrevInstance to NULL, so check w/ FindWindow()
00170 HWND hwnd = FindWindow (szClassNameWithMenu, NULL);
00171
00172 if (!hwnd)
00173 hwnd = FindWindow (szClassNameWithoutMenu, NULL);
00174 if (hwnd) {
00175 // We found another version of ourself. Lets defer to it:
00176 if (IsIconic (hwnd)) {
00177 ShowWindow (hwnd, SW_RESTORE);
00178 }
00179 SetForegroundWindow (hwnd);
00180 return FALSE;
00181 }
00182
00183 // Create brush for background: Nasty Brown (Lin City color # 105)
00184 hbrBackground = CreateSolidBrush (RGB (0x4C, 0x4C, 0));
00185
00186 // Fill in WNDCLASS for class WITH MENU.
00187 wcWithMenu.style = 0;
00188 wcWithMenu.lpfnWndProc = (WNDPROC) WndProc;
00189 wcWithMenu.cbClsExtra = 0;
00190 wcWithMenu.cbWndExtra = 0;
00191 wcWithMenu.hInstance = hInstance;
00192 wcWithMenu.hIcon = LoadIcon (hInstance, szAppName);
00193 wcWithMenu.hCursor = LoadCursor (NULL, IDC_ARROW);
00194 wcWithMenu.hbrBackground = hbrBackground;
00195
00196 // Windows95 has different recommended help menu format.
00197 #if defined (USE_WIN32_MENU)
00198 if (IS_WIN95) {
00199 wcWithMenu.lpszMenuName = "WIN95";
00200 } else {
00201 wcWithMenu.lpszMenuName = szAppName;
00202 }
00203 wcWithMenu.lpszClassName = szClassNameWithMenu;
00204 #else
00205 wcWithMenu.lpszMenuName = "";
00206 wcWithMenu.lpszClassName = szClassNameWithMenu;
00207 #endif
00208
00209 // Fill in WNDCLASS for class WITHOUT MENU.
00210 wcWithoutMenu.style = 0;
00211 wcWithoutMenu.lpfnWndProc = (WNDPROC) WndProc;
00212 wcWithoutMenu.cbClsExtra = 0;
00213 wcWithoutMenu.cbWndExtra = 0;
00214 wcWithoutMenu.hInstance = hInstance;
00215 wcWithoutMenu.hIcon = LoadIcon (hInstance, szAppName);
00216 wcWithoutMenu.hCursor = LoadCursor (NULL, IDC_ARROW);
00217 wcWithoutMenu.hbrBackground = hbrBackground;
00218 wcWithoutMenu.lpszMenuName = "";
00219 wcWithoutMenu.lpszClassName = szClassNameWithoutMenu;
00220
00221 // Register the window classes and return success/failure code.
00222 if (IS_WIN95) {
00223 BOOL rv;
00224 rv = MyRegisterClass (&wcWithMenu);
00225 if (!rv)
00226 return rv;
00227 rv = MyRegisterClass (&wcWithoutMenu);
00228 return rv;
00229 } else {
00230 BOOL rv;
00231 rv = RegisterClass (&wcWithMenu);
00232 if (!rv)
00233 return rv;
00234 rv = RegisterClass (&wcWithoutMenu);
00235 return rv;
00236 }
00237 }
|
|
|
Definition at line 766 of file winmain.c. 00767 {
00768 RECT rc;
00769
00770 GetClientRect (hWnd, &rc);
00771 display.winW = rc.right - rc.left;
00772 display.winH = rc.bottom - rc.top;
00773
00774 InitializePalette ();
00775 CreateDDB (hWnd);
00776 if (display.useDIB) {
00777 CreateDIB ();
00778 }
00779 display.hSaveUnderHdc = 0;
00780 display.hSaveUnderBitmap = 0;
00781 }
|
|
|
Definition at line 799 of file winmain.c. 00800 {
00801 INT iLoop;
00802
00803 display.hPal = 0;
00804 display.pLogPal = 0;
00805 // Clear out palette arrays
00806 for (iLoop = 0; iLoop < 256; iLoop++) {
00807 display.colorrefPal[iLoop] = 0;
00808 display.brushPal[iLoop] = 0;
00809 }
00810
00811 // If the device uses a palette (e.g. 8 bit display),
00812 // we need to create an HPALETTE for the HDC.
00813 if (display.hasPalette) {
00814 // Allocate memory for LOGPALETTE
00815 display.pLogPal = (NPLOGPALETTE) LocalAlloc (LMEM_FIXED,
00816 (sizeof (LOGPALETTE) +
00817 (sizeof (PALETTEENTRY) * (display.paletteSize))));
00818 if (!display.pLogPal) {
00819 MessageBox (display.hWnd, "Not enough memory for logical palette.", NULL, MB_OK | MB_ICONHAND);
00820 PostQuitMessage (0);
00821 exit (-1);
00822 }
00823 display.pLogPal->palVersion = 0x300;
00824 display.pLogPal->palNumEntries = display.paletteSize;
00825
00826 // Fill palette with system colors by default
00827 for (iLoop = 0; iLoop < display.paletteSize; iLoop++) {
00828 *((WORD *) (&display.pLogPal->palPalEntry[iLoop].peRed)) = (WORD) iLoop;
00829 display.pLogPal->palPalEntry[iLoop].peBlue = 0;
00830 display.pLogPal->palPalEntry[iLoop].peFlags = PC_EXPLICIT;
00831 }
00832
00833 // Convert LOGPALETTE into HPALETTE
00834 display.hPal = CreatePalette ((LPLOGPALETTE) display.pLogPal);
00835 }
00836 }
|
|
||||||||||||
|
Definition at line 258 of file winmain.c. 00259 {
00260 HDC hDCGlobal = GetDC (NULL);
00261 INT iRasterCaps;
00262 char *szClassName = 0;
00263 DWORD dwStyle;
00264 RECT client_size;
00265
00266 // Determine graphics capabilities
00267 iRasterCaps = GetDeviceCaps (hDCGlobal, RASTERCAPS);
00268 if (iRasterCaps & RC_PALETTE) {
00269 display.hasPalette = TRUE;
00270 display.paletteSize = GetDeviceCaps (hDCGlobal, SIZEPALETTE);
00271 display.defaultPaletteSize = GetDeviceCaps (hDCGlobal, NUMCOLORS);
00272 } else {
00273 display.hasPalette = FALSE;
00274 }
00275
00276 display.colorDepth = GetDeviceCaps (hDCGlobal, BITSPIXEL);
00277 ReleaseDC (NULL, hDCGlobal);
00278
00279 // Decide whether to use DIB's or DDB's
00280 #if defined (WIN32_USEDIB)
00281 if (display.colorDepth == 8) // Only use DIB for 256 colors
00282 display.useDIB = TRUE;
00283 else
00284 display.useDIB = FALSE;
00285 #else /* */
00286 display.useDIB = FALSE;
00287 #endif /* */
00288
00289 // Do some global initializations
00290 display.hInst = hInstance;
00291 display.fullscreen = FALSE;
00292 //display.fullscreen = TRUE;
00293 display.screenW = GetSystemMetrics (SM_CXSCREEN);
00294 display.screenH = GetSystemMetrics (SM_CYSCREEN);
00295 display.winFullscreenClientW = (INT) GetSystemMetrics (SM_CXFULLSCREEN);
00296 display.winFullscreenClientH = (INT) GetSystemMetrics (SM_CYFULLSCREEN);
00297 InitializePalette ();
00298
00299 // Choose one of Lin City window types
00300 // a) no pix doubling, no border
00301 // b) no pix doubling, 30 pixel border
00302 // c) pix doubling, no border
00303 // GCS FIX: This doesn't work. I need to call AdjustWindowRect on these values (?)
00304 if ((display.screenW >= 2*WINWIDTH + 2*BORDERX) &&
00305 (display.screenH >= 2*WINHEIGHT + 2*BORDERY)) {
00306 pix_double = 1;
00307 borderx = 1;
00308 bordery = 1;
00309 }
00310 else if ((display.screenW >= 2*WINWIDTH) &&
00311 (display.screenH >= 2*WINHEIGHT)) {
00312 pix_double = 1;
00313 borderx = 0;
00314 bordery = 0;
00315 }
00316 else if ((display.screenW >= WINWIDTH + (2 * BORDERX))
00317 &&(display.screenH >= WINHEIGHT + (2 * BORDERY))) {
00318 pix_double = 0;
00319 borderx = BORDERX;
00320 bordery = BORDERY;
00321 } else {
00322 pix_double = 0;
00323 borderx = 0;
00324 bordery = 0;
00325 }
00326 display.clientW = ((pix_double + 1) * WINWIDTH) + (2 * borderx);
00327 display.clientH = ((pix_double + 1) * WINHEIGHT) + (2 * bordery);
00328
00329 // Choose one of three client window types
00330 // a) full screen
00331 // b) maximized window
00332 // c) regular window
00333 // Prefer regular over maximized over full screen
00334 dwStyle = WS_CAPTION | WS_SYSMENU | WS_MINIMIZEBOX | WS_MAXIMIZEBOX | WS_SIZEBOX;
00335 client_size.left = 0;
00336 client_size.top = 0;
00337 client_size.right = display.clientW;
00338 client_size.bottom = display.clientH;
00339 AdjustWindowRect (&client_size, dwStyle, TRUE);
00340
00341 if (((client_size.right - client_size.left) <= display.screenW)
00342 &&((client_size.bottom - client_size.top) <= display.screenH))
00343 {
00344 // Use regular (overlapped) window
00345 szClassName = szClassNameWithMenu;
00346 if (client_size.left < 0) {
00347 client_size.right -= client_size.left;
00348 client_size.left = CW_USEDEFAULT;
00349 }
00350 if (client_size.top < 0) {
00351 client_size.bottom -= client_size.top;
00352 client_size.top = CW_USEDEFAULT;
00353 }
00354 } else {
00355 // Check maximized by subtracting out the DLGFRAME size.
00356 // Note that the "obvious" method of calling AdjustWindowRect()
00357 // with style WS_MAXIMIZE doesn't work!
00358 int win_border_x = GetSystemMetrics (SM_CXDLGFRAME);
00359 int win_border_y = GetSystemMetrics (SM_CYDLGFRAME);
00360 if (((client_size.right - client_size.left - 2 * win_border_x) <= display.screenW)
00361 &&((client_size.bottom - client_size.top - 2 * win_border_y) <= display.screenH))
00362 {
00363 // Use maximized window
00364 szClassName = szClassNameWithMenu;
00365 // dwStyle |= WS_MAXIMIZE;
00366 if (client_size.left < 0) {
00367 client_size.right -= client_size.left;
00368 client_size.left = CW_USEDEFAULT;
00369 }
00370 if (client_size.top < 0) {
00371 client_size.bottom -= client_size.top;
00372 client_size.top = CW_USEDEFAULT;
00373 }
00374 nCmdShow = SW_SHOWMAXIMIZED;
00375 } else {
00376 // Need fullsize window
00377 szClassName = szClassNameWithoutMenu;
00378 dwStyle = WS_POPUP;
00379 client_size.left = 0;
00380 client_size.top = 0;
00381 client_size.right = display.screenW;
00382 client_size.bottom = display.screenH;
00383 }
00384 }
00385
00386 display.min_h = client_size.bottom - client_size.top;
00387 display.min_w = client_size.right - client_size.left;
00388
00389 // Create the window
00390 display.hWnd = CreateWindow (szClassName, // Class name
00391 szTitle, // Caption
00392 dwStyle, // Style
00393 client_size.left, client_size.top, // Position
00394 client_size.right, client_size.bottom, // Size
00395 (HWND) NULL, // Parent window (no parent)
00396 (HMENU) NULL, // use class menu
00397 (HINSTANCE) hInstance, // handle to window instance
00398 (LPVOID) NULL // no params to pass on
00399 );
00400
00401 if (!display.hWnd) {
00402 return (FALSE);
00403 }
00404
00405 // Display the window
00406 ShowWindow (display.hWnd, nCmdShow);
00407 UpdateWindow (display.hWnd);
00408
00409 return (TRUE);
00410 }
|
|
|
Definition at line 115 of file winmain.c. 00116 {
00117 HANDLE hMod;
00118 FARPROC proc;
00119 WNDCLASSEX wcex;
00120
00121 hMod = GetModuleHandle ("USER32");
00122 if (hMod != NULL) {
00123 #if defined (UNICODE)
00124 proc = GetProcAddress ((HMODULE) hMod, "RegisterClassExW");
00125 #else /* */
00126 proc = GetProcAddress ((HMODULE) hMod, "RegisterClassExA");
00127 #endif /* */
00128 if (proc != NULL) {
00129 // GCS: This typedef is for the typecast in the return stmt below
00130 typedef int (FAR WINAPI * my_FARPROC) (WNDCLASSEX *);
00131
00132 wcex.style = lpwc->style;
00133 wcex.lpfnWndProc = lpwc->lpfnWndProc;
00134 wcex.cbClsExtra = lpwc->cbClsExtra;
00135 wcex.cbWndExtra = lpwc->cbWndExtra;
00136 wcex.hInstance = lpwc->hInstance;
00137 wcex.hIcon = lpwc->hIcon;
00138 wcex.hCursor = lpwc->hCursor;
00139 wcex.hbrBackground = lpwc->hbrBackground;
00140 wcex.lpszMenuName = lpwc->lpszMenuName;
00141 wcex.lpszClassName = lpwc->lpszClassName;
00142
00143 // Added elements for Windows 95:
00144 wcex.cbSize = sizeof (WNDCLASSEX);
00145 wcex.hIconSm = LoadIcon (wcex.hInstance, "SMALL");
00146
00147 return (*((my_FARPROC) (proc))) (&wcex);
00148 }
00149 }
00150 return (RegisterClass (lpwc));
00151 }
|
|
|
Definition at line 419 of file winmain.c. 00420 {
00421
00422 MSG msg;
00423 if (GetMessage (&msg, NULL, 0, 0)) {
00424 if (!TranslateAccelerator (msg.hwnd, (HACCEL) display.hAccelTable,
00425 &msg)) {
00426 TranslateMessage (&msg);
00427 DispatchMessage (&msg);
00428 }
00429 }
00430 ProcessPendingEvents ();
00431 }
|
|
|
Definition at line 440 of file winmain.c. 00441 {
00442 MSG msg;
00443 while (PeekMessage (&msg, NULL, 0, 0, PM_REMOVE)) {
00444 if (!TranslateAccelerator (msg.hwnd, (HACCEL) display.hAccelTable,
00445 &msg)) {
00446 TranslateMessage (&msg);
00447 DispatchMessage (&msg);
00448 }
00449 }
00450 }
|
|
|
Definition at line 784 of file winmain.c. 00785 {
00786 ResizeDDB (hWnd);
00787 if (display.useDIB) {
00788 // This had better be false
00789 exit(-1);
00790 }
00791 }
|
|
|
Definition at line 949 of file winmain.c. 00950 {
00951 RECT rect;
00952 HDC hdc;
00953 HBRUSH hbr, hbrOld;
00954
00955 hdc = GetDC (hWnd);
00956 DeleteObject (display.hBitmap);
00957 display.hBitmap = CreateCompatibleBitmap (hdc, pending_resize_w, pending_resize_h);
00958 SelectObject (display.hdcMem, display.hBitmap);
00959
00960 rect.left = 0;
00961 rect.top = 0;
00962 rect.right = pending_resize_w;
00963 rect.bottom = pending_resize_h;
00964 hbr = hbrBackground;
00965 hbrOld = (HBRUSH) SelectObject (hdc, hbr); // Select brush
00966 FillRect (display.hdcMem, &rect, (HBRUSH) hbr); // Draw rectangle
00967 hbr = (HBRUSH) SelectObject (display.hdcMem, hbrOld); // Unselect brush
00968
00969 ReleaseDC (hWnd, hdc);
00970 }
|
|
|
Definition at line 1380 of file winmain.c. 01381 {
01382 if (display.hasPalette) {
01383 // Make a new HPALETTE and select to hdcGlobal and hdcMem
01384 HPALETTE hPalNew;
01385 hPalNew = CreatePalette ((LPLOGPALETTE) display.pLogPal);
01386 SelectPalette (display.hdcMem, hPalNew, FALSE);
01387 RealizePalette (display.hdcMem);
01388 DeleteObject (display.hPal);
01389 display.hPal = hPalNew;
01390 }
01391 }
|
|
||||||||||||||||||||
|
Definition at line 67 of file winmain.c. 00068 {
00069 char *args[] = {"wlincity"};
00070
00071 if (!hPrevInstance) {
00072 // Perform instance initialization:
00073 if (!InitApplication (hInstance)) {
00074 return (FALSE);
00075 }
00076 }
00077
00078 // Perform application initialization, including creating the
00079 // Lin-City main window.
00080 if (!InitInstance (hInstance, nCmdShow)) {
00081 return (FALSE);
00082 }
00083
00084 // Load keyboard accelerators (shortkut keys)
00085 display.hAccelTable = LoadAccelerators (hInstance, szAppName);
00086
00087 // Take care of any outstanding messages
00088 ProcessPendingEvents ();
00089
00090 // lincity_main() contains main message loop
00091 lincity_main (1, args);
00092
00093 // Take care of any outstanding messages after main() finishes.
00094 ProcessPendingEvents ();
00095
00096 return 0;
00097 lpCmdLine; // This prevents 'unused formal parameter' warnings
00098 }
|
|
||||||||||||||||||||
|
Definition at line 547 of file winmain.c. 00548 {
00549 #if defined (USE_WIN32_MENU)
00550 int wmId, wmEvent;
00551 #endif
00552
00553 switch (message)
00554 {
00555 #if defined (USE_WIN32_MENU)
00556 case WM_COMMAND: {
00557 wmId = LOWORD (wParam);
00558 wmEvent = HIWORD (wParam);
00559
00560 //Parse the menu selections:
00561 switch (wmId)
00562 {
00563
00564 case IDM_OPEN:
00565 load_flag = 1;
00566 DisableWindowsMenuItems ();
00567 break;
00568
00569 case IDM_SAVE:
00570 save_flag = 1;
00571 DisableWindowsMenuItems ();
00572 break;
00573
00574 case IDM_EXIT:
00575 // GCS FIX: I'm still not quite satisfied with this...
00576 // x_key_value = 'q';
00577 DestroyWindow (hWnd);
00578 break;
00579
00580 case IDM_ABOUT:
00581 DialogBox (display.hInst, "AboutBox", hWnd, (DLGPROC) About);
00582 break;
00583
00584 case IDM_HELPCONTENTS:
00585 help_flag = 1;
00586 DisableWindowsMenuItems ();
00587 activate_help ("index.hlp");
00588 break;
00589
00590 default:
00591 return (DefWindowProc (hWnd, message, wParam, lParam));
00592 }
00593 }
00594 break;
00595 #endif
00596
00597 case WM_KEYDOWN: {
00598 int nVirtKey = (int) wParam;
00599 x_key_shifted = (GetKeyState (VK_SHIFT) & 0x80000000) ? TRUE : FALSE;
00600 switch (nVirtKey)
00601 {
00602 case VK_LEFT:
00603 x_key_value = 1;
00604 break;
00605
00606 case VK_DOWN:
00607 x_key_value = 2;
00608 break;
00609
00610 case VK_UP:
00611 x_key_value = 3;
00612 break;
00613
00614 case VK_RIGHT:
00615 x_key_value = 4;
00616 break;
00617
00618 case VK_ESCAPE:
00619 x_key_value = 5;
00620 break;
00621 }
00622 }
00623 break;
00624
00625 case WM_CHAR: {
00626 TCHAR chCharCode = (TCHAR) wParam; // character code
00627 LPARAM lKeyData = lParam; // key data
00628 if (chCharCode == 8) { // Fix backspace
00629 chCharCode = 127;
00630 } else if (chCharCode == VK_ESCAPE) { // Fix escape
00631 chCharCode = 5;
00632 }
00633 x_key_value = chCharCode;
00634 }
00635 break;
00636
00637 // RightClick on windows non-client area
00638 case WM_NCRBUTTONUP:
00639 if (IS_WIN95 && SendMessage (hWnd, WM_NCHITTEST, 0, lParam) == HTSYSMENU)
00640 {
00641 // The user has clicked the right button on the applications
00642 // 'System Menu'. Here is where you would alter the default
00643 // system menu to reflect your application. Notice how the
00644 // explorer deals with this. For this app, we aren't doing
00645 // anything
00646 return (DefWindowProc (hWnd, message, wParam, lParam));
00647 } else {
00648 // Nothing we are interested in, allow default handling...
00649 return (DefWindowProc (hWnd, message, wParam, lParam));
00650 }
00651 break;
00652
00653 // RightClick in windows client area
00654 case WM_RBUTTONDOWN:
00655 pending_mouse_x = UnAdjustX (LOWORD (lParam));
00656 pending_mouse_y = UnAdjustY (HIWORD (lParam));
00657 pending_mouse_event = LC_MOUSE_RIGHTBUTTON | LC_MOUSE_PRESS;
00658 cs_mouse_shifted = (wParam & MK_SHIFT) ? 1 : 0;
00659 break;
00660
00661 // Left Click in windows client area
00662 case WM_LBUTTONDOWN:
00663 pending_mouse_x = UnAdjustX (LOWORD (lParam));
00664 pending_mouse_y = UnAdjustY (HIWORD (lParam));
00665 pending_mouse_event = LC_MOUSE_LEFTBUTTON | LC_MOUSE_PRESS;
00666 cs_mouse_shifted = (wParam & MK_SHIFT) ? 1 : 0;
00667 break;
00668
00669 case WM_RBUTTONUP:
00670 pending_mouse_x = UnAdjustX (LOWORD (lParam));
00671 pending_mouse_y = UnAdjustY (HIWORD (lParam));
00672 pending_mouse_event = LC_MOUSE_RIGHTBUTTON | LC_MOUSE_RELEASE;
00673 cs_mouse_shifted = (wParam & MK_SHIFT) ? 1 : 0;
00674 break;
00675
00676 case WM_LBUTTONUP:
00677 pending_mouse_x = UnAdjustX (LOWORD (lParam));
00678 pending_mouse_y = UnAdjustY (HIWORD (lParam));
00679 pending_mouse_event = LC_MOUSE_LEFTBUTTON | LC_MOUSE_RELEASE;
00680 cs_mouse_shifted = (wParam & MK_SHIFT) ? 1 : 0;
00681 break;
00682
00683 case WM_MOUSEMOVE:
00684 pending_mouse_x = UnAdjustX (LOWORD (lParam));
00685 pending_mouse_y = UnAdjustY (HIWORD (lParam));
00686 cs_mouse_shifted = (wParam & MK_SHIFT) ? 1 : 0;
00687 break;
00688
00689 // Only comes through on plug'n'play systems
00690 case WM_DISPLAYCHANGE: {
00691 SIZE szScreen;
00692 BOOL fChanged = (BOOL) wParam;
00693
00694 szScreen.cx = LOWORD (lParam);
00695 szScreen.cy = HIWORD (lParam);
00696
00697 if (fChanged) {
00698 // The display 'has' changed. szScreen reflects the
00699 // new size.
00700 MessageBox (GetFocus (), "Display Changed", szAppName, 0);
00701 } else {
00702 // The display 'is' changing. szScreen reflects the
00703 // original size.
00704 MessageBeep (0);
00705 }
00706 }
00707 break;
00708
00709 case WM_PAINT: {
00710 PAINTSTRUCT ps;
00711 HDC hdc;
00712
00713 hdc = BeginPaint (hWnd, &ps);
00714 CopyBackingStoreToScreen (hdc, hWnd, &ps);
00715 EndPaint (hWnd, &ps);
00716 }
00717 break;
00718
00719 // Create client area
00720 case WM_CREATE:
00721 InitializeBackingStore (hWnd);
00722 break;
00723
00724 case WM_DESTROY:
00725 // PostQuitMessage(0);
00726 exit (0); // OK??
00727 break;
00728
00729 case WM_SIZE:
00730 // Resize window
00731 if (wParam != SIZE_MINIMIZED) {
00732 pending_resize_event = 1;
00733 pending_resize_w = LOWORD (lParam);
00734 pending_resize_h = HIWORD (lParam);
00735 ResizeBackingStore (hWnd);
00736 }
00737 break;
00738
00739 case WM_GETMINMAXINFO: {
00740 /* GCS FIX */
00741 /* This needs to include client menu */
00742 /* To do this, I need to call AdjustWindowRect, but
00743 probably I need consider that the window might be POPUP... */
00744 LPMINMAXINFO lpmmi = (LPMINMAXINFO) lParam;
00745 #if defined (commentout)
00746 lpmmi->ptMinTrackSize.x = (640 << pix_double) + 2 * borderx;
00747 lpmmi->ptMinTrackSize.y = (480 << pix_double) + 2 * bordery;
00748 #endif
00749 lpmmi->ptMinTrackSize.x = display.min_w;
00750 lpmmi->ptMinTrackSize.y = display.min_h;
00751 break;
00752 }
00753
00754 default:
00755 return (DefWindowProc (hWnd, message, wParam, lParam));
00756 }
00757 return (0);
00758 }
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1.3.9.1