win32: reformat examples, crt etc

This commit is contained in:
grischka
2009-07-18 22:07:10 +02:00
parent bb5e0df79a
commit 97738d1ae9
4 changed files with 148 additions and 134 deletions

View File

@ -4,12 +4,9 @@
// //
#include <windows.h> #include <windows.h>
#define DLL_EXPORT __declspec(dllexport) #define DLL_EXPORT __declspec(dllexport)
DLL_EXPORT void HelloWorld (void) DLL_EXPORT void HelloWorld (void)
{ {
MessageBox (0, "Hello World!", "From DLL", MB_ICONINFORMATION); MessageBox (0, "Hello World!", "From DLL", MB_ICONINFORMATION);
} }

View File

@ -10,9 +10,7 @@
char szAppName[] = APPNAME; // The name of this application char szAppName[] = APPNAME; // The name of this application
char szTitle[] = APPNAME; // The title bar text char szTitle[] = APPNAME; // The title bar text
char *pWindowText; const char *pWindowText;
HINSTANCE g_hInst; // current instance
void CenterWindow(HWND hWnd); void CenterWindow(HWND hWnd);
@ -28,8 +26,8 @@ void CenterWindow(HWND hWnd);
LRESULT CALLBACK WndProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam) LRESULT CALLBACK WndProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
{ {
switch (message) switch (message) {
{
// ----------------------- first and last // ----------------------- first and last
case WM_CREATE: case WM_CREATE:
CenterWindow(hwnd); CenterWindow(hwnd);
@ -39,7 +37,6 @@ LRESULT CALLBACK WndProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
PostQuitMessage(0); PostQuitMessage(0);
break; break;
// ----------------------- get out of it... // ----------------------- get out of it...
case WM_RBUTTONUP: case WM_RBUTTONUP:
DestroyWindow(hwnd); DestroyWindow(hwnd);
@ -50,7 +47,6 @@ LRESULT CALLBACK WndProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
DestroyWindow(hwnd); DestroyWindow(hwnd);
break; break;
// ----------------------- display our minimal info // ----------------------- display our minimal info
case WM_PAINT: case WM_PAINT:
{ {
@ -86,14 +82,15 @@ int APIENTRY WinMain(
HINSTANCE hInstance, HINSTANCE hInstance,
HINSTANCE hPrevInstance, HINSTANCE hPrevInstance,
LPSTR lpCmdLine, LPSTR lpCmdLine,
int nCmdShow) int nCmdShow
)
{ {
MSG msg; MSG msg;
WNDCLASS wc; WNDCLASS wc;
HWND hwnd; HWND hwnd;
pWindowText = lpCmdLine[0] ? lpCmdLine : "Hello Windows!";
// Fill in window class structure with parameters that describe // Fill in window class structure with parameters that describe
// the main window. // the main window.
@ -106,7 +103,8 @@ int APIENTRY WinMain(
wc.hIcon = LoadIcon(NULL, IDI_APPLICATION); wc.hIcon = LoadIcon(NULL, IDI_APPLICATION);
wc.hCursor = LoadCursor(NULL, IDC_ARROW); wc.hCursor = LoadCursor(NULL, IDC_ARROW);
if (FALSE == RegisterClass(&wc)) return 0; if (FALSE == RegisterClass(&wc))
return 0;
// create the browser // create the browser
hwnd = CreateWindow( hwnd = CreateWindow(
@ -119,16 +117,14 @@ int APIENTRY WinMain(
240,//CW_USEDEFAULT, 240,//CW_USEDEFAULT,
0, 0,
0, 0,
g_hInst, hInstance,
0); 0);
if (NULL == hwnd) return 0; if (NULL == hwnd)
return 0;
pWindowText = lpCmdLine[0] ? lpCmdLine : "Hello Windows!";
// Main message loop: // Main message loop:
while (GetMessage(&msg, NULL, 0, 0) > 0) while (GetMessage(&msg, NULL, 0, 0) > 0) {
{
TranslateMessage(&msg); TranslateMessage(&msg);
DispatchMessage(&msg); DispatchMessage(&msg);
} }
@ -142,16 +138,24 @@ int APIENTRY WinMain(
void CenterWindow(HWND hwnd_self) void CenterWindow(HWND hwnd_self)
{ {
RECT rw_self, rc_parent, rw_parent; HWND hwnd_parent; HWND hwnd_parent;
RECT rw_self, rc_parent, rw_parent;
int xpos, ypos;
hwnd_parent = GetParent(hwnd_self); hwnd_parent = GetParent(hwnd_self);
if (NULL==hwnd_parent) hwnd_parent = GetDesktopWindow(); if (NULL == hwnd_parent)
hwnd_parent = GetDesktopWindow();
GetWindowRect(hwnd_parent, &rw_parent); GetWindowRect(hwnd_parent, &rw_parent);
GetClientRect(hwnd_parent, &rc_parent); GetClientRect(hwnd_parent, &rc_parent);
GetWindowRect(hwnd_self, &rw_self); GetWindowRect(hwnd_self, &rw_self);
SetWindowPos(hwnd_self, NULL,
rw_parent.left + (rc_parent.right + rw_self.left - rw_self.right) / 2, xpos = rw_parent.left + (rc_parent.right + rw_self.left - rw_self.right) / 2;
rw_parent.top + (rc_parent.bottom + rw_self.top - rw_self.bottom) / 2, ypos = rw_parent.top + (rc_parent.bottom + rw_self.top - rw_self.bottom) / 2;
0, 0,
SetWindowPos(
hwnd_self, NULL,
xpos, ypos, 0, 0,
SWP_NOSIZE|SWP_NOZORDER|SWP_NOACTIVATE SWP_NOSIZE|SWP_NOZORDER|SWP_NOACTIVATE
); );
} }

View File

@ -10,40 +10,53 @@ void _controlfp(unsigned a, unsigned b);
int _winstart(void) int _winstart(void)
{ {
char *szCmd; STARTUPINFO startinfo; char *szCmd;
STARTUPINFO startinfo;
int fShow;
int ret;
__set_app_type(__GUI_APP); __set_app_type(__GUI_APP);
_controlfp(0x10000, 0x30000); _controlfp(0x10000, 0x30000);
szCmd = GetCommandLine(); szCmd = GetCommandLine();
if (szCmd) if (szCmd) {
{ while (' ' == *szCmd)
while (' ' == *szCmd) szCmd++; szCmd++;
if ('\"' == *szCmd) if ('\"' == *szCmd) {
{
while (*++szCmd) while (*++szCmd)
if ('\"' == *szCmd) { szCmd++; break; } if ('\"' == *szCmd) {
szCmd++;
break;
} }
else } else {
{ while (*szCmd && ' ' != *szCmd)
while (*szCmd && ' ' != *szCmd) szCmd++; szCmd++;
} }
while (' ' == *szCmd) szCmd++; while (' ' == *szCmd)
szCmd++;
} }
GetStartupInfo(&startinfo); GetStartupInfo(&startinfo);
exit(WinMain(GetModuleHandle(NULL), NULL, szCmd, fShow = startinfo.wShowWindow;
(startinfo.dwFlags & STARTF_USESHOWWINDOW) ? if (0 == (startinfo.dwFlags & STARTF_USESHOWWINDOW))
startinfo.wShowWindow : SW_SHOWDEFAULT)); fShow = SW_SHOWDEFAULT;
ret = WinMain(GetModuleHandle(NULL), NULL, szCmd, fShow);
exit(ret);
} }
int _runwinmain(int argc, char **argv) int _runwinmain(int argc, char **argv)
{ {
char *szCmd = NULL; char *szCmd, *p;
char *p = GetCommandLine();
if (argc > 1) szCmd = strstr(p, argv[1]); p = GetCommandLine();
if (NULL == szCmd) szCmd = ""; szCmd = NULL;
else if (szCmd > p && szCmd[-1] == '\"') --szCmd; if (argc > 1)
szCmd = strstr(p, argv[1]);
if (NULL == szCmd)
szCmd = "";
else if (szCmd > p && szCmd[-1] == '\"')
--szCmd;
return WinMain(GetModuleHandle(NULL), NULL, szCmd, SW_SHOWDEFAULT); return WinMain(GetModuleHandle(NULL), NULL, szCmd, SW_SHOWDEFAULT);
} }