[3/4] view: Handle the commandline
André Hentschel
nerv at dawncrow.de
Mon Jul 25 16:53:54 CDT 2011
logic taken from our wordpad
---
programs/view/view.c | 96 +++++++++++++++++++++++++++++++++----------------
1 files changed, 64 insertions(+), 32 deletions(-)
diff --git a/programs/view/view.c b/programs/view/view.c
index 884fb7f..d738d8a 100644
--- a/programs/view/view.c
+++ b/programs/view/view.c
@@ -23,6 +23,7 @@
#include <stdio.h>
HINSTANCE hInst;
+HWND hMainWnd;
char szAppName[5] = "View";
char szTitle[80];
@@ -160,6 +161,26 @@ static HMETAFILE GetPlaceableMetaFile( HWND hwnd, LPCSTR szFileName )
return hmf;
}
+static void DoOpenFile(LPCSTR filename)
+{
+ if (!filename) return;
+
+ isAldus = FileIsPlaceable(filename);
+ if (isAldus) {
+ hmf = GetPlaceableMetaFile(hMainWnd, filename);
+ } else {
+ RECT r;
+ isEnhanced = FileIsEnhanced(filename);
+ if (isEnhanced)
+ enhmf = GetEnhMetaFile(filename);
+ else
+ hmf = GetMetaFile(filename);
+ GetClientRect(hMainWnd, &r);
+ width = r.right - r.left;
+ height = r.bottom - r.top;
+ }
+ InvalidateRect( hMainWnd, NULL, TRUE );
+}
LRESULT CALLBACK WndProc(HWND hwnd,
UINT uMessage,
@@ -195,23 +216,8 @@ LRESULT CALLBACK WndProc(HWND hwnd,
case IDM_OPEN:
{
char filename[MAX_PATH];
- if (FileOpen(hwnd, filename, sizeof(filename))) {
- isAldus = FileIsPlaceable(filename);
- if (isAldus) {
- hmf = GetPlaceableMetaFile(hwnd, filename);
- } else {
- RECT r;
- isEnhanced = FileIsEnhanced(filename);
- if (isEnhanced)
- enhmf = GetEnhMetaFile(filename);
- else
- hmf = GetMetaFile(filename);
- GetClientRect(hwnd, &r);
- width = r.right - r.left;
- height = r.bottom - r.top;
- }
- InvalidateRect( hwnd, NULL, TRUE );
- }
+ if (FileOpen(hwnd, filename, sizeof(filename)))
+ DoOpenFile(filename);
}
break;
@@ -304,34 +310,58 @@ BOOL InitApplication(HINSTANCE hInstance)
BOOL InitInstance(HINSTANCE hInstance, int nCmdShow)
{
- HWND hwnd;
-
/* Save the instance handle in a global variable for later use */
hInst = hInstance;
/* Create main window */
- hwnd = CreateWindow(szAppName, /* See RegisterClass() call */
- szTitle, /* window title */
- WS_OVERLAPPEDWINDOW, /* Window style */
- CW_USEDEFAULT, 0, /* positioning */
- CW_USEDEFAULT, 0, /* size */
- NULL, /* Overlapped has no parent */
- NULL, /* Use the window class menu */
- hInstance,
- NULL);
-
- if (!hwnd)
+ hMainWnd = CreateWindow(szAppName, /* See RegisterClass() call */
+ szTitle, /* window title */
+ WS_OVERLAPPEDWINDOW, /* Window style */
+ CW_USEDEFAULT, 0, /* positioning */
+ CW_USEDEFAULT, 0, /* size */
+ NULL, /* Overlapped has no parent */
+ NULL, /* Use the window class menu */
+ hInstance,
+ NULL);
+
+ if (!hMainWnd)
return FALSE;
/* Call module specific instance initialization functions here */
/* show the window, and paint it for the first time */
- ShowWindow(hwnd, nCmdShow);
- UpdateWindow(hwnd);
+ ShowWindow(hMainWnd, nCmdShow);
+ UpdateWindow(hMainWnd);
return TRUE;
}
+static void HandleCommandLine(LPSTR cmdline)
+{
+ CHAR delimiter;
+
+ /* skip white space */
+ while (*cmdline == ' ') cmdline++;
+
+ /* skip executable name */
+ delimiter = (*cmdline == '"' ? '"' : ' ');
+
+ if (*cmdline == delimiter) cmdline++;
+ while (*cmdline && *cmdline != delimiter) cmdline++;
+ if (*cmdline == delimiter) cmdline++;
+
+ if (*cmdline)
+ {
+ /* file name is passed on the command line */
+ if (cmdline[0] == '"')
+ {
+ cmdline++;
+ cmdline[lstrlen(cmdline) - 1] = 0;
+ }
+ DoOpenFile(cmdline);
+ }
+}
+
int APIENTRY WinMain(HINSTANCE hInstance,
HINSTANCE hPrevInstance,
LPSTR lpCmdLine,
@@ -356,6 +386,8 @@ int APIENTRY WinMain(HINSTANCE hInstance,
return FALSE;
}
+ HandleCommandLine(GetCommandLine());
+
hAccelTable = LoadAccelerators(hInstance, szAppName);
/* Main loop */
--
Best Regards, André Hentschel
More information about the wine-patches
mailing list