Windows API學習筆記(1)

2021-04-12 20:04:46 字數 2395 閱讀 2262

一、視窗處理

1.建立視窗

hwnd createwindow(lpctstr lpclassname, lpctstr lpwindowname, dword dwstyle,int x,int y,int nwidth,int nheight,hwnd hwndparent,hmenu hmenu,handle hinstance,lpvoid lpparam)

該函式建立乙個重疊式、彈出式視窗或子視窗。指定視窗的型別、視窗的標題、視窗的式樣和視窗的初始位置及大小(可選項),以及視窗的父視窗、擁有者視窗和視窗選單。

常用的子視窗樣式:ws_child,ws_visible,ws_border常用的子視窗的型別:button,edit,listbox,mdiclient,richedit,scrollbar,static。

hwnd createwindowex函式建立具有dwexstyle樣式的視窗.常用的擴充套件樣式有:ws_ex_acceptfiles, ws_ex_clentedge, ws_ex_contexthelp, ws_ex_topmost.

2.關閉視窗函式

bool closewindow(hwnd hwnd);//最小化視窗

bool destroywindow(hwnd hwnd);//銷毀視窗

3.視窗間關係的函式

hwnd setparent(hwnd hwndchild,hwnd hwndnewparent);//將子視窗的父視窗重新指定為新的父視窗

hwnd getparent(hwnd hwnd);//函式獲得hwnd的父視窗

4.遍歷視窗

bool enumwindows(wndenumproc lpenumfunc,lparam lparam)

遍歷系統所有的頂層視窗,並把每個視窗控制代碼都傳遞給使用者定義的遍歷**函式。直到遍歷完所有視窗或lpenumfunc返回false才返回

bool enumchildwindows(hwnd hwnd,wndenumproc lpenumfunc,lparam lparam)

遍歷hwnd的所有字視窗,並把每個子視窗的控制代碼都傳遞給使用者自定義的過程。

以上兩個函式所用的**函式定義是: bool callback enumwindowproc(hwnd hwnd,lparam lparam);

因此可以在**函式中對視窗進行處理。

5.獲取指定的子視窗

hwnd childwindowfrompoint(hwnd hwndparent,point pt);//函式首先判斷hwndparent在pt處是否有子視窗,如果有返回這個子視窗的控制代碼。

hwnd childwindowfrompointex(hwnd hwndparent,point pt,uint uflags);//該函式通過uflags可以設定忽略不可見、無效和透明的子視窗。

6.視窗的大小:

bool getwindowrect(hwnd hwnd,lprect lprect);//獲得視窗的外邊框矩形

bool getclientrect(hwnd hwnd,lprect lprect);//獲得視窗的客戶區的矩形

bool setwindowpos(hwnd hwnd,hwnd hwndinsrtafter,int x,int y,int cx,int cy,unit uflags);函式改變子視窗、彈出式視窗或頂層視窗的位置、大小和z序。

7.顯示視窗

bool showwindow(hwnd hwnd,int ncmdshow);//顯示或改變給定的視窗

bool showwindowasync(hwnd hwnd,int ncmdshow);//設定別的執行緒建立的視窗的狀態

bool openicon(hwnd hwnd);//將處於最小化狀態的視窗恢復到以前的顯示狀態。

8.視窗屬性設定

bool setwindowtext(hwnd hwnd,lpctstr lpstring);//設定視窗的標題

int getwindowtext(hwnd hwnd,lptstr lpstring,int nmaxcount);//獲取給定視窗的標題

int getwindowtextlength(hwnd hwnd);//返回給定視窗的標題的長度

9.查詢視窗

hwnd findwindow(lpctstr lpclassname,lpctstr lpwindowname);//返回乙個視窗的控制代碼,該視窗的類由lpclassname引數給出,其視窗名字或標題由lpwindowname函式給出,不查詢子視窗。

hwnd findwindowex(hwnd hwndparent,hwnd hwndchildafter,lpctstr lpszclass,lpctstr lpszwindow);函式查詢子視窗的控制代碼。

hwnd windowfrompoint(point point);該函式返回所給點的視窗,point必須是螢幕中一點的螢幕座標。

總結windows API 的用法(1)

由於現在主要在wndows系統中寫東西,所以會經常使用一些windows api 所以想總結一下,已經使用過的。寫這個也就是為了作為回顧,如果以後想不起來了,還是使用google一下,就可以了。1.createdirectory 建立乙個新目錄 引數 lpnewdirectory string 新目...

WindowsApi學習筆記 建立乙個簡單的視窗

include lresult callback mainwndproc hwnd,uint,wparam,lparam 視窗函式的函式原型 int apientry winmain apientry是 stdcall的巨集定義 hinstance hinstance,本模組的例項控制代碼 hins...

windows api學習筆記 簡單的記事本

include include resource.h include lresult callback mainwndproc hwnd,uint,wparam,lparam 視窗函式的函式原型 int apientry winmain apientry是 stdcall的巨集定義 hinstanc...