Chinaunix首页 | 论坛 | 博客
  • 博客访问: 13354
  • 博文数量: 3
  • 博客积分: 160
  • 博客等级: 入伍新兵
  • 技术积分: 50
  • 用 户 组: 普通用户
  • 注册时间: 2008-12-22 12:28
文章分类

全部博文(3)

文章存档

2008年(3)

我的朋友
最近访客

分类: C/C++

2008-12-22 12:30:38

今天看了一下Ultimate++的主执行流,Ultimate++的主函数GUI_APP_MAIN是一个宏(SmartWin++不同):
CtrlCore.h:

void GuiMainFn_();\
\
int APIENTRY WinMain(HINSTANCE hInstance, HINSTANCE, LPSTR lpCmdLine, int nCmdShow) \
{ \
    UPP::Ctrl::
InitWin32(hInstance); \
    UPP::coreCmdLine__() = UPP::SplitCmdLine__(lpCmdLine); \
    UPP::AppInitEnvironment__(); \
    
GuiMainFn_(); \
    UPP::Ctrl::CloseTopCtrls(); \
    UPP::UsrLog("---------- About to delete this log"); \
    UPP::DeleteUsrLog(); \
    UPP::Ctrl::ExitWin32(); \
    UPP::AppExit__(); \
    return UPP::GetExitCode(); \
} \
\
void GuiMainFn_()

其实我们填充的是GuiMainFn_()函数的主题部分(含大括号)这里的重点是“InitWin32()”
Win32Wnd.cpp:

void Ctrl::InitWin32(HINSTANCE hInstance)
{
    LLOG("InitWin32");
//    RLOGBLOCK("Ctrl::InitWin32");
#define ILOG(x) // RLOG(x)
    Ctrl::hInstance = hInstance;
    ILOG("RegisterClassW");

#ifndef PLATFORM_WINCE
    
if(IsWinNT())
#endif
    {
        WNDCLASSW  wc;
        Zero(wc);
        wc.style         = CS_DBLCLKS|CS_HREDRAW|CS_VREDRAW;
        
wc.lpfnWndProc   = (WNDPROC)Ctrl::WndProc;
        wc.hInstance     = hInstance;
        wc.hCursor       = LoadCursor(
NULL, IDC_ARROW);
        wc.hbrBackground = 
NULL; //(HBRUSH)(COLOR_WINDOW+1);
        wc.lpszClassName = L"UPP-CLASS-W";
        RegisterClassW(&wc);
        wc.style         = 0x20000|CS_DBLCLKS|CS_HREDRAW|CS_VREDRAW;
        wc.lpszClassName = L"UPP-CLASS-DS-W";
        RegisterClassW(&wc);
        wc.style         = CS_SAVEBITS|CS_DBLCLKS|CS_HREDRAW|CS_VREDRAW;
        wc.lpszClassName = L"UPP-CLASS-SB-W";
        RegisterClassW(&wc);
        wc.style         = 0x20000|CS_DBLCLKS|CS_HREDRAW|CS_VREDRAW|CS_SAVEBITS;
        wc.lpszClassName = L"UPP-CLASS-SB-DS-W";
        RegisterClassW(&wc);
    }

    ILOG("RegisterClassA");
    WNDCLASS  wc;
    Zero(wc);
    wc.style         = CS_DBLCLKS|CS_HREDRAW|CS_VREDRAW;
    wc.lpfnWndProc   = (WNDPROC)Ctrl::WndProc;
    wc.hInstance     = hInstance;
    wc.hCursor       = LoadCursor(
NULL, IDC_ARROW);
    wc.hbrBackground = 
NULL; //(HBRUSH)(COLOR_WINDOW+1);
    wc.lpszClassName = L_("UPP-CLASS-A");
    RegisterClass(&wc);
    
if(IsWinXP()) {
        wc.style         = 0x20000|CS_DBLCLKS|CS_HREDRAW|CS_VREDRAW;
        wc.lpszClassName = L_("UPP-CLASS-DS-A");
        RegisterClass(&wc);
    }
    wc.style         = CS_SAVEBITS|CS_DBLCLKS|CS_HREDRAW|CS_VREDRAW;
    wc.lpszClassName = L_("UPP-CLASS-SB-A");
    RegisterClass(&wc);
    
if(IsWinXP()) {
        wc.style         = 0x20000|CS_DBLCLKS|CS_HREDRAW|CS_VREDRAW|CS_SAVEBITS;
        wc.lpszClassName = L_("UPP-CLASS-SB-DS-A");
        RegisterClass(&wc);
    }
    wc.style         = 0;
    wc.lpszClassName = L_("UPP-TIMER");
    wc.hCursor       = 
NULL;
    wc.lpfnWndProc   = &Ctrl::SysTimerProc;
    RegisterClass(&wc);

    ILOG("InitTimer");
    InitTimer();
    ILOG("SetTimer");
    timerHWND = CreateWindow(L_("UPP-TIMER"), L_(""), WS_OVERLAPPED,
        CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT,
        
NULLNULLNULLNULL);
    SetTimer(timerHWND, 1, 10, 
NULL);
    ILOG("Windows");
    Windows(); //?? TRC: what
's the use of this?

    ChSync();

    OleInitialize(
NULL);

/* TRC 05/11/14: moved 
to GuiSleep to avoid thread creation in OCX DllMain
    DWORD dummy;
    
OverwatchThread = CreateThread(NULL, 0x100000, Win32OverwatchThread, NULL, 0, &dummy);
    ExitLoopEvent().Wait();
*/

// TRC 05/11/18: pSetLayeredWindowAttributes moved 
to GLOBAL_VAR (see below) to make OCX initialization simpler
#undef ILOG
}

Win32Wnd.cpp:

LRESULT CALLBACK Ctrl::WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
{
    
if(sFinished)
        return DefWindowProc(hWnd, message, wParam, lParam);
#ifdef PLATFORM_WINCE
    
if(message == WM_CREATE)
#
else
    
if(message == WM_NCCREATE)
#endif
    {
        Ctrl *w = (Ctrl *)((LPCREATESTRUCT) lParam)->lpCreateParams;
        
if(w) {
            w->NcCreate(hWnd);
            
int i = Windows().Find(NULL);
            
if(i >= 0) {
                Windows().SetKey(i, hWnd);
                Windows()[i] = w;
            }
            
else
                Windows().Add(hWnd) = w;
        }
    }
    Ctrl *w = Windows().Get(hWnd, 
NULL);
#ifdef PLATFORM_WINCE
    
if(message == WM_DESTROY)
#
else
    
if(message == WM_NCDESTROY)
#endif
    {
        
if(w) w->NcDestroy();
        
int i = Windows().Find(hWnd);
        
if(i >= 0)
            Windows().SetKey(i, 
NULL);
    }
    #
if LOGMESSAGES
    bool logblk = 
false;
    
if(message != WM_SETCURSOR && message != WM_CTLCOLORBTN && message != WM_TIMER &&
#ifndef PLATFORM_WINCE
       message != WM_NCHITTEST  && message != WM_ENTERIDLE &&
#endif
       message != WM_CTLCOLORDLG && message != WM_CTLCOLOREDIT && message != WM_CTLCOLORLISTBOX &&
       message != WM_CTLCOLORMSGBOX && message != WM_CTLCOLORSCROLLBAR &&
       message != WM_CTLCOLORSTATIC && message != WM_CANCELMODE &&
       message != 0x0118)
        
for(WinMsg *m = sWinMsg; m->ID; m++)
            
if(m->ID == message) {
                RLOG(m->name << 
' ' << UPP::Name(w) <<
                    Sprintf(", wParam = %d (0x%x), lParam = %d (0x%x)",
                           wParam, wParam, lParam, lParam));
                VppLog().Begin();
                logblk = 
true;
                break;
            }
    #endif
    LRESULT l = 0;
    
if(w) {
        try
        {
#
if defined(_DEBUG) && LOGTIMING
            
int ticks = msecs();
            
String wname = w->Name();
#endif
            Ptr pw = w;
            
l = w->WindowProc(message, wParam, lParam);
            
if(pw)
                pw->SyncMoves();
#
if defined(_DEBUG) && LOGTIMING
            
String msgname;
            
for(WinMsg *m = sWinMsg; m->ID; m++)
                
if(m->ID == message) {
                    msgname = m->name;
                    break;
                }
            
if(IsNull(msgname))
                msgname = NFormat("0x%04x", (
int)message);
            LLOG(NFormat("T+%d %s 0x%08x 0x%08x -> %s", msecs(ticks), msgname, (
int)wParam, (int)lParam, wname));
#endif
        }
        catch(Exc e)
        {
            
LOG("Ctrl::WindowProc -> Exc: " << e);
            NEVER();
        }
    }
    
else
        l = DefWindowProc(hWnd, message, wParam, lParam);
#
if LOGMESSAGES
    
if(logblk)
        VppLog().End();
#endif
    return l;
}

Win32Proc.cpp:

LRESULT Ctrl::WindowProc(UINT message, WPARAM wParam, LPARAM lParam)
{
   //
消息处理的主体
}


:
Win32OverwatchThread->OverWatchWndProc
先到这里吧
阅读(675) | 评论(0) | 转发(0) |
0

上一篇:没有了

下一篇:POCO C++库导游

给主人留下些什么吧!~~