搜索

首页  >  问答  >  正文

c++ - WinAPI的CreateWindow 如何指定任务栏图标

我现在画了一个窗体,但是奇怪的是任务栏的图标并没有显示成默认的图标,而是如下图:
:
下面是我的全部代码,请问有啥问题:

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

27

28

29

30

31

32

33

34

35

36

37

38

39

40

41

42

43

44

45

46

47

48

49

50

51

52

53

54

55

56

57

58

59

60

61

62

63

64

65

66

67

68

69

70

71

72

73

74

75

76

77

78

79

80

81

82

83

84

<code>    #include <windows.h>

    #include <stdlib.h>

    #include <string.h>

    #include <tchar.h>

    #include <stdio.h>

    #include <GL/GL.h>

 

    #pragma comment (lib,"kernel32.lib")

    #pragma comment (lib,"user32.lib")

    #pragma comment (lib,"opengl32.lib")

    #pragma comment (lib,"Gdi32.lib")

 

    LRESULT CALLBACK WndProc(HWND hWnd,UINT msg,WPARAM wPara,LPARAM lPara);

 

    int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow)

    {

        MSG msg         = {0};

        WNDCLASSEX wc   = {0};

        wc.cbSize       = sizeof(WNDCLASSEX);

        wc.lpfnWndProc  = WndProc;

        wc.hInstance    = GetModuleHandle(NULL);

        wc.hbrBackground = (HBRUSH)(COLOR_BACKGROUND);

        wc.lpszClassName = "Hello,world";

        wc.style = CS_OWNDC;

        wc.hCursor      = LoadCursor(NULL,IDC_ARROW);

        wc.hIcon        = LoadIconW(wc.hInstance,MAKEINTRESOURCEW(IDI_APPLICATION));

        wc.hIconSm      = LoadIconW(wc.hInstance,MAKEINTRESOURCEW(IDI_APPLICATION));

        if(!RegisterClassEx(&wc))

            return 1;

        CreateWindowW(L"Hello,World",L"Hello,World",WS_OVERLAPPEDWINDOW|WS_VISIBLE,0,0,640,480,0,0,hInstance,0);

        while(GetMessage(&msg,NULL,0,0) > 0)

            DispatchMessage(&msg);

 

        return 0;

    }

 

    LRESULT CALLBACK WndProc(HWND hWnd,UINT msg,WPARAM wPara,LPARAM lPara)

    {

        switch(msg)

        {

            case WM_CREATE:

                {

                    PIXELFORMATDESCRIPTOR pfd =

                    {

                        sizeof(PIXELFORMATDESCRIPTOR),

                        1,

                        PFD_DRAW_TO_WINDOW | PFD_SUPPORT_OPENGL | PFD_DOUBLEBUFFER,

                        PFD_TYPE_RGBA,

                        32,

                        0,0,0,0,0,0,

                        0,

                        0,

                        0,

                        0,0,0,0,

                        24,

                        8,

                        0,

                        PFD_MAIN_PLANE,

                        0,

                        0,0,0

                    };

                    HDC ourWindowHandleToDeviceContext = GetDC(hWnd);

 

                    int letWindowChooseThisPixelFormat = ChoosePixelFormat(ourWindowHandleToDeviceContext,&pfd);

                    SetPixelFormat(ourWindowHandleToDeviceContext,letWindowChooseThisPixelFormat,&pfd);

 

                    HGLRC ourOpenGLRenderingContext = wglCreateContext(ourWindowHandleToDeviceContext);

                    wglMakeCurrent(ourWindowHandleToDeviceContext,ourOpenGLRenderingContext);

 

                    // printf("opengl version: %s\n",glGetString(GL_VERSION));

 

                    // MessageBoxA(0,(char*)glGetString(GL_VERSION),"OPENGL VERSION",0);

                }

                break;

            case WM_DESTROY:

                PostQuitMessage(0);

                break;

            default:

                return DefWindowProc(hWnd,msg,wPara,lPara);

                break;

        }

        return 0;

    }

</code>

伊谢尔伦伊谢尔伦2815 天前579

全部回复(1)我来回复

  • 黄舟

    黄舟2017-04-17 11:19:30

    找到问题了,将LoadIcon的第一个参数设为NULL就好了.
    附:官方文档上对第一个参数的解释:
    A handle to an instance of the module whose executable file contains the icon to be loaded. This parameter must be NULL when a standard icon is being loaded.

    回复
    0
  • 取消回复