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>
#define DLL_EXPORT __declspec(dllexport)
DLL_EXPORT void HelloWorld (void)
{
MessageBox (0, "Hello World!", "From DLL", MB_ICONINFORMATION);
}

View File

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

View File

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