TOP C C++ Languages API COM MFC

References

Tips

Resource

SubClass

Hook
saved_proc = (WNDPROC)GetWindowLong(hwnd, GWL_WNDPROC);
SetWindowLong(hwnd, GWL_WNDPROC, (LONG)new_proc);
new_proc
LRESULT CALLBACK new_proc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam){
    PAINTSTRUCT ps;
    HDC hdc;

    switch(message)    {
        case WM_PAINT:
            hdc = BeginPaint(hwnd, &ps);
            OnPaint(hwnd, hdc, NULL);
            EndPaint(hwnd, &ps);
            return 0;
        default:
            break;   
    }
    return CallWindowProc(saved_proc, hwnd, message, wParam, lParam);
}

BeginPaint vs GetDC

BeginPaintGetDC
Clipping RegionyesnoBeginPaint can draw in clipping region. To know this , use RectVisible(HDC,const RECT *)
GetDC can draw anywhere in client area
validationyesnoBeginPaing will validate the invalidate area.
GetDC won't do, then WM_PAINT will be sent continuously
To validate use ValidateRect(HWND ,CONST RECT *)

StockObject

BLACK_BRUSHBlack brush
DKGRAY_BRUSHDark gray brush
DC_BRUSHSolid brush.(Color is white,changed by SetDCBrushColor()
GRAY_BRUSHGray brush
HOLLOW_BRUSH=NULL_BRUSH
LTGRAY_BRUSHLight gray brush
NULL_BRUSH=HOLLOW_BRUSH
WHITE_BRUSHWhite brush
BLACK_PENBlack pen
DC_PENSolid pen. Color is white,changed by SetDCPenColor()
NULL_PENEmpty pen
WHITE_PENWhite pen
ANSI_FIXED_FONTmonospace system font
ANSI_VAR_FONTproportional system font
DEVICE_DEFAULT_FONTDevice-dependent font
DEFAULT_GUI_FONTMS Sans Serif?
OEM_FIXED_FONTOEM monospace font
SYSTEM_FONTSystem font:
MS Sans Serif(Windows 95/98/NT)
Tahoma(Windows 2000/XP)
SYSTEM_FIXED_FONTmonospace) system font(for 16-bit Windows)
DEFAULT_PALETTEDefault palette

WM_ENABLE

Use EnableWindow(HWND,BOOL);
or Set WS_DISABLED to the control style, then use SendMessage(HWND,WM_ENABLE,BOOL,0);

WM_COMMAND memo

Message SourcewParam (high word)wParam (low word)lParam
Menu0Menu identifier (IDM_*)0
Accelerator1Accelerator identifier (IDM_*)0
ControlControl-defined notification codeControl identifierHandle to the control window

WM_USER WM_APP

0x0000WM_USER-1システム・メッセージ
WM_USER(0x4000)WM_APP-1各ウィンドウクラス・メッセージ
WM_APP (0x8000)0xBFFFアプリケーション・メッセージ
0xC0000xFFFFアプリケーション・文字列(RegisterWindowMessage)
0x10000-reserved

WM_GETDLGCODE

How To Use the WM_GETDLGCODE Message
WM_GETDLGCODE Message
to handle VK_RETURN in EDIT control, return DLGC_WANTALLKEYS

MessageBox

Power Management

BitBlt

HDC hdc_mem; // memory device context
HBITMAP hbitmap; // actual memory to draw
:
void prepare_img(){
    HDC hDC = GetDC(hWnd);
    hdc_mem = CreateCompatibleDC(hDC); // or use NULL for screen DC
    
    RECT rt;
    GetClientRect(hWnd, &rt);
    
    hbitmap = CreateCompatibleBitmap( hDC, rt.right, rt.bottom );
    SelectObject(hdc_mem,hbitmap); // assign memory to dc
    HBRUSH hOrigBrush = (HBRUSH)SelectObject( full_range_dc, GetStockObject( BLACK_BRUSH ) );
    PatBlt( hdc_mem, 0, 0, rt.right, rt.bottom, PATCOPY ); // paint back in black
    {
       // Draw Something to thie hdc_mem
       // TextOut(hdc_mem , 10 , 10 , "Hello" , 5);
    }
    ReleaseDC(hWnd , hDC);
}
void un_prepare(){
    DeleteDC(hdc_mem); hdc_mem=NULL;
    DeleteObject(hbitmap); hbitmap=NULL;
}
:
// in Paint Handler
BitBlt( hdc, 0, 0, rt.right, rt.Widtg, hdc_mem, 0, 0, SRCCOPY );

管理人/副管理人のみ編集できます