23,116
社区成员
发帖
与我相关
我的任务
分享
static int HelloWinProc(HWND hWnd, int message, WPARAM wParam, LPARAM lParam)
{
HDC hdc;
syskey = "";
switch (message) {
case MSG_CREATE:
make_welcome_text ();
SetTimer (hWnd, 100, 200);
break;
case MSG_TIMER:
sprintf (msg_text, HL_ST_TIMER,
GetTickCount ());
InvalidateRect (hWnd, &msg_rc, TRUE);
break;
case MSG_LBUTTONDOWN:
strcpy (msg_text, HL_ST_LBD);
InvalidateRect (hWnd, &msg_rc, TRUE);
break;
case MSG_LBUTTONUP:
strcpy (msg_text, HL_ST_LBU);
InvalidateRect (hWnd, &msg_rc, TRUE);
break;
case MSG_RBUTTONDOWN:
strcpy (msg_text, HL_ST_RBD);
InvalidateRect (hWnd, &msg_rc, TRUE);
break;
case MSG_RBUTTONUP:
strcpy (msg_text, HL_ST_RBU);
InvalidateRect (hWnd, &msg_rc, TRUE);
break;
case MSG_PAINT:
hdc = BeginPaint (hWnd);
DrawText (hdc, welcome_text, -1, &welcome_rc, DT_LEFT | DT_WORDBREAK);
DrawText (hdc, msg_text, -1, &msg_rc, DT_LEFT | DT_WORDBREAK);
EndPaint (hWnd, hdc);
return 0;
case MSG_SYSKEYDOWN:
syskey = HL_ST_SYS;
case MSG_KEYDOWN:
if(last_key == wParam)
last_key_count++;
else
{
last_key = wParam;
last_key_count = 1;
}
sprintf (msg_text, HL_ST_KEYD,
wParam, syskey, last_key_count);
InvalidateRect (hWnd, &msg_rc, TRUE);
return 0;
case MSG_KEYLONGPRESS:
sprintf (msg_text, HL_ST_KEYLONG, wParam);
InvalidateRect (hWnd, &msg_rc, TRUE);
break;
case MSG_KEYALWAYSPRESS:
sprintf (msg_text, HL_ST_KEYALWAY, wParam);
InvalidateRect (hWnd, &msg_rc, TRUE);
break;
case MSG_KEYUP:
sprintf (msg_text, HL_ST_KEYU, wParam);
InvalidateRect (hWnd, &msg_rc, TRUE);
return 0;
case MSG_CLOSE:
KillTimer (hWnd, 100);
DestroyMainWindow (hWnd);
PostQuitMessage (hWnd);
return 0;
}
return DefaultMainWinProc(hWnd, message, wParam, lParam);
}
extern "C" int LoadUI()
{
MSG Msg;
HWND hMainWnd;
MAINWINCREATE CreateInfo;
#ifdef _MGRM_PROCESSES
JoinLayer(NAME_DEF_LAYER , "helloworld" , 0 , 0);
#endif
CreateInfo.dwStyle =
WS_VISIBLE | WS_BORDER | WS_CAPTION;
CreateInfo.dwExStyle = WS_EX_NONE;
CreateInfo.spCaption = HL_ST_CAP;
CreateInfo.hMenu = 0;
CreateInfo.hCursor = GetSystemCursor(0);
CreateInfo.hIcon = 0;
CreateInfo.MainWindowProc = HelloWinProc;
CreateInfo.lx = 0;
CreateInfo.ty = 0;
CreateInfo.rx = g_rcScr.right;
CreateInfo.by = g_rcScr.bottom;
CreateInfo.iBkColor = COLOR_lightwhite;
CreateInfo.dwAddData = 0;
CreateInfo.hHosting = HWND_DESKTOP;
hMainWnd = CreateMainWindow (&CreateInfo);
if (hMainWnd == HWND_INVALID)
return -1;
ShowWindow(hMainWnd, SW_SHOWNORMAL);
while (GetMessage(&Msg, hMainWnd)) {
TranslateMessage(&Msg);
DispatchMessage(&Msg);
}
MainWindowThreadCleanup (hMainWnd);
return 0;
}
extern "C" int Add(int a, int b)
{
return a+b;
}
while (GetMessage(&Msg, hMainWnd)) {
TranslateMessage(&Msg);
DispatchMessage(&Msg);
}
while (GetMessage(&Msg, hMainWnd)) {
TranslateMessage(&Msg);
DispatchMessage(&Msg);
}
[/quote]
我根本就没有main函数,我把main函数更改为LoadUI了,然后在另外一个可执行模块中调用LoadUI而已.