Limit GUI updates the the main thread
[TortoiseGit.git] / src / touch / touch.cpp
blobc8089cd8c9d37ddb30e84ff401cc8cc8e9ce36b9
1 // TortoiseGit - a Windows shell extension for easy version control
3 // Copyright (C) 2010-2012 - TortoiseGit
5 // This program is free software; you can redistribute it and/or
6 // modify it under the terms of the GNU General Public License
7 // as published by the Free Software Foundation; either version 2
8 // of the License, or (at your option) any later version.
10 // This program is distributed in the hope that it will be useful,
11 // but WITHOUT ANY WARRANTY; without even the implied warranty of
12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 // GNU General Public License for more details.
15 // You should have received a copy of the GNU General Public License
16 // along with this program; if not, write to the Free Software Foundation,
17 // 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
20 // touch.cpp : Defines the entry point for the application.
23 #include "stdafx.h"
24 #include "touch.h"
26 #define MAX_LOADSTRING 100
28 // Global Variables:
29 HINSTANCE hInst; // current instance
30 TCHAR szTitle[MAX_LOADSTRING]; // The title bar text
31 TCHAR szWindowClass[MAX_LOADSTRING]; // the main window class name
33 // Forward declarations of functions included in this code module:
34 ATOM MyRegisterClass(HINSTANCE hInstance);
35 BOOL InitInstance(HINSTANCE, int);
36 LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM);
37 INT_PTR CALLBACK About(HWND, UINT, WPARAM, LPARAM);
39 TCHAR longname[MAX_PATH +1];
41 int APIENTRY _tWinMain(HINSTANCE /*hInstance*/,
42 HINSTANCE /*hPrevInstance*/,
43 LPTSTR lpCmdLine,
44 int /*nCmdShow*/)
46 SetDllDirectory(L"");
48 if(_tcslen(lpCmdLine) == 0)
49 return -1;
51 //GetLongPathName(lpCmdLine,longname,MAX_PATH);
53 if(lpCmdLine[0] == '\"')
55 lpCmdLine ++;
56 for(size_t i=0;i<_tcslen(lpCmdLine);i++)
57 if(lpCmdLine[i]== '\"')
59 lpCmdLine[i]=0;
60 break;
63 HANDLE handle=CreateFile(lpCmdLine,GENERIC_READ | GENERIC_WRITE, 0,NULL,OPEN_ALWAYS,0,NULL);
64 if(handle == INVALID_HANDLE_VALUE)
65 return -1;
66 CloseHandle(handle);
68 DWORD attr=GetFileAttributes(lpCmdLine);
69 SetFileAttributes(lpCmdLine,attr);
70 return 0;
74 // FUNCTION: MyRegisterClass()
76 // PURPOSE: Registers the window class.
78 // COMMENTS:
80 // This function and its usage are only necessary if you want this code
81 // to be compatible with Win32 systems prior to the 'RegisterClassEx'
82 // function that was added to Windows 95. It is important to call this function
83 // so that the application will get 'well formed' small icons associated
84 // with it.
86 ATOM MyRegisterClass(HINSTANCE hInstance)
88 WNDCLASSEX wcex;
90 wcex.cbSize = sizeof(WNDCLASSEX);
92 wcex.style = CS_HREDRAW | CS_VREDRAW;
93 wcex.lpfnWndProc = WndProc;
94 wcex.cbClsExtra = 0;
95 wcex.cbWndExtra = 0;
96 wcex.hInstance = hInstance;
97 wcex.hIcon = LoadIcon(hInstance, MAKEINTRESOURCE(IDI_TOUCH));
98 wcex.hCursor = LoadCursor(NULL, IDC_ARROW);
99 wcex.hbrBackground = (HBRUSH)(COLOR_WINDOW+1);
100 wcex.lpszMenuName = MAKEINTRESOURCE(IDC_TOUCH);
101 wcex.lpszClassName = szWindowClass;
102 wcex.hIconSm = LoadIcon(wcex.hInstance, MAKEINTRESOURCE(IDI_SMALL));
104 return RegisterClassEx(&wcex);
108 // FUNCTION: InitInstance(HINSTANCE, int)
110 // PURPOSE: Saves instance handle and creates main window
112 // COMMENTS:
114 // In this function, we save the instance handle in a global variable and
115 // create and display the main program window.
117 BOOL InitInstance(HINSTANCE hInstance, int nCmdShow)
119 HWND hWnd;
121 hInst = hInstance; // Store instance handle in our global variable
123 hWnd = CreateWindow(szWindowClass, szTitle, WS_OVERLAPPEDWINDOW,
124 CW_USEDEFAULT, 0, CW_USEDEFAULT, 0, NULL, NULL, hInstance, NULL);
126 if (!hWnd)
128 return FALSE;
131 ShowWindow(hWnd, nCmdShow);
132 UpdateWindow(hWnd);
134 return TRUE;
138 // FUNCTION: WndProc(HWND, UINT, WPARAM, LPARAM)
140 // PURPOSE: Processes messages for the main window.
142 // WM_COMMAND - process the application menu
143 // WM_PAINT - Paint the main window
144 // WM_DESTROY - post a quit message and return
147 LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
149 int wmId, wmEvent;
150 PAINTSTRUCT ps;
151 HDC hdc;
153 switch (message)
155 case WM_COMMAND:
156 wmId = LOWORD(wParam);
157 wmEvent = HIWORD(wParam);
158 // Parse the menu selections:
159 switch (wmId)
161 case IDM_ABOUT:
162 DialogBox(hInst, MAKEINTRESOURCE(IDD_ABOUTBOX), hWnd, About);
163 break;
164 case IDM_EXIT:
165 DestroyWindow(hWnd);
166 break;
167 default:
168 return DefWindowProc(hWnd, message, wParam, lParam);
170 break;
171 case WM_PAINT:
172 hdc = BeginPaint(hWnd, &ps);
173 // Add any drawing code here...
174 EndPaint(hWnd, &ps);
175 break;
176 case WM_DESTROY:
177 PostQuitMessage(0);
178 break;
179 default:
180 return DefWindowProc(hWnd, message, wParam, lParam);
182 return 0;
185 // Message handler for about box.
186 INT_PTR CALLBACK About(HWND hDlg, UINT message, WPARAM wParam, LPARAM /*lParam*/)
188 switch (message)
190 case WM_INITDIALOG:
191 return (INT_PTR)TRUE;
193 case WM_COMMAND:
194 if (LOWORD(wParam) == IDOK || LOWORD(wParam) == IDCANCEL)
196 EndDialog(hDlg, LOWORD(wParam));
197 return (INT_PTR)TRUE;
199 break;
201 return (INT_PTR)FALSE;